Skip to content

Commit be7e06f

Browse files
authored
Merge pull request #692 from snyk/chore/os-tests
chore: adjust Operator tests for OpenShift 4.6 and above
2 parents d337efd + 86395a4 commit be7e06f

26 files changed

+547
-380
lines changed

.circleci/config.yml

Lines changed: 6 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,11 @@ jobs:
4242
- checkout
4343
- setup_remote_docker
4444
- install_python_requests
45-
- run:
46-
command: pip install operator-courier==2.1.7
47-
name: Install operator-courier
4845
- run:
4946
command: |
50-
RELEASE_VERSION=v0.15.1
51-
DOWNLOAD_LOCATION=./operator-sdk
52-
CURL_FOLLOW_REDIRECTS="-L"
53-
curl ${CURL_FOLLOW_REDIRECTS} https://github.com/operator-framework/operator-sdk/releases/download/${RELEASE_VERSION}/operator-sdk-${RELEASE_VERSION}-x86_64-linux-gnu -o ${DOWNLOAD_LOCATION}
54-
chmod +x ${DOWNLOAD_LOCATION}
55-
name: Download Operator SDK
47+
scripts/operator/download_operator_sdk.py
48+
scripts/operator/download_operator_package_manager.py
49+
name: Download Operator SDK and Operator Package Manager
5650
- run:
5751
command: |
5852
export IMAGE_TAG=$([[ "$CIRCLE_BRANCH" == "staging" ]] && echo "staging-candidate" || echo "discardable")
@@ -71,16 +65,10 @@ jobs:
7165
name: Package Operator Bundle
7266
- run:
7367
command: |
74-
if [ "$CIRCLE_BRANCH" != "staging" ]; then
75-
exit 0
76-
fi
77-
export QUAY_TOKEN=$(scripts/operator/get_quay_token.py "${QUAY_USERNAME}" "${QUAY_PASSWORD}")
7868
export OPERATOR_DIR=$OPERATOR_PATH
79-
export QUAY_NAMESPACE=snyk-runtime
80-
export PACKAGE_NAME=snyk-operator
8169
export PACKAGE_VERSION="0.0.1-${CIRCLE_SHA1}"
82-
operator-courier push "${OPERATOR_DIR}" "${QUAY_NAMESPACE}" "${PACKAGE_NAME}" "${PACKAGE_VERSION}" "${QUAY_TOKEN}"
83-
name: Upload Operator to Quay
70+
scripts/operator/create_operator_bundle_and_index_and_push.py "${OPERATOR_DIR}" "${PACKAGE_VERSION}" "${DOCKERHUB_USER}" "${DOCKERHUB_PASSWORD}"
71+
name: Create Operator Bundle and Index and push to Docker Hub
8472
- run:
8573
command: |
8674
./scripts/slack/notify_failure_on_branch.py "${CIRCLE_BRANCH}" "${CIRCLE_JOB}" "${CIRCLE_BUILD_URL}" "${CIRCLE_PULL_REQUEST}" "${SLACK_WEBHOOK}"
@@ -109,21 +97,6 @@ jobs:
10997
name: Notify Slack on failure
11098
when: on_fail
11199
working_directory: ~/kubernetes-monitor
112-
delete_operators_from_quay:
113-
docker:
114-
- auth:
115-
password: $DOCKERHUB_PASSWORD
116-
username: $DOCKERHUB_USER
117-
image: circleci/python:3.9
118-
steps:
119-
- checkout
120-
- install_python_requests
121-
- run:
122-
command: |
123-
python3 scripts/operator/delete_operators_from_quay.py "${QUAY_USERNAME}" "${QUAY_PASSWORD}"
124-
name: Delete Operators from Quay
125-
when: always
126-
working_directory: ~/kubernetes-monitor
127100
deploy_dev:
128101
docker:
129102
- auth:
@@ -266,11 +239,6 @@ jobs:
266239
export KUBERNETES_MONITOR_IMAGE_NAME_AND_TAG=$(./scripts/circleci-jobs/setup-integration-tests.py)
267240
.circleci/do-exclusively --branch staging --job ${CIRCLE_JOB} npm run test:integration:kindolm:operator
268241
name: Operator integration tests on plain k8s
269-
- run:
270-
command: |
271-
scripts/operator/delete_operators_from_quay.py "${QUAY_USERNAME}" "${QUAY_PASSWORD}"
272-
name: Delete Operators from Quay
273-
when: always
274242
- run:
275243
command: |
276244
./scripts/slack/notify_failure_on_branch.py "${CIRCLE_BRANCH}" "${CIRCLE_JOB}" "${CIRCLE_BUILD_URL}" "${CIRCLE_PULL_REQUEST}" "${SLACK_WEBHOOK}"
@@ -342,10 +310,7 @@ jobs:
342310
name: create temp dir for logs
343311
- run:
344312
command: |
345-
echo "${OPENSHIFT4_ETC_HOSTS_ENTRY}" | sudo tee -a /etc/hosts
346-
name: Append an entry to the test environment to /etc/hosts
347-
- run:
348-
command: |
313+
export OPERATOR_VERSION="0.0.1-${CIRCLE_SHA1}"
349314
export KUBERNETES_MONITOR_IMAGE_NAME_AND_TAG=$(./scripts/circleci-jobs/setup-integration-tests.py)
350315
.circleci/do-exclusively --branch staging --job ${CIRCLE_JOB} npm run test:integration:openshift4:operator
351316
name: Integration tests OpenShift 4
@@ -957,14 +922,6 @@ workflows:
957922
requires:
958923
- build_image
959924
- build_and_upload_operator
960-
- delete_operators_from_quay:
961-
filters:
962-
branches:
963-
only:
964-
- staging
965-
requires:
966-
- integration_tests_operator_on_k8s
967-
- openshift4_integration_tests
968925
- tag_and_push:
969926
filters:
970927
branches:

.circleci/config/@config.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,6 @@ workflows:
7979
- build_image
8080
- build_and_upload_operator
8181
<<: *staging_branch_only_filter
82-
- delete_operators_from_quay:
83-
requires:
84-
- integration_tests_operator_on_k8s
85-
- openshift4_integration_tests
86-
<<: *staging_branch_only_filter
8782
- tag_and_push:
8883
requires:
8984
- build_image

.circleci/config/jobs/@jobs.yml

Lines changed: 6 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,10 @@ build_and_upload_operator:
3333
- setup_remote_docker
3434
- install_python_requests
3535
- run:
36-
name: Install operator-courier
37-
command: pip install operator-courier==2.1.7
38-
- run:
39-
name: Download Operator SDK
36+
name: Download Operator SDK and Operator Package Manager
4037
command: |
41-
RELEASE_VERSION=v0.15.1
42-
DOWNLOAD_LOCATION=./operator-sdk
43-
CURL_FOLLOW_REDIRECTS="-L"
44-
curl ${CURL_FOLLOW_REDIRECTS} https://github.com/operator-framework/operator-sdk/releases/download/${RELEASE_VERSION}/operator-sdk-${RELEASE_VERSION}-x86_64-linux-gnu -o ${DOWNLOAD_LOCATION}
45-
chmod +x ${DOWNLOAD_LOCATION}
38+
scripts/operator/download_operator_sdk.py
39+
scripts/operator/download_operator_package_manager.py
4640
- run:
4741
name: Create Operator and push Operator image to DockerHub
4842
command: |
@@ -60,17 +54,11 @@ build_and_upload_operator:
6054
OPERATOR_PATH=$(scripts/operator/package_operator_bundle.py "${SNYK_OPERATOR_VERSION}" "${SNYK_OPERATOR_IMAGE_TAG}" "${SNYK_MONITOR_IMAGE_TAG}")
6155
echo "export OPERATOR_PATH=$OPERATOR_PATH" >> $BASH_ENV
6256
- run:
63-
name: Upload Operator to Quay
57+
name: Create Operator Bundle and Index and push to Docker Hub
6458
command: |
65-
if [ "$CIRCLE_BRANCH" != "staging" ]; then
66-
exit 0
67-
fi
68-
export QUAY_TOKEN=$(scripts/operator/get_quay_token.py "${QUAY_USERNAME}" "${QUAY_PASSWORD}")
6959
export OPERATOR_DIR=$OPERATOR_PATH
70-
export QUAY_NAMESPACE=snyk-runtime
71-
export PACKAGE_NAME=snyk-operator
7260
export PACKAGE_VERSION="0.0.1-${CIRCLE_SHA1}"
73-
operator-courier push "${OPERATOR_DIR}" "${QUAY_NAMESPACE}" "${PACKAGE_NAME}" "${PACKAGE_VERSION}" "${QUAY_TOKEN}"
61+
scripts/operator/create_operator_bundle_and_index_and_push.py "${OPERATOR_DIR}" "${PACKAGE_VERSION}" "${DOCKERHUB_USER}" "${DOCKERHUB_PASSWORD}"
7462
- run:
7563
name: Notify Slack on failure
7664
command: |
@@ -278,13 +266,10 @@ openshift4_integration_tests:
278266
- run:
279267
name: create temp dir for logs
280268
command: mkdir -p /tmp/logs/test/integration/openshift4
281-
- run:
282-
name: Append an entry to the test environment to /etc/hosts
283-
command: |
284-
echo "${OPENSHIFT4_ETC_HOSTS_ENTRY}" | sudo tee -a /etc/hosts
285269
- run:
286270
name: Integration tests OpenShift 4
287271
command: |
272+
export OPERATOR_VERSION="0.0.1-${CIRCLE_SHA1}"
288273
export KUBERNETES_MONITOR_IMAGE_NAME_AND_TAG=$(./scripts/circleci-jobs/setup-integration-tests.py)
289274
.circleci/do-exclusively --branch staging --job ${CIRCLE_JOB} npm run test:integration:openshift4:operator
290275
- run:
@@ -295,22 +280,6 @@ openshift4_integration_tests:
295280
- store_artifacts:
296281
path: /tmp/logs/test/integration/openshift4
297282

298-
delete_operators_from_quay:
299-
docker:
300-
- image: circleci/python:3.9
301-
auth:
302-
username: $DOCKERHUB_USER
303-
password: $DOCKERHUB_PASSWORD
304-
working_directory: ~/kubernetes-monitor
305-
steps:
306-
- checkout
307-
- install_python_requests
308-
- run:
309-
name: Delete Operators from Quay
310-
command: |
311-
python3 scripts/operator/delete_operators_from_quay.py "${QUAY_USERNAME}" "${QUAY_PASSWORD}"
312-
when: always
313-
314283
######################## MERGE TO STAGING ########################
315284
tag_and_push:
316285
docker:

.circleci/config/jobs/integration_tests_operator_on_k8s.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,6 @@ steps:
1414
export KUBERNETES_MONITOR_IMAGE_NAME_AND_TAG=$(./scripts/circleci-jobs/setup-integration-tests.py)
1515
.circleci/do-exclusively --branch staging --job ${CIRCLE_JOB} npm run test:integration:kindolm:operator
1616
name: Operator integration tests on plain k8s
17-
- run:
18-
name: Delete Operators from Quay
19-
command: |
20-
scripts/operator/delete_operators_from_quay.py "${QUAY_USERNAME}" "${QUAY_PASSWORD}"
21-
when: always
2217
- run:
2318
command: |
2419
./scripts/slack/notify_failure_on_branch.py "${CIRCLE_BRANCH}" "${CIRCLE_JOB}" "${CIRCLE_BUILD_URL}" "${CIRCLE_PULL_REQUEST}" "${SLACK_WEBHOOK}"

.dockerignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,7 @@ snyk-operator
4444

4545
snyk-monitor-operator-source.yaml
4646
operator-sdk
47+
__pycache__
48+
opm
49+
.operator_version
50+
snyk-monitor-catalog-source.yaml

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,7 @@ snyk-operator/helm-charts
5555

5656
snyk-monitor-operator-source.yaml
5757
operator-sdk
58+
__pycache__
59+
opm
60+
.operator_version
61+
snyk-monitor-catalog-source.yaml

scripts/operator/create_operator.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from tempfile import mkdtemp
2424
from subprocess import call
2525
from os import chdir
26-
from shutil import copy, copytree, rmtree
26+
from shutil import copy, copytree
2727

2828

2929
def createOperatorAndBuildOperatorImage(operator_name_and_tag: str, monitor_tag: str) -> None:
@@ -56,8 +56,6 @@ def createOperatorAndBuildOperatorImage(operator_name_and_tag: str, monitor_tag:
5656
call([operator_sdk_path, "build", operator_name_and_tag])
5757
chdir(return_path)
5858

59-
rmtree(new_operator_dir)
60-
6159

6260
if __name__ == '__main__':
6361
_, operator_name_and_tag, monitor_tag = argv
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#! /usr/bin/python3
2+
3+
from os import chdir, environ, getcwd
4+
from subprocess import call
5+
from shutil import copy
6+
from sys import argv
7+
8+
9+
def createOperatorBundleAndIndexAndPushToDockerHub(operator_path: str, new_operator_tag: str, dockerhub_user: str, dockerhub_password: str) -> None:
10+
current_dir = getcwd()
11+
opm_copy_path = operator_path + "/" + "certified-operator/opm"
12+
copy(current_dir + "/" + "opm", opm_copy_path)
13+
14+
call(["docker", "login", "--username=" + dockerhub_user,
15+
"--password=" + dockerhub_password])
16+
17+
return_dir = current_dir
18+
chdir(operator_path + "/" + "certified-operator")
19+
print(operator_path + "/" + "certified-operator")
20+
environ['VERSION'] = new_operator_tag
21+
call(["make", "bundle-build"])
22+
call(["docker", "push", "snyk/kubernetes-operator-bundle" + ":" + new_operator_tag])
23+
24+
call([opm_copy_path, "index", "add", "-c", "docker", "--bundles", "snyk/kubernetes-operator-bundle" +
25+
":" + new_operator_tag, "--tag", "snyk/kubernetes-operator-index" + ":" + new_operator_tag])
26+
call(["docker", "push", "snyk/kubernetes-operator-index" + ":" + new_operator_tag])
27+
chdir(return_dir)
28+
29+
30+
if __name__ == '__main__':
31+
_, operator_path, new_operator_tag, dockerhub_user, dockerhub_password = argv
32+
createOperatorBundleAndIndexAndPushToDockerHub(
33+
operator_path, new_operator_tag, dockerhub_user, dockerhub_password)

scripts/operator/delete_operators_from_quay.py

Lines changed: 0 additions & 63 deletions
This file was deleted.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#! /usr/bin/python3
2+
3+
from os import chmod, getcwd
4+
from os.path import isfile
5+
from requests import get
6+
from platform import system
7+
8+
9+
def downloadOperatorPackageManager() -> None:
10+
cwd = getcwd()
11+
operator_package_manager_path = cwd + "/" + "opm"
12+
if isfile(operator_package_manager_path):
13+
print("OPM is present locally")
14+
return
15+
16+
current_sys = system()
17+
if current_sys == "Darwin":
18+
opm = get(
19+
"https://github.com/operator-framework/operator-registry/releases/download/v1.16.1/darwin-amd64-opm")
20+
else:
21+
opm = get(
22+
"https://github.com/operator-framework/operator-registry/releases/download/v1.16.1/linux-amd64-opm")
23+
24+
with open(operator_package_manager_path, "wb") as f:
25+
f.write(opm.content)
26+
chmod(operator_package_manager_path, 0o744)
27+
28+
29+
if __name__ == "__main__":
30+
downloadOperatorPackageManager()

0 commit comments

Comments
 (0)