Skip to content

Commit bd83de3

Browse files
authored
chore: improve racy logic in openshift-CI-kuttl-tests.sh (#1091)
Signed-off-by: Jonathan West <jgwest@gmail.com>
1 parent 9a57715 commit bd83de3

1 file changed

Lines changed: 60 additions & 2 deletions

File tree

scripts/openshift-CI-kuttl-tests.sh

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,34 @@
22

33
set -ex
44

5+
cleanup_on_failure() {
6+
local exit_code=$?
7+
if [ $exit_code -ne 0 ]; then
8+
echo ">> Script failed with exit code ${exit_code}, collecting debug logs..."
9+
echo ""
10+
echo "Pods in openshift-gitops-operator"
11+
oc get pods -n openshift-gitops-operator -o yaml
12+
echo ""
13+
echo "Operator pod log"
14+
oc logs deployment/openshift-gitops-operator-controller-manager -n openshift-gitops-operator
15+
echo ""
16+
echo "Events in openshift-gitops-operator"
17+
oc get events -n openshift-gitops-operator
18+
echo ""
19+
echo "ArgoCDs in test-argocd:"
20+
oc get argocds -n test-argocd -o yaml
21+
echo ""
22+
echo "Pods in test-argocd:"
23+
oc get pods -n test-argocd -o yaml
24+
echo ""
25+
echo "Events in test-argocd:"
26+
oc get events -n test-argocd
27+
echo ""
28+
fi
29+
exit $exit_code
30+
}
31+
trap cleanup_on_failure EXIT
32+
533
export CI="prow"
634
go mod vendor
735

@@ -32,10 +60,40 @@ metadata:
3260
namespace: test-argocd
3361
EOF
3462

35-
sleep 60s
63+
64+
EXPECTED_LABELS=("argocd-application-controller" "argocd-redis" "argocd-repo-server" "argocd-server")
65+
TIMEOUT=900
66+
INTERVAL=10
67+
ELAPSED=0
68+
69+
echo ">> Waiting for all ${#EXPECTED_LABELS[@]} ArgoCD pods to exist in test-argocd..."
70+
while true; do
71+
ALL_EXIST=true
72+
for label in "${EXPECTED_LABELS[@]}"; do
73+
if ! oc get pod -n test-argocd -l "app.kubernetes.io/name=${label}" --no-headers 2>/dev/null | grep -q .; then
74+
ALL_EXIST=false
75+
break
76+
fi
77+
done
78+
79+
if $ALL_EXIST; then
80+
echo ">> All ${#EXPECTED_LABELS[@]} ArgoCD pods exist after ${ELAPSED}s."
81+
break
82+
fi
83+
84+
if [ $ELAPSED -ge $TIMEOUT ]; then
85+
echo ">> Timed out after ${TIMEOUT}s waiting for ArgoCD pods to exist."
86+
oc get pods -n test-argocd
87+
exit 1
88+
fi
89+
90+
sleep $INTERVAL
91+
ELAPSED=$((ELAPSED + INTERVAL))
92+
done
3693

3794
oc get pods -n test-argocd
3895

39-
oc wait --for=condition=Ready -n test-argocd pod --timeout=15m -l 'app.kubernetes.io/name in (argocd-application-controller,argocd-redis,argocd-repo-server,argocd-server)'
96+
oc wait --for=condition=Ready -n test-argocd pod --timeout=15m \
97+
-l 'app.kubernetes.io/name in (argocd-application-controller,argocd-redis,argocd-repo-server,argocd-server)'
4098

4199
echo ">> Running tests on ${CI}"

0 commit comments

Comments
 (0)