@@ -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