Skip to content

Commit b12bea9

Browse files
authored
Merge pull request #1054 from snyk/chore/operator-upgrade-tests
fix: fix flaky operator upgrade tests and wrong ubi image
2 parents a1d60f4 + cadfe80 commit b12bea9

File tree

4 files changed

+42
-32
lines changed

4 files changed

+42
-32
lines changed

.circleci/config.yml

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ jobs:
513513
514514
# Package Operator Bundle to be uploaded to Docker Hub
515515
SNYK_OPERATOR_IMAGE_TAG=${OPERATOR_VERSION}
516-
SNYK_MONITOR_IMAGE_TAG=${OPERATOR_VERSION}
516+
SNYK_MONITOR_IMAGE_TAG=${OPERATOR_VERSION}-ubi8
517517
OPERATOR_DIR=$(python scripts/operator/package_operator_bundle.py $OPERATOR_VERSION $SNYK_OPERATOR_IMAGE_TAG $SNYK_MONITOR_IMAGE_TAG)
518518
519519
python scripts/operator/create_operator_bundle_and_index_and_push.py $OPERATOR_DIR $OPERATOR_VERSION $DOCKERHUB_USER $DOCKERHUB_PASSWORD
@@ -582,8 +582,8 @@ jobs:
582582
set -eo pipefail
583583
584584
REPLACES_VERSION=${OPERATOR_VERSION}
585-
586-
OPERATOR_DIR=$(python scripts/operator/package_operator_bundle.py "${LATEST_TAG}" "${LATEST_TAG}" "${LATEST_TAG}" "${REPLACES_VERSION}")
585+
SNYK_MONITOR_TAG=${LATEST_TAG}-ubi8
586+
OPERATOR_DIR=$(python scripts/operator/package_operator_bundle.py "${LATEST_TAG}" "${LATEST_TAG}" "${SNYK_MONITOR_TAG}" "${REPLACES_VERSION}")
587587
python scripts/operator/create_operator_bundle_and_index_and_push.py $OPERATOR_DIR $LATEST_TAG $DOCKERHUB_USER $DOCKERHUB_PASSWORD $REPLACES_VERSION
588588
description: Now we are testing that any upgrades to the Operator are detected and applied in the cluster.
589589
name: Package Operator Bundle upgrade and push to Docker Hub
@@ -600,18 +600,21 @@ jobs:
600600
SLEEP_SECONDS_BETWEEN_ATTEMPTS=5
601601
# total = 10 minutes wait time
602602
603+
EXPECTED_TAG="${LATEST_TAG}-ubi8"
603604
# Periodically poll if the snyk-monitor has upgraded
604605
for (( attempt=1; attempt<ATTEMPTS; attempt++))
605606
do
606-
# Grab the tag of the snyk-monitor container image. If snyk-monitor is not deployed for some reason, we exit immediately.
607-
VERSION=$(kubectl get pods -n snyk-monitor --no-headers | \
608-
grep "snyk-monitor" | \
609-
awk 'END { if (NR==0) exit 1; else print $1 }' | \
610-
xargs -I{} kubectl get pod {} -n snyk-monitor -o jsonpath={..containers[*].image} | \
611-
awk '{print $1}' | grep -oE "[0-9]{1}\.[0-9]{1,2}\.[0-9]{1,3}$")
607+
# Grab the tag of the snyk-monitor container image.
608+
SNYK_MONITOR_POD=$(kubectl get pods -n snyk-monitor --no-headers | grep "snyk-monitor")
609+
if [[ ! -z "${SNYK_MONITOR_POD}" ]]; then
610+
VERSION=$(echo "${SNYK_MONITOR_POD}" | \
611+
awk 'END { print $1 }' | \
612+
xargs '-I{}' kubectl get pod '{}' -n snyk-monitor -o 'jsonpath={..containers[*].image}' | \
613+
grep -oE "[0-9]{1}\.[0-9]{1,2}\.[0-9]{1,3}$")
614+
fi
612615
613616
# Break out of the polling if the tag matches the one we want to upgrade to.
614-
if [[ "${VERSION}" == "${LATEST_TAG}" ]]; then
617+
if [[ "${VERSION}" == "${EXPECTED_TAG}" ]]; then
615618
break
616619
fi
617620
@@ -621,17 +624,17 @@ jobs:
621624
622625
SNYK_MONITOR_POD=$(kubectl get pods -n snyk-monitor --no-headers | \
623626
grep "snyk-monitor" | \
624-
awk 'END { if (NR==0) exit 1; else print $1 }')
627+
awk 'END { if (NR==0) exit 101; else print $1 }')
625628
626629
# If we polled for 5 minutes and the snyk-monitor still hasn't upgraded, fail the current job.
627-
if [[ "${VERSION}" != "${LATEST_TAG}" ]]; then
628-
&>2 echo "versions (${VERSION}) does not match expected (${LATEST_TAG})!"
630+
if [[ "${VERSION}" != "${EXPECTED_TAG}" ]]; then
631+
&>2 echo "versions (${VERSION}) does not match expected (${EXPECTED_TAG})!"
629632
630633
kubectl describe pod ${SNYK_MONITOR_POD} -n snyk-monitor
631634
kubectl describe catalogsource snyk-operator -n openshift-marketplace
632635
kubectl get snykmonitors.charts.helm.k8s.io -n snyk-monitor -o yaml
633636
634-
exit 1
637+
exit 102
635638
fi
636639
637640
# We need to wait for the Pod to become Ready
@@ -787,7 +790,8 @@ jobs:
787790
name: End tests early if no new Operator is to be released
788791
- run:
789792
command: |
790-
OPERATOR_PATH=$(python scripts/operator/package_operator_bundle.py "${NEW_OPERATOR_VERSION}" "${NEW_OPERATOR_VERSION}" "${NEW_OPERATOR_VERSION}" "${LAST_OPERATOR_VERSION}")
793+
SNYK_MONITOR_TAG="${NEW_OPERATOR_VERSION}-ubi8"
794+
OPERATOR_PATH=$(python scripts/operator/package_operator_bundle.py "${NEW_OPERATOR_VERSION}" "${NEW_OPERATOR_VERSION}" "${SNYK_MONITOR_TAG}" "${LAST_OPERATOR_VERSION}")
791795
echo "export OPERATOR_PATH=${OPERATOR_PATH}" >> $BASH_ENV
792796
name: Package Operator Bundle
793797
- run:
@@ -853,7 +857,8 @@ jobs:
853857
name: End tests early if no new Operator is to be released
854858
- run:
855859
command: |
856-
OPERATOR_PATH=$(python scripts/operator/package_operator_bundle.py "${NEW_OPERATOR_VERSION}" "${NEW_OPERATOR_VERSION}" "${NEW_OPERATOR_VERSION}" "${LAST_OPERATOR_VERSION}")
860+
SNYK_MONITOR_TAG="${NEW_OPERATOR_VERSION}-ubi8"
861+
OPERATOR_PATH=$(python scripts/operator/package_operator_bundle.py "${NEW_OPERATOR_VERSION}" "${NEW_OPERATOR_VERSION}" "${SNYK_MONITOR_TAG}" "${LAST_OPERATOR_VERSION}")
857862
echo "export OPERATOR_PATH=${OPERATOR_PATH}" >> $BASH_ENV
858863
name: Package Operator Bundle
859864
- run:

.circleci/config/jobs/operator_upgrade_tests.yml

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ steps:
8383
8484
# Package Operator Bundle to be uploaded to Docker Hub
8585
SNYK_OPERATOR_IMAGE_TAG=${OPERATOR_VERSION}
86-
SNYK_MONITOR_IMAGE_TAG=${OPERATOR_VERSION}
86+
SNYK_MONITOR_IMAGE_TAG=${OPERATOR_VERSION}-ubi8
8787
OPERATOR_DIR=$(python scripts/operator/package_operator_bundle.py $OPERATOR_VERSION $SNYK_OPERATOR_IMAGE_TAG $SNYK_MONITOR_IMAGE_TAG)
8888
8989
python scripts/operator/create_operator_bundle_and_index_and_push.py $OPERATOR_DIR $OPERATOR_VERSION $DOCKERHUB_USER $DOCKERHUB_PASSWORD
@@ -157,8 +157,8 @@ steps:
157157
set -eo pipefail
158158
159159
REPLACES_VERSION=${OPERATOR_VERSION}
160-
161-
OPERATOR_DIR=$(python scripts/operator/package_operator_bundle.py "${LATEST_TAG}" "${LATEST_TAG}" "${LATEST_TAG}" "${REPLACES_VERSION}")
160+
SNYK_MONITOR_TAG=${LATEST_TAG}-ubi8
161+
OPERATOR_DIR=$(python scripts/operator/package_operator_bundle.py "${LATEST_TAG}" "${LATEST_TAG}" "${SNYK_MONITOR_TAG}" "${REPLACES_VERSION}")
162162
python scripts/operator/create_operator_bundle_and_index_and_push.py $OPERATOR_DIR $LATEST_TAG $DOCKERHUB_USER $DOCKERHUB_PASSWORD $REPLACES_VERSION
163163
164164
- run:
@@ -175,18 +175,21 @@ steps:
175175
SLEEP_SECONDS_BETWEEN_ATTEMPTS=5
176176
# total = 10 minutes wait time
177177
178+
EXPECTED_TAG="${LATEST_TAG}-ubi8"
178179
# Periodically poll if the snyk-monitor has upgraded
179180
for (( attempt=1; attempt<ATTEMPTS; attempt++))
180181
do
181-
# Grab the tag of the snyk-monitor container image. If snyk-monitor is not deployed for some reason, we exit immediately.
182-
VERSION=$(kubectl get pods -n snyk-monitor --no-headers | \
183-
grep "snyk-monitor" | \
184-
awk 'END { if (NR==0) exit 1; else print $1 }' | \
185-
xargs -I{} kubectl get pod {} -n snyk-monitor -o jsonpath={..containers[*].image} | \
186-
awk '{print $1}' | grep -oE "[0-9]{1}\.[0-9]{1,2}\.[0-9]{1,3}$")
182+
# Grab the tag of the snyk-monitor container image.
183+
SNYK_MONITOR_POD=$(kubectl get pods -n snyk-monitor --no-headers | grep "snyk-monitor")
184+
if [[ ! -z "${SNYK_MONITOR_POD}" ]]; then
185+
VERSION=$(echo "${SNYK_MONITOR_POD}" | \
186+
awk 'END { print $1 }' | \
187+
xargs '-I{}' kubectl get pod '{}' -n snyk-monitor -o 'jsonpath={..containers[*].image}' | \
188+
grep -oE "[0-9]{1}\.[0-9]{1,2}\.[0-9]{1,3}$")
189+
fi
187190
188191
# Break out of the polling if the tag matches the one we want to upgrade to.
189-
if [[ "${VERSION}" == "${LATEST_TAG}" ]]; then
192+
if [[ "${VERSION}" == "${EXPECTED_TAG}" ]]; then
190193
break
191194
fi
192195
@@ -196,17 +199,17 @@ steps:
196199
197200
SNYK_MONITOR_POD=$(kubectl get pods -n snyk-monitor --no-headers | \
198201
grep "snyk-monitor" | \
199-
awk 'END { if (NR==0) exit 1; else print $1 }')
202+
awk 'END { if (NR==0) exit 101; else print $1 }')
200203
201204
# If we polled for 5 minutes and the snyk-monitor still hasn't upgraded, fail the current job.
202-
if [[ "${VERSION}" != "${LATEST_TAG}" ]]; then
203-
&>2 echo "versions (${VERSION}) does not match expected (${LATEST_TAG})!"
205+
if [[ "${VERSION}" != "${EXPECTED_TAG}" ]]; then
206+
&>2 echo "versions (${VERSION}) does not match expected (${EXPECTED_TAG})!"
204207
205208
kubectl describe pod ${SNYK_MONITOR_POD} -n snyk-monitor
206209
kubectl describe catalogsource snyk-operator -n openshift-marketplace
207210
kubectl get snykmonitors.charts.helm.k8s.io -n snyk-monitor -o yaml
208211
209-
exit 1
212+
exit 102
210213
fi
211214
212215
# We need to wait for the Pod to become Ready

.circleci/config/jobs/push_operator_to_community_operators.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ steps:
4848
- run:
4949
name: Package Operator Bundle
5050
command: |
51-
OPERATOR_PATH=$(python scripts/operator/package_operator_bundle.py "${NEW_OPERATOR_VERSION}" "${NEW_OPERATOR_VERSION}" "${NEW_OPERATOR_VERSION}" "${LAST_OPERATOR_VERSION}")
51+
SNYK_MONITOR_TAG="${NEW_OPERATOR_VERSION}-ubi8"
52+
OPERATOR_PATH=$(python scripts/operator/package_operator_bundle.py "${NEW_OPERATOR_VERSION}" "${NEW_OPERATOR_VERSION}" "${SNYK_MONITOR_TAG}" "${LAST_OPERATOR_VERSION}")
5253
echo "export OPERATOR_PATH=${OPERATOR_PATH}" >> $BASH_ENV
5354
5455
- run:

.circleci/config/jobs/push_operator_to_embedded_community_operators.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ steps:
4848
- run:
4949
name: Package Operator Bundle
5050
command: |
51-
OPERATOR_PATH=$(python scripts/operator/package_operator_bundle.py "${NEW_OPERATOR_VERSION}" "${NEW_OPERATOR_VERSION}" "${NEW_OPERATOR_VERSION}" "${LAST_OPERATOR_VERSION}")
51+
SNYK_MONITOR_TAG="${NEW_OPERATOR_VERSION}-ubi8"
52+
OPERATOR_PATH=$(python scripts/operator/package_operator_bundle.py "${NEW_OPERATOR_VERSION}" "${NEW_OPERATOR_VERSION}" "${SNYK_MONITOR_TAG}" "${LAST_OPERATOR_VERSION}")
5253
echo "export OPERATOR_PATH=${OPERATOR_PATH}" >> $BASH_ENV
5354
5455
- run:

0 commit comments

Comments
 (0)