@@ -6,6 +6,9 @@ import platforms from './platforms';
6
6
import * as kubectl from '../helpers/kubectl' ;
7
7
import * as waiters from './waiters' ;
8
8
9
+ const testPlatform = process . env [ 'TEST_PLATFORM' ] || 'kind' ;
10
+ const createCluster = process . env [ 'CREATE_CLUSTER' ] === 'true' ;
11
+
9
12
function getIntegrationId ( ) : string {
10
13
const integrationId = uuidv4 ( ) ;
11
14
console . log ( `Generated new integration ID ${ integrationId } ` ) ;
@@ -55,9 +58,13 @@ function createTestYamlDeployment(
55
58
56
59
export async function removeMonitor ( ) : Promise < void > {
57
60
try {
58
- await platforms . kind . delete ( ) ;
61
+ if ( createCluster ) {
62
+ await platforms [ testPlatform ] . delete ( ) ;
63
+ } else {
64
+ await platforms [ testPlatform ] . clean ( ) ;
65
+ }
59
66
} catch ( error ) {
60
- console . log ( `Could not delete kind cluster : ${ error . message } ` ) ;
67
+ console . log ( `Could not remove the Kubernetes-Monitor : ${ error . message } ` ) ;
61
68
}
62
69
63
70
console . log ( 'Removing KUBECONFIG environment variable...' ) ;
@@ -73,20 +80,20 @@ export async function removeMonitor(): Promise<void> {
73
80
74
81
async function createEnvironment ( ) : Promise < void > {
75
82
// TODO: we probably want to use k8s-api for that, not kubectl
76
- const servicesNamespace = 'services' ;
77
- await kubectl . createNamespace ( servicesNamespace ) ;
83
+ await kubectl . createNamespace ( 'services' ) ;
78
84
// Small hack to prevent timing problems in CircleCI...
85
+ // TODO: should be replaced by actively waiting for the namespace to be created
79
86
await sleep ( 5000 ) ;
87
+ }
80
88
81
- // Create imagePullSecrets for pulling private images from gcr.io.
82
- // This is needed for deploying gcr.io images in KinD (this is _not_ used by snyk-monitor).
89
+ async function createSecretForGcrIoAccess ( ) : Promise < void > {
83
90
const gcrSecretName = 'gcr-io' ;
84
91
const gcrKubectlSecretsKeyPrefix = '--' ;
85
92
const gcrSecretType = 'docker-registry' ;
86
93
const gcrToken = getEnvVariableOrDefault ( 'GCR_IO_SERVICE_ACCOUNT' , '{}' ) ;
87
94
await kubectl . createSecret (
88
95
gcrSecretName ,
89
- servicesNamespace ,
96
+ 'services' ,
90
97
{
91
98
'docker-server' : 'https://gcr.io' ,
92
99
'docker-username' : '_json_key' ,
@@ -129,17 +136,17 @@ export async function deployMonitor(): Promise<string> {
129
136
'snyk/kubernetes-monitor:local' ,
130
137
) ;
131
138
132
- const testPlatform = process . env [ 'TEST_PLATFORM' ] || 'kind' ;
133
- const createCluster = process . env [ 'CREATE_CLUSTER' ] === 'true' ;
134
139
console . log ( `platform chosen is ${ testPlatform } , createCluster===${ createCluster } ` ) ;
135
140
136
141
await kubectl . downloadKubectl ( ) ;
137
142
if ( createCluster ) {
138
- await platforms [ testPlatform ] . create ( imageNameAndTag ) ;
143
+ await platforms [ testPlatform ] . create ( ) ;
139
144
}
145
+ const remoteImageName = await platforms [ testPlatform ] . loadImage ( imageNameAndTag ) ;
140
146
await platforms [ testPlatform ] . config ( ) ;
141
147
await createEnvironment ( ) ;
142
- const integrationId = await installKubernetesMonitor ( imageNameAndTag ) ;
148
+ await createSecretForGcrIoAccess ( ) ;
149
+ const integrationId = await installKubernetesMonitor ( remoteImageName ) ;
143
150
await waiters . waitForMonitorToBeReady ( ) ;
144
151
console . log ( `Deployed the snyk-monitor with integration ID ${ integrationId } ` ) ;
145
152
return integrationId ;
@@ -157,15 +164,3 @@ export async function deployMonitor(): Promise<string> {
157
164
throw err ;
158
165
}
159
166
}
160
-
161
- export async function createSampleDeployments ( ) : Promise < void > {
162
- const servicesNamespace = 'services' ;
163
- const someImageWithSha = 'alpine@sha256:7746df395af22f04212cd25a92c1d6dbc5a06a0ca9579a229ef43008d4d1302a' ;
164
- await Promise . all ( [
165
- kubectl . applyK8sYaml ( './test/fixtures/alpine-pod.yaml' ) ,
166
- kubectl . applyK8sYaml ( './test/fixtures/nginx-replicationcontroller.yaml' ) ,
167
- kubectl . applyK8sYaml ( './test/fixtures/redis-deployment.yaml' ) ,
168
- kubectl . applyK8sYaml ( './test/fixtures/centos-deployment.yaml' ) ,
169
- kubectl . createDeploymentFromImage ( 'alpine-from-sha' , someImageWithSha , servicesNamespace ) ,
170
- ] ) ;
171
- }
0 commit comments