Skip to content

Commit f0f9ae7

Browse files
authored
Merge pull request #714 from snyk/chore/fix-olm-tests
chore: fix Operator tests with OLM on vanilla Kubernetes
2 parents 8edd305 + ec4f490 commit f0f9ae7

File tree

5 files changed

+58
-28
lines changed

5 files changed

+58
-28
lines changed

.circleci/config.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,9 +236,10 @@ jobs:
236236
name: Create temporary directory for logs
237237
- run:
238238
command: |
239+
export OPERATOR_VERSION="0.0.1-${CIRCLE_SHA1}"
239240
export KUBERNETES_MONITOR_IMAGE_NAME_AND_TAG=$(./scripts/circleci-jobs/setup-integration-tests.py)
240241
.circleci/do-exclusively --branch staging --job ${CIRCLE_JOB} npm run test:integration:kindolm:operator
241-
name: Operator integration tests on plain k8s
242+
name: Operator integration tests on vanilla Kubernetes
242243
- run:
243244
command: |
244245
./scripts/slack/notify_failure_on_branch.py "${CIRCLE_BRANCH}" "${CIRCLE_JOB}" "${CIRCLE_BUILD_URL}" "${CIRCLE_PULL_REQUEST}" "${SLACK_WEBHOOK}"

.circleci/config/jobs/integration_tests_operator_on_k8s.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ steps:
1111
name: Create temporary directory for logs
1212
- run:
1313
command: |
14+
export OPERATOR_VERSION="0.0.1-${CIRCLE_SHA1}"
1415
export KUBERNETES_MONITOR_IMAGE_NAME_AND_TAG=$(./scripts/circleci-jobs/setup-integration-tests.py)
1516
.circleci/do-exclusively --branch staging --job ${CIRCLE_JOB} npm run test:integration:kindolm:operator
16-
name: Operator integration tests on plain k8s
17+
name: Operator integration tests on vanilla Kubernetes
1718
- run:
1819
command: |
1920
./scripts/slack/notify_failure_on_branch.py "${CIRCLE_BRANCH}" "${CIRCLE_JOB}" "${CIRCLE_BUILD_URL}" "${CIRCLE_PULL_REQUEST}" "${SLACK_WEBHOOK}"
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
apiVersion: operators.coreos.com/v1alpha1
2+
kind: CatalogSource
3+
metadata:
4+
name: snyk-operator
5+
namespace: marketplace
6+
spec:
7+
sourceType: grpc
8+
image: docker.io/snyk/kubernetes-operator-index:TAG_OVERRIDE
9+
displayName: Snyk Operator Bundle
10+
publisher: Snyk Ltd.
11+
updateStrategy:
12+
registryPoll:
13+
interval: 1m

test/setup/deployers/operator-olm.ts

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
21
import * as sleep from 'sleep-promise';
2+
import { parse, stringify } from 'yaml';
3+
import { readFileSync, writeFileSync } from 'fs';
4+
35
import { IDeployer, IImageOptions } from './types';
46
import * as kubectl from '../../helpers/kubectl';
57

@@ -33,14 +35,37 @@ async function waitToDeployKubernetesOperator(namespace: string): Promise<void>
3335
async function deployKubernetesMonitor(
3436
_imageOptions: IImageOptions,
3537
): 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');
4671
}

test/setup/platforms/kind-olm.ts

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,19 @@
1+
import * as sleep from 'sleep-promise';
2+
13
import { createCluster as kindCreateCluster } from './kind';
24
import * as kubectl from '../../helpers/kubectl';
3-
import * as sleep from 'sleep-promise';
45
import { throwIfEnvironmentVariableUnset } from './helpers';
56

67
export async function createCluster(version: string): Promise<void> {
78
await kindCreateCluster(version);
89

9-
// OLM installation: https://github.com/operator-framework/community-operators/blob/master/docs/testing-operators.md#2-install-olm
10-
11-
const operatorLifecycleManagerVersion = '0.15.1'; // https://github.com/operator-framework/operator-lifecycle-manager/releases/tag/0.15.1
12-
await kubectl.applyK8sYaml(`https://github.com/operator-framework/operator-lifecycle-manager/releases/download/${operatorLifecycleManagerVersion}/crds.yaml`);
10+
// OLM installation: https://github.com/operator-framework/operator-lifecycle-manager/blob/master/doc/install/install.md#installing-olm
11+
await kubectl.applyK8sYaml('https://raw.githubusercontent.com/operator-framework/operator-lifecycle-manager/master/deploy/upstream/quickstart/crds.yaml');
1312
await sleep(5000); // give enough time to k8s to apply the previous yaml
14-
await kubectl.applyK8sYaml(`https://github.com/operator-framework/operator-lifecycle-manager/releases/download/${operatorLifecycleManagerVersion}/olm.yaml`);
13+
await kubectl.applyK8sYaml('https://raw.githubusercontent.com/operator-framework/operator-lifecycle-manager/master/deploy/upstream/quickstart/olm.yaml');
1514
await kubectl.waitForDeployment('catalog-operator', 'olm');
1615
await kubectl.waitForDeployment('olm-operator', 'olm');
1716
await kubectl.waitForDeployment('packageserver', 'olm');
18-
19-
await kubectl.applyK8sYaml('https://raw.githubusercontent.com/operator-framework/operator-marketplace/0c2dfdec91f3518370b9af6a50a88dd5eb16a91e/deploy/upstream/01_namespace.yaml');
20-
await kubectl.applyK8sYaml('https://raw.githubusercontent.com/operator-framework/operator-marketplace/0c2dfdec91f3518370b9af6a50a88dd5eb16a91e/deploy/upstream/03_operatorsource.crd.yaml');
21-
await kubectl.applyK8sYaml('https://raw.githubusercontent.com/operator-framework/operator-marketplace/0c2dfdec91f3518370b9af6a50a88dd5eb16a91e/deploy/upstream/04_service_account.yaml');
22-
await kubectl.applyK8sYaml('https://raw.githubusercontent.com/operator-framework/operator-marketplace/0c2dfdec91f3518370b9af6a50a88dd5eb16a91e/deploy/upstream/05_role.yaml');
23-
await kubectl.applyK8sYaml('https://raw.githubusercontent.com/operator-framework/operator-marketplace/0c2dfdec91f3518370b9af6a50a88dd5eb16a91e/deploy/upstream/06_role_binding.yaml');
24-
await kubectl.applyK8sYaml('https://raw.githubusercontent.com/operator-framework/operator-marketplace/0c2dfdec91f3518370b9af6a50a88dd5eb16a91e/deploy/upstream/07_upstream_operatorsource.cr.yaml');
25-
// Fixing the marketplace-operator image version to 4.5.0
26-
await kubectl.applyK8sYaml('./test/fixtures/operator/marketplace-operator.yaml');
2717
}
2818

2919
export async function validateRequiredEnvironment(): Promise<void> {

0 commit comments

Comments
 (0)