@@ -6,6 +6,9 @@ import platforms from './platforms';
66import * as kubectl from '../helpers/kubectl' ;
77import * as waiters from './waiters' ;
88
9+ const testPlatform = process . env [ 'TEST_PLATFORM' ] || 'kind' ;
10+ const createCluster = process . env [ 'CREATE_CLUSTER' ] === 'true' ;
11+
912function getIntegrationId ( ) : string {
1013 const integrationId = uuidv4 ( ) ;
1114 console . log ( `Generated new integration ID ${ integrationId } ` ) ;
@@ -55,9 +58,13 @@ function createTestYamlDeployment(
5558
5659export async function removeMonitor ( ) : Promise < void > {
5760 try {
58- await platforms . kind . delete ( ) ;
61+ if ( createCluster ) {
62+ await platforms [ testPlatform ] . delete ( ) ;
63+ } else {
64+ await platforms [ testPlatform ] . clean ( ) ;
65+ }
5966 } catch ( error ) {
60- console . log ( `Could not delete kind cluster : ${ error . message } ` ) ;
67+ console . log ( `Could not remove the Kubernetes-Monitor : ${ error . message } ` ) ;
6168 }
6269
6370 console . log ( 'Removing KUBECONFIG environment variable...' ) ;
@@ -73,20 +80,20 @@ export async function removeMonitor(): Promise<void> {
7380
7481async function createEnvironment ( ) : Promise < void > {
7582 // 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' ) ;
7884 // Small hack to prevent timing problems in CircleCI...
85+ // TODO: should be replaced by actively waiting for the namespace to be created
7986 await sleep ( 5000 ) ;
87+ }
8088
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 > {
8390 const gcrSecretName = 'gcr-io' ;
8491 const gcrKubectlSecretsKeyPrefix = '--' ;
8592 const gcrSecretType = 'docker-registry' ;
8693 const gcrToken = getEnvVariableOrDefault ( 'GCR_IO_SERVICE_ACCOUNT' , '{}' ) ;
8794 await kubectl . createSecret (
8895 gcrSecretName ,
89- servicesNamespace ,
96+ 'services' ,
9097 {
9198 'docker-server' : 'https://gcr.io' ,
9299 'docker-username' : '_json_key' ,
@@ -129,17 +136,17 @@ export async function deployMonitor(): Promise<string> {
129136 'snyk/kubernetes-monitor:local' ,
130137 ) ;
131138
132- const testPlatform = process . env [ 'TEST_PLATFORM' ] || 'kind' ;
133- const createCluster = process . env [ 'CREATE_CLUSTER' ] === 'true' ;
134139 console . log ( `platform chosen is ${ testPlatform } , createCluster===${ createCluster } ` ) ;
135140
136141 await kubectl . downloadKubectl ( ) ;
137142 if ( createCluster ) {
138- await platforms [ testPlatform ] . create ( imageNameAndTag ) ;
143+ await platforms [ testPlatform ] . create ( ) ;
139144 }
145+ const remoteImageName = await platforms [ testPlatform ] . loadImage ( imageNameAndTag ) ;
140146 await platforms [ testPlatform ] . config ( ) ;
141147 await createEnvironment ( ) ;
142- const integrationId = await installKubernetesMonitor ( imageNameAndTag ) ;
148+ await createSecretForGcrIoAccess ( ) ;
149+ const integrationId = await installKubernetesMonitor ( remoteImageName ) ;
143150 await waiters . waitForMonitorToBeReady ( ) ;
144151 console . log ( `Deployed the snyk-monitor with integration ID ${ integrationId } ` ) ;
145152 return integrationId ;
@@ -157,15 +164,3 @@ export async function deployMonitor(): Promise<string> {
157164 throw err ;
158165 }
159166}
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