Skip to content

Commit 2d25643

Browse files
committed
chore: increase Operator upgrade wait time to 5 mins and use polling
Sometimes it takes the Operator a bit longer than the 2 mins timeout to deploy an upgrade to the snyk-monitor.
1 parent 3e280dc commit 2d25643

File tree

2 files changed

+48
-14
lines changed

2 files changed

+48
-14
lines changed

.circleci/config.yml

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -469,17 +469,34 @@ jobs:
469469
source $BASH_ENV
470470
set -xeo pipefail
471471
472+
# Replace the catalog source with the latest bundled version of snyk-monitor, this is what initiates the upgrade
472473
sed -i.bak "s|${OPERATOR_VERSION}|${LATEST_TAG}|g" ./test/fixtures/operator/catalog-source.yaml
473474
kubectl apply -f ./test/fixtures/operator/catalog-source.yaml
474475
475-
sleep 120
476+
ATTEMPTS=60
477+
SLEEP_SECONDS_BETWEEN_ATTEMPTS=5
478+
# total = 5 minutes wait time
476479
477-
VERSION=$(kubectl get pods -n snyk-monitor --no-headers | \
478-
grep "snyk-monitor" | \
479-
awk 'END { if (NR==0) exit 1; else print $1 }' | \
480-
xargs -I{} kubectl get pod {} -n snyk-monitor -o jsonpath={..containers[*].image} | \
481-
awk '{print $1}' | grep -oE "[0-9]{1}\.[0-9]{1,2}\.[0-9]{1,3}$")
480+
# Periodically poll if the snyk-monitor has upgraded
481+
for (( attempt=1; attempt<ATTEMPTS; attempt++))
482+
do
483+
# Grab the tag of the snyk-monitor container image. If snyk-monitor is not deployed for some reason, we exit immediately.
484+
VERSION=$(kubectl get pods -n snyk-monitor --no-headers | \
485+
grep "snyk-monitor" | \
486+
awk 'END { if (NR==0) exit 1; else print $1 }' | \
487+
xargs -I{} kubectl get pod {} -n snyk-monitor -o jsonpath={..containers[*].image} | \
488+
awk '{print $1}' | grep -oE "[0-9]{1}\.[0-9]{1,2}\.[0-9]{1,3}$")
489+
490+
# Break out of the polling if the tag matches the one we want to upgrade to.
491+
if [[ "${VERSION}" == "${LATEST_TAG}" ]]; then
492+
break
493+
fi
494+
495+
# Otherwise keep polling
496+
sleep $SLEEP_SECONDS_BETWEEN_ATTEMPTS
497+
done
482498
499+
# If we polled for 5 minutes and the snyk-monitor still hasn't upgraded, fail the current job.
483500
if [[ "${VERSION}" != "${LATEST_TAG}" ]]; then
484501
&>2 echo "versions (${VERSION}) does not match expected (${LATEST_TAG})!"
485502
exit 1

.circleci/config/jobs/operator_upgrade_tests.yml

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -163,17 +163,34 @@ steps:
163163
source $BASH_ENV
164164
set -xeo pipefail
165165
166+
# Replace the catalog source with the latest bundled version of snyk-monitor, this is what initiates the upgrade
166167
sed -i.bak "s|${OPERATOR_VERSION}|${LATEST_TAG}|g" ./test/fixtures/operator/catalog-source.yaml
167168
kubectl apply -f ./test/fixtures/operator/catalog-source.yaml
168169
169-
sleep 120
170-
171-
VERSION=$(kubectl get pods -n snyk-monitor --no-headers | \
172-
grep "snyk-monitor" | \
173-
awk 'END { if (NR==0) exit 1; else print $1 }' | \
174-
xargs -I{} kubectl get pod {} -n snyk-monitor -o jsonpath={..containers[*].image} | \
175-
awk '{print $1}' | grep -oE "[0-9]{1}\.[0-9]{1,2}\.[0-9]{1,3}$")
176-
170+
ATTEMPTS=60
171+
SLEEP_SECONDS_BETWEEN_ATTEMPTS=5
172+
# total = 5 minutes wait time
173+
174+
# Periodically poll if the snyk-monitor has upgraded
175+
for (( attempt=1; attempt<ATTEMPTS; attempt++))
176+
do
177+
# Grab the tag of the snyk-monitor container image. If snyk-monitor is not deployed for some reason, we exit immediately.
178+
VERSION=$(kubectl get pods -n snyk-monitor --no-headers | \
179+
grep "snyk-monitor" | \
180+
awk 'END { if (NR==0) exit 1; else print $1 }' | \
181+
xargs -I{} kubectl get pod {} -n snyk-monitor -o jsonpath={..containers[*].image} | \
182+
awk '{print $1}' | grep -oE "[0-9]{1}\.[0-9]{1,2}\.[0-9]{1,3}$")
183+
184+
# Break out of the polling if the tag matches the one we want to upgrade to.
185+
if [[ "${VERSION}" == "${LATEST_TAG}" ]]; then
186+
break
187+
fi
188+
189+
# Otherwise keep polling
190+
sleep $SLEEP_SECONDS_BETWEEN_ATTEMPTS
191+
done
192+
193+
# If we polled for 5 minutes and the snyk-monitor still hasn't upgraded, fail the current job.
177194
if [[ "${VERSION}" != "${LATEST_TAG}" ]]; then
178195
&>2 echo "versions (${VERSION}) does not match expected (${LATEST_TAG})!"
179196
exit 1

0 commit comments

Comments
 (0)