@@ -4,6 +4,7 @@ import * as uuidv4 from 'uuid/v4';
44
55import platforms from './platforms' ;
66import deployers from './deployers' ;
7+ import { IImageOptions } from './deployers/types' ;
78import * as kubectl from '../helpers/kubectl' ;
89
910const testPlatform = process . env [ 'TEST_PLATFORM' ] || 'kind' ;
@@ -44,6 +45,22 @@ async function createEnvironment(): Promise<void> {
4445 await sleep ( 5000 ) ;
4546}
4647
48+ async function predeploy ( integrationId : string ) : Promise < void > {
49+ try {
50+ const namespace = 'snyk-monitor' ;
51+ await kubectl . createNamespace ( namespace ) ;
52+
53+ const secretName = 'snyk-monitor' ;
54+ const gcrDockercfg = process . env [ 'GCR_IO_DOCKERCFG' ] || '{}' ;
55+ await kubectl . createSecret ( secretName , namespace , {
56+ 'dockercfg.json' : gcrDockercfg ,
57+ integrationId,
58+ } ) ;
59+ } catch ( error ) {
60+ console . log ( 'Could not create namespace and secret, they probably already exist' ) ;
61+ }
62+ }
63+
4764async function createSecretForGcrIoAccess ( ) : Promise < void > {
4865 const gcrSecretName = 'gcr-io' ;
4966 const gcrKubectlSecretsKeyPrefix = '--' ;
@@ -89,17 +106,15 @@ export async function deployMonitor(): Promise<string> {
89106 await createSecretForGcrIoAccess ( ) ;
90107
91108 const integrationId = getIntegrationId ( ) ;
109+ await predeploy ( integrationId ) ;
92110
93111 // TODO: hack, rewrite this
94112 const imagePullPolicy = testPlatform === 'kind' ? 'Never' : 'Always' ;
95- const deploymentImageOptions = {
96- imageNameAndTag : remoteImageName ,
97- imagePullPolicy,
113+ const deploymentImageOptions : IImageOptions = {
114+ nameAndTag : remoteImageName ,
115+ pullPolicy : imagePullPolicy ,
98116 } ;
99- await deployers [ deploymentType ] . deploy (
100- integrationId ,
101- deploymentImageOptions ,
102- ) ;
117+ await deployers [ deploymentType ] . deploy ( deploymentImageOptions ) ;
103118 await kubectl . waitForDeployment ( 'snyk-monitor' , 'snyk-monitor' ) ;
104119 console . log ( `Deployed the snyk-monitor with integration ID ${ integrationId } ` ) ;
105120 return integrationId ;
0 commit comments