1- import { readFileSync , writeFileSync } from 'fs' ;
21import * as sleep from 'sleep-promise' ;
32import * as uuidv4 from 'uuid/v4' ;
4- import { parse , stringify } from 'yaml' ;
3+
54import platforms from './platforms' ;
5+ import deployers from './deployers' ;
66import * as kubectl from '../helpers/kubectl' ;
77import * as waiters from './waiters' ;
8+ import { DeploymentType } from './deployers/types' ;
89
910const testPlatform = process . env [ 'TEST_PLATFORM' ] || 'kind' ;
1011const createCluster = process . env [ 'CREATE_CLUSTER' ] === 'true' ;
@@ -22,41 +23,6 @@ function getEnvVariableOrDefault(envVarName: string, defaultValue: string): stri
2223 : value ;
2324}
2425
25- function createTestYamlDeployment (
26- newYamlPath : string ,
27- integrationId : string ,
28- imageNameAndTag : string ,
29- imagePullPolicy : string ,
30- ) : void {
31- console . log ( 'Creating test deployment...' ) ;
32- const originalDeploymentYaml = readFileSync ( './snyk-monitor-deployment.yaml' , 'utf8' ) ;
33- const deployment = parse ( originalDeploymentYaml ) ;
34-
35- deployment . spec . template . spec . containers [ 0 ] . image = imageNameAndTag ;
36- deployment . spec . template . spec . containers [ 0 ] . imagePullPolicy = imagePullPolicy ;
37-
38- // This is important due to an odd bug when running on Travis.
39- // By adding the Google nameserver, the container can start resolving external hosts.
40- deployment . spec . template . spec . dnsConfig = {
41- nameservers : [ '8.8.8.8' ] ,
42- } ;
43-
44- // Inject the integration ID that will be used throughout the integration tests.
45- deployment . spec . template . spec . containers [ 0 ] . env [ 0 ] = {
46- name : 'SNYK_INTEGRATION_ID' ,
47- value : integrationId ,
48- } ;
49-
50- // Inject the baseUrl of kubernetes-upstream that snyk-monitor container use to send metadata
51- deployment . spec . template . spec . containers [ 0 ] . env [ 2 ] = {
52- name : 'SNYK_INTEGRATION_API' ,
53- value : 'https://kubernetes-upstream.dev.snyk.io' ,
54- } ;
55-
56- writeFileSync ( newYamlPath , stringify ( deployment ) ) ;
57- console . log ( 'Created test deployment' ) ;
58- }
59-
6026export async function removeMonitor ( ) : Promise < void > {
6127 try {
6228 if ( createCluster ) {
@@ -96,30 +62,6 @@ async function createSecretForGcrIoAccess(): Promise<void> {
9662 ) ;
9763}
9864
99- async function installKubernetesMonitor (
100- imageNameAndTag : string ,
101- imagePullPolicy : string ,
102- ) : Promise < string > {
103- const namespace = 'snyk-monitor' ;
104- await kubectl . createNamespace ( namespace ) ;
105-
106- const secretName = 'snyk-monitor' ;
107- const integrationId = getIntegrationId ( ) ;
108- const gcrDockercfg = getEnvVariableOrDefault ( 'GCR_IO_DOCKERCFG' , '{}' ) ;
109- await kubectl . createSecret ( secretName , namespace , {
110- 'dockercfg.json' : gcrDockercfg ,
111- integrationId,
112- } ) ;
113-
114- const testYaml = 'snyk-monitor-test-deployment.yaml' ;
115- createTestYamlDeployment ( testYaml , integrationId , imageNameAndTag , imagePullPolicy ) ;
116-
117- await kubectl . applyK8sYaml ( './snyk-monitor-cluster-permissions.yaml' ) ;
118- await kubectl . applyK8sYaml ( './snyk-monitor-test-deployment.yaml' ) ;
119-
120- return integrationId ;
121- }
122-
12365export async function deployMonitor ( ) : Promise < string > {
12466 console . log ( 'Begin deploying the snyk-monitor...' ) ;
12567
@@ -145,10 +87,18 @@ export async function deployMonitor(): Promise<string> {
14587 await createEnvironment ( ) ;
14688 await createSecretForGcrIoAccess ( ) ;
14789
90+ const integrationId = getIntegrationId ( ) ;
91+
14892 // TODO: hack, rewrite this
14993 const imagePullPolicy = testPlatform === 'kind' ? 'Never' : 'Always' ;
150-
151- const integrationId = await installKubernetesMonitor ( remoteImageName , imagePullPolicy ) ;
94+ const deploymentImageOptions = {
95+ imageNameAndTag : remoteImageName ,
96+ imagePullPolicy,
97+ } ;
98+ await deployers [ DeploymentType . YAML ] . deploy (
99+ integrationId ,
100+ deploymentImageOptions ,
101+ ) ;
152102 await waiters . waitForMonitorToBeReady ( ) ;
153103 console . log ( `Deployed the snyk-monitor with integration ID ${ integrationId } ` ) ;
154104 return integrationId ;
0 commit comments