Skip to content

Commit 29da915

Browse files
jrhynessclaude
andcommitted
fix: wait for CR finalizers before deleting operators
Addresses Code Rabbit review: the script was deleting operators immediately after requesting CR deletion, which could interrupt finalizer processing if the deletion was still in progress. Changes: - Add polling loop after CR deletion to wait for finalizers to complete - Check every 2 seconds for up to 60 seconds that all CRs are gone - Only proceed to delete Subscriptions/CSVs after CRs are confirmed deleted - Warn if CRs are still stuck after timeout (indicates stuck finalizers) - Use wc -l with arithmetic to count CRs (avoids grep -vc || echo issues) - Properly handle empty output (0 lines = 0 CRs) This ensures operators have time to properly clean up Deployments, ReplicaSets, and Pods before we remove the operators themselves, preventing orphaned resources. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 1ae57fc commit 29da915

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

.github/hack/cleanup-odh.sh

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,26 @@ for policy_ns in kuadrant-system rh-connectivity-link; do
127127
kubectl delete kuadrant --all -n "$policy_ns" --ignore-not-found --timeout=60s 2>/dev/null || true
128128
kubectl delete limitador --all -n "$policy_ns" --ignore-not-found --timeout=60s 2>/dev/null || true
129129
kubectl delete authorino --all -n "$policy_ns" --ignore-not-found --timeout=60s 2>/dev/null || true
130-
echo " ✅ Workload CRs deleted from $policy_ns"
130+
131+
# Wait for CRs to be fully deleted (finalizers processed) before removing operators
132+
# This prevents orphaned resources if we delete operators while finalizers are still running
133+
echo " Waiting for CR finalizers to complete in $policy_ns..."
134+
timeout=60
135+
deadline=$((SECONDS + timeout))
136+
remaining=1
137+
while [[ $SECONDS -lt $deadline ]]; do
138+
# Count remaining CRs (wc -l counts all lines, subtract 1 for header if present)
139+
count=$(kubectl get kuadrant,limitador,authorino -n "$policy_ns" --ignore-not-found 2>/dev/null | wc -l)
140+
remaining=$((count > 0 ? count - 1 : 0))
141+
if [[ $remaining -eq 0 ]]; then
142+
echo " ✅ All workload CRs deleted from $policy_ns"
143+
break
144+
fi
145+
sleep 2
146+
done
147+
if [[ $remaining -gt 0 ]]; then
148+
echo " ⚠️ Warning: $remaining CR(s) still exist in $policy_ns after ${timeout}s (finalizers may be stuck)"
149+
fi
131150
fi
132151
done
133152

0 commit comments

Comments
 (0)