Skip to content

Commit 39dc3c5

Browse files
guzalvclaude
andcommitted
Fix race condition in e2e compliance test setup
Problem: The install_e2e_compliance_resources() function was creating a TailoredProfile immediately after creating the CustomRule it references, without waiting for the CustomRule to be processed by the compliance operator. This caused a race condition where the TailoredProfile could fail to reach READY state if the CustomRule wasn't validated yet. Solution: Add a wait loop after creating the CustomRule to ensure it exists and give the compliance operator time to process it (10 seconds) before creating the TailoredProfile. Also improved error reporting to show the TailoredProfile's error message and current state during the wait loop. The e2e-tailored-profile.yaml references check-cm-marker CustomRule in its enableRules, so the CustomRule must be ready before the TailoredProfile can be validated successfully. Fixes: #19880 CI failure in ocp-4-21-compliance-e2e-tests Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 5dd8504 commit 39dc3c5

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

tests/e2e/lib.sh

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -563,8 +563,22 @@ install_the_compliance_operator() {
563563
install_e2e_compliance_resources() {
564564
info "Installing e2e custom rule and tailored profile"
565565
oc apply -f "${ROOT}/tests/e2e/yaml/compliance-operator/e2e-custom-rule.yaml"
566+
567+
# Wait for CustomRule to exist and give compliance operator time to process it
568+
info "Waiting for CustomRule check-cm-marker to be created and processed..."
569+
local retries=30
570+
for i in $(seq 1 $retries); do
571+
if oc get customrule check-cm-marker -n openshift-compliance &>/dev/null; then
572+
info "CustomRule check-cm-marker exists, waiting for compliance operator to process it"
573+
sleep 10
574+
break
575+
fi
576+
sleep 5
577+
done
578+
566579
oc apply -f "${ROOT}/tests/e2e/yaml/compliance-operator/e2e-tailored-profile.yaml"
567-
# Wait for TP to become READY
580+
581+
# Wait for TP to become READY with better error reporting
568582
local retries=30
569583
for i in $(seq 1 $retries); do
570584
state=$(oc get tailoredprofile e2e-tailored-profile -n openshift-compliance \
@@ -573,9 +587,15 @@ install_e2e_compliance_resources() {
573587
info "TailoredProfile e2e-tailored-profile is READY"
574588
return
575589
fi
590+
if [[ "$state" == "ERROR" ]]; then
591+
error_msg=$(oc get tailoredprofile e2e-tailored-profile -n openshift-compliance \
592+
-o jsonpath='{.status.errorMessage}' 2>/dev/null || true)
593+
die "TailoredProfile e2e-tailored-profile is in ERROR state: $error_msg"
594+
fi
595+
info "Waiting for TailoredProfile (attempt $i/$retries, current state: $state)"
576596
sleep 5
577597
done
578-
die "TailoredProfile e2e-tailored-profile did not become READY"
598+
die "TailoredProfile e2e-tailored-profile did not become READY after ${retries} attempts"
579599
}
580600

581601
setup_client_CA_auth_provider() {

0 commit comments

Comments
 (0)