Skip to content

Commit db76426

Browse files
authored
Implement cluster operator stability check (#504)
Added a function to check the stability of OpenShift cluster operators before running tests.
1 parent 16ba1ea commit db76426

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

prow/integ-suite-ocp.sh

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,37 @@ set -u
5252
# Print commands
5353
set -x
5454

55+
check_cluster_operators() {
56+
# Check if jq is installed
57+
if ! command -v jq &> /dev/null; then
58+
echo "ERROR: jq is required for the cluster operator health check. Please install jq."
59+
exit 1
60+
fi
61+
62+
local timeout_seconds=600 # 10 minutes
63+
echo "Validating OpenShift cluster operators are stable..."
64+
local end_time=$(( $(date +%s) + timeout_seconds ))
65+
66+
while [ "$(date +%s)" -lt $end_time ]; do
67+
# This command uses jq to count operators that are not Available, or are Progressing, or are Degraded.
68+
# A healthy cluster should have a count of 0.
69+
local unstable_operators
70+
unstable_operators=$(oc get clusteroperator -o json | jq '[.items[] | select(.status.conditions[] | (.type == "Available" and .status == "False") or (.type == "Progressing" and .status == "True") or (.type == "Degraded" and .status == "True"))] | length')
71+
72+
if [[ $unstable_operators -eq 0 ]]; then
73+
echo "All cluster operators are stable."
74+
return 0
75+
fi
76+
77+
echo -n "."
78+
sleep 15
79+
done
80+
81+
echo "ERROR: Timeout reached. Not all cluster operators are stable."
82+
oc get clusteroperator
83+
exit 1
84+
}
85+
5586
# shellcheck source=common/scripts/kind_provisioner.sh
5687
source "${ROOT}/prow/setup/ocp_setup.sh"
5788

@@ -215,7 +246,7 @@ base_cmd+=("--istio.test.kube.helm.values=${helm_values}")
215246

216247
# Append sail operator setup script to base command
217248
if [ "${CONTROL_PLANE_SOURCE}" == "sail" ]; then
218-
# Remove timeout 60m
249+
# Remove timeout 60m
219250
for i in "${!base_cmd[@]}"; do
220251
if [[ "${base_cmd[$i]}" == "-timeout="* ]]; then
221252
unset 'base_cmd[i]'
@@ -235,6 +266,9 @@ if [ -n "${SKIP_TESTS}" ]; then
235266
base_cmd+=("-skip" "${SKIP_TESTS}")
236267
fi
237268

269+
# Check cluster operators are stable before starting the tests
270+
check_cluster_operators
271+
238272
# Execute the command and handle junit output
239273
if [ "${TEST_OUTPUT_FORMAT}" == "junit" ]; then
240274
echo "A junit report file will be generated"

0 commit comments

Comments
 (0)