Skip to content

Commit d9b0c98

Browse files
committed
chore: adjust Operator tests for OpenShift 4.6 and above
Version 4.6 introduced a breaking change to how Operators get deployed into the cluster and broke our integration tests. The tests now also reference the new test cluster on OpenShift Dedicated.
1 parent fe485bd commit d9b0c98

File tree

20 files changed

+524
-279
lines changed

20 files changed

+524
-279
lines changed

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

scripts/operator/delete_operators_from_quay.py

Lines changed: 0 additions & 63 deletions
This file was deleted.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
raise RuntimeError("Unsupported system " + current_sys)
22+
23+
with open(operator_package_manager_path, "wb") as f:
24+
f.write(opm.content)
25+
chmod(operator_package_manager_path, 0o744)
26+
27+
28+
if __name__ == "__main__":
29+
downloadOperatorPackageManager()

scripts/operator/get_quay_token.py

Lines changed: 0 additions & 24 deletions
This file was deleted.

scripts/operator/main.py

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,24 @@
1414
- DOCKERHUB_PASSWORD
1515
"""
1616

17-
from os import environ
17+
from os import environ, remove
1818
from hashlib import sha1
1919
from datetime import datetime
20+
from shutil import rmtree
2021
from subprocess import call
21-
from get_quay_token import getQuayToken
22+
from download_operator_package_manager import downloadOperatorPackageManager
2223
from create_operator_and_push import createOperatorAndPushToDockerHub
2324
from package_operator_bundle import createOperatorFromTemplate
24-
from upload_operator_bundle_to_quay import uploadOperatorBundleToQuay
2525
from download_operator_sdk import downloadOperatorSdk
26-
26+
from create_operator_bundle_and_index_and_push import createOperatorBundleAndIndexAndPushToDockerHub
2727

2828
if __name__ == '__main__':
2929
random_digest = sha1(str(datetime.now()).encode("utf-8")).hexdigest()
3030
operator_version = "0.0.1-" + random_digest
3131

32+
with open(".operator_version", "w") as f:
33+
f.write(operator_version)
34+
3235
try:
3336
new_monitor_tag = environ['KUBERNETES_MONITOR_IMAGE_TAG']
3437
except:
@@ -39,17 +42,10 @@
3942
call(["docker", "build", "-t", monitor_name_and_tag, "."])
4043
call(["docker", "push", monitor_name_and_tag])
4144

42-
print("Authenticating to Quay")
43-
quay_username = environ['QUAY_USERNAME']
44-
quay_password = environ['QUAY_PASSWORD']
45-
quay_token = getQuayToken(
46-
"https://quay.io/cnr/api/v1/users/login",
47-
quay_username,
48-
quay_password
49-
)
50-
5145
print("Downloading Operator SDK")
5246
downloadOperatorSdk()
47+
print("Downloading Operator Package Manager")
48+
downloadOperatorPackageManager()
5349
call(["pip3", "install", "operator-courier==2.1.7"])
5450

5551
print("Creating Operator image and pushing to DockerHub")
@@ -58,12 +54,17 @@
5854
createOperatorAndPushToDockerHub(
5955
operator_version, new_monitor_tag, dockerhub_user, dockerhub_password)
6056

61-
new_version = new_operator_tag = operator_version
57+
new_operator_tag = operator_version
6258

6359
print("Creating Operator bundle")
6460
operator_path = createOperatorFromTemplate(
6561
operator_version, new_operator_tag, new_monitor_tag)
66-
print("Pushing Operator bundle to Quay")
67-
uploadOperatorBundleToQuay(
68-
operator_path, "snyk-runtime-local", "snyk-operator", operator_version, quay_token)
69-
print("Operator version " + operator_version + " has been pushed to Quay")
62+
print("Pushing Operator bundle")
63+
createOperatorBundleAndIndexAndPushToDockerHub(
64+
operator_path, new_operator_tag, dockerhub_user, dockerhub_password)
65+
print("Operator version " + operator_version +
66+
" has been pushed to Docker Hub")
67+
68+
# rmtree(operator_path)
69+
# remove("operator-sdk")
70+
# remove("opm")

scripts/operator/package_operator_bundle.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from tempfile import mkdtemp
44
from os import mkdir
55
from datetime import datetime
6-
from shutil import copy
6+
from shutil import copy, copytree
77
from sys import argv
88

99

@@ -46,6 +46,13 @@ def createOperatorFromTemplate(new_version: str, new_operator_tag: str, new_moni
4646
with open(new_manifest_path, "w") as f:
4747
f.write(updated_manifest)
4848

49+
copytree("snyk-operator/certified-operator",
50+
new_operator_dir + "/" + "certified-operator")
51+
copy(new_csv_path, new_operator_dir + "/" + "certified-operator/bundle/manifests" +
52+
"/" + "snyk-operator.v" + new_version + ".clusterserviceversion.yaml")
53+
copy(new_crd_path, new_operator_dir + "/" + "certified-operator/bundle/manifests" +
54+
"/" + "snykmonitors.charts.helm.k8s.io.crd.yaml")
55+
4956
return new_operator_dir
5057

5158

scripts/operator/upload_operator_bundle_to_quay.py

Lines changed: 0 additions & 15 deletions
This file was deleted.

scripts/test-openshift4.sh

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
# - See test/README-OPENSHIFT4.md for instructions (skip if already done).
1111
#
1212
# The following environment variables:
13-
# - QUAY_USERNAME (search in 1Password: xnz2hv2h3bdwriove2zlbnlwhq)
14-
# - QUAY_PASSWORD (search in 1Password: xnz2hv2h3bdwriove2zlbnlwhq)
1513
# - DOCKERHUB_USER (search in 1Password: mrvhrhni3jdj3mjzlf3u3zfhgm)
1614
# - DOCKERHUB_PASSWORD (search in 1Password: mrvhrhni3jdj3mjzlf3u3zfhgm)
1715
# - OPENSHIFT4_USER (crc console --credentials)
@@ -23,6 +21,8 @@
2321
# Choose a published tag from https://github.com/snyk/kubernetes-monitor/releases.
2422
#
2523

24+
set -eo pipefail
25+
2626
function validateEnvVar {
2727
var_name="$1"
2828
var_value="$2"
@@ -32,18 +32,13 @@ function validateEnvVar {
3232
fi
3333
}
3434

35-
validateEnvVar QUAY_USERNAME "$QUAY_USERNAME"
36-
validateEnvVar QUAY_PASSWORD "$QUAY_PASSWORD"
3735
validateEnvVar DOCKERHUB_USER "$DOCKERHUB_USER"
3836
validateEnvVar DOCKERHUB_PASSWORD "$DOCKERHUB_PASSWORD"
3937
validateEnvVar OPENSHIFT4_USER "$OPENSHIFT4_USER"
4038
validateEnvVar OPENSHIFT4_PASSWORD "$OPENSHIFT4_PASSWORD"
4139
validateEnvVar OPENSHIFT4_CLUSTER_URL "$OPENSHIFT4_CLUSTER_URL"
4240

4341
if [ "${CI}" != "true" ]; then
44-
# Ensure any left-over Operators don't interfere with this test run
45-
python3 scripts/operator/delete_operators_from_quay.py "${QUAY_USERNAME}" "${QUAY_PASSWORD}"
46-
4742
if [ "$KUBERNETES_MONITOR_IMAGE_TAG" == "" ]; then
4843
RED_COLOR='\033[0;31m'
4944
NO_COLOR='\033[0m'
@@ -58,10 +53,14 @@ if [ "${CI}" != "true" ]; then
5853
sleep 10
5954
fi
6055

61-
# no-op if already started:
62-
crc start
63-
64-
oc login -u "${OPENSHIFT4_USER}" -p "${OPENSHIFT4_PASSWORD}" "${OPENSHIFT4_CLUSTER_URL}" --insecure-skip-tls-verify=true
56+
# Check if we're testing against a local OpenShift cluster
57+
if [ "${OPENSHIFT4_CLUSTER_URL}" == "https://api.crc.testing:6443" ]; then
58+
# no-op if already started:
59+
crc start
60+
oc login -u "${OPENSHIFT4_USER}" -p "${OPENSHIFT4_PASSWORD}" "${OPENSHIFT4_CLUSTER_URL}" --insecure-skip-tls-verify=true
61+
else
62+
oc login --token="${OPENSHIFT4_PASSWORD}" --server="${OPENSHIFT4_CLUSTER_URL}"
63+
fi
6564

6665
python3 scripts/operator/main.py
6766
fi

0 commit comments

Comments
 (0)