11#! /bin/bash
22
3+ # Be strict about pipelines; failures are handled via retries.
4+ set -o pipefail
5+
36# Max number of retries
47MAX_RETRIES=7
58# Retry counter
69retry_count=0
710
11+ # Listing packagemanifests cluster-wide (-A) is expensive and can overload the API server during kind bootstrap.
12+ # PackageManifests are typically available in the "default" namespace (see e2e usage), so scope queries there.
13+ PACKAGEMANIFEST_NAMESPACE=" ${PACKAGEMANIFEST_NAMESPACE:- olm} "
14+
15+ # Give kubectl more time; kind+podman can be slow during OLM bootstrap.
16+ KUBECTL_TIMEOUT=" ${KUBECTL_TIMEOUT:- 60s} "
17+
818# Function to check the output and continue if the condition is met
919check_and_continue () {
1020 GREEN=$' \e [0;32m'
1121 NC=$' \e [0m'
1222 RED=$' \e [0;31m'
1323
14- # Run the command and count matching lines
15- result_count=$( kubectl get packagemanifest -A | grep -c GRC)
24+ # Fail fast if the API server isn't responding (avoids hammering it and causing TLS handshake timeouts).
25+ kubectl --request-timeout=" ${KUBECTL_TIMEOUT} " get --raw=/readyz > /dev/null 2>&1 || {
26+ echo " ${RED} API server not ready (readyz failed). Retrying...${NC} "
27+ return 1
28+ }
29+
30+ # PackageManifest names are just operator names (e.g. "example-operator") and won't include the catalog display
31+ # name. Use the standard table output (scoped to one namespace) so the "GRC mock operators" catalog display name
32+ # appears in the output for matching.
33+ output=" $( kubectl --request-timeout=" ${KUBECTL_TIMEOUT} " get packagemanifest -n " ${PACKAGEMANIFEST_NAMESPACE} " --no-headers 2>&1 ) "
34+ rc=$?
35+ if [ " $rc " -ne 0 ]; then
36+ echo " ${RED} kubectl failed (exit ${rc} ); will retry:${NC} "
37+ echo " ${RED}${output}${NC} "
38+ return 1
39+ fi
40+
41+ # Count matching lines
42+ result_count=" $( echo " ${output} " | grep -c GRC || true) "
1643
1744 if [ " $result_count " -gt 0 ]; then
1845 echo " ${GREEN} Found these grc fake operators..${NC} "
19- kubectl get packagemanifest -A | grep GRC
46+ echo " ${output} " | grep GRC
2047 echo " ${GREEN} GRC found ($result_count lines). Continuing...${NC} "
2148 return 0
2249 else
@@ -30,13 +57,13 @@ while ! check_and_continue; do
3057 retry_count=$(( retry_count + 1 ))
3158
3259 if [ " $retry_count " -ge " $MAX_RETRIES " ]; then
33- kubectl get catalogsource -n olm grc-mock-source -o yaml
34- kubectl get pod -n olm
35- kubectl describe pods -l olm.catalogSource=grc-mock-source -n olm
60+ kubectl --request-timeout= " ${KUBECTL_TIMEOUT} " get catalogsource -n olm grc-mock-source -o yaml || true
61+ kubectl --request-timeout= " ${KUBECTL_TIMEOUT} " get pod -n olm || true
62+ kubectl --request-timeout= " ${KUBECTL_TIMEOUT} " get packagemanifest -n " ${PACKAGEMANIFEST_NAMESPACE} " || true
3663 echo " ${RED} Max retries reached. Exiting.${NC} "
3764 exit 1
3865 fi
3966
40- # Wait before retrying
41- sleep 10
67+ # Wait before retrying (simple backoff)
68+ sleep $(( 10 + retry_count * 5 ))
4269done
0 commit comments