|
1 | | - |
2 | 1 | import * as sleep from 'sleep-promise'; |
| 2 | +import { parse, stringify } from 'yaml'; |
| 3 | +import { readFileSync, writeFileSync } from 'fs'; |
| 4 | + |
3 | 5 | import { IDeployer, IImageOptions } from './types'; |
4 | 6 | import * as kubectl from '../../helpers/kubectl'; |
5 | 7 |
|
@@ -33,14 +35,37 @@ async function waitToDeployKubernetesOperator(namespace: string): Promise<void> |
33 | 35 | async function deployKubernetesMonitor( |
34 | 36 | _imageOptions: IImageOptions, |
35 | 37 | ): Promise<void> { |
36 | | - await kubectl.applyK8sYaml('./test/fixtures/operator/operator-source-k8s.yaml'); |
37 | | - await kubectl.applyK8sYaml('./test/fixtures/operator/installation-k8s.yaml'); |
38 | | - |
39 | | - // Await for the Operator to become available, only then |
40 | | - // the Operator can start processing the custom resource. |
41 | | - await kubectl.waitForDeployment('snyk-operator', 'marketplace'); |
42 | | - await kubectl.waitForCRD('snykmonitors.charts.helm.k8s.io'); |
43 | | - await kubectl.applyK8sYaml('./test/fixtures/operator/custom-resource-k8s.yaml'); |
44 | | - await waitToDeployKubernetesOperator('marketplace'); |
45 | | - await kubectl.waitForDeployment('snyk-operator', 'marketplace'); |
| 38 | + const overriddenOperatorSource = 'snyk-monitor-catalog-source.yaml'; |
| 39 | + createTestOperatorSource(overriddenOperatorSource); |
| 40 | + await kubectl.applyK8sYaml(overriddenOperatorSource); |
| 41 | + await kubectl.applyK8sYaml('./test/fixtures/operator/installation-k8s.yaml'); |
| 42 | + |
| 43 | + // Await for the Operator to become available, only then |
| 44 | + // the Operator can start processing the custom resource. |
| 45 | + await kubectl.waitForDeployment('snyk-operator', 'marketplace'); |
| 46 | + await kubectl.waitForCRD('snykmonitors.charts.helm.k8s.io'); |
| 47 | + await kubectl.applyK8sYaml('./test/fixtures/operator/custom-resource-k8s.yaml'); |
| 48 | + await waitToDeployKubernetesOperator('marketplace'); |
| 49 | + await kubectl.waitForDeployment('snyk-operator', 'marketplace'); |
| 50 | +} |
| 51 | + |
| 52 | +function createTestOperatorSource(newYamlPath: string): void { |
| 53 | + console.log('Creating YAML CatalogSource...'); |
| 54 | + const operatorVersion = |
| 55 | + process.env.OPERATOR_VERSION ?? readFileSync('./.operator_version', 'utf8'); |
| 56 | + const originalCatalogSourceYaml = readFileSync( |
| 57 | + './test/fixtures/operator/catalog-source-k8s.yaml', |
| 58 | + 'utf8', |
| 59 | + ); |
| 60 | + const catalogSource: { spec: { image: string } } = parse( |
| 61 | + originalCatalogSourceYaml, |
| 62 | + ); |
| 63 | + |
| 64 | + catalogSource.spec.image = catalogSource.spec.image.replace( |
| 65 | + 'TAG_OVERRIDE', |
| 66 | + operatorVersion, |
| 67 | + ); |
| 68 | + |
| 69 | + writeFileSync(newYamlPath, stringify(catalogSource)); |
| 70 | + console.log('Created YAML CatalogSource'); |
46 | 71 | } |
0 commit comments