fix(bundler): add pre-flight finalizer check to undeploy.sh (#406)#561
Merged
fix(bundler): add pre-flight finalizer check to undeploy.sh (#406)#561
Conversation
Coverage Report ✅
Coverage BadgeNo Go source files changed in this PR. |
23 tasks
0960800 to
b242a3e
Compare
b242a3e to
bc8bc91
Compare
mchmarny
approved these changes
Apr 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add a pre-flight check to
undeploy.shthat detects custom resources with active finalizers on CRDs owned by bundle operators. Warns theuser and exits before teardown to prevent the unrecoverable hang described in #406.
Motivation / Context
undeploy.shhangs indefinitely when CRs have finalizers that require their controller to process, but the controller has already beenuninstalled. The deadlock:
delete_release_cluster_resources()deletes CRDs without--wait=false(line 81), the CRD'scustomresourcecleanupfinalizer blocks until all CR instances are gone, but CRs in user namespaces have controller-managed finalizers thatcan never be processed.
Fixes: #406
Related: N/A
Type of Change
Component(s) Affected
cmd/aicr,pkg/cli)cmd/aicrd,pkg/api,pkg/server)pkg/recipe)pkg/bundler,pkg/component/*)pkg/collector,pkg/snapshotter)pkg/validator)pkg/errors,pkg/k8s)docs/,examples/)Implementation Notes
Pre-flight check (
check_release_for_stuck_crds/check_crd_for_stuck_resources):helm get manifestto discover CRDs owned by each Helm component (generic — no hardcoded CRD group list needed).metadata.finalizershelm get manifestfailure →return 0)--skip-preflightflag to bypass when the user knows what they're doingComponent manifest: Lists all components that will be removed (with type tags:
[helm],[kustomize],[manifests]) so users can seeexactly what undeploy will do — important for shared components like cert-manager.
jq hard requirement: Replaced the
HAS_JQsoft-check with a hard gate. Removes ~8 branching guards throughout the script. jq wasalready effectively required for CRD cleanup and webhook handling to work correctly.
Stuck CRD handling: Changed the existing silent force-clear of CRD finalizers to a warning with remediation commands. Force-clearing CRD
finalizers can orphan CR data in etcd — the user should decide.
Testing
make qualify # all tests, lint, e2e pass; scan fails on pre-existing stdlib CVEs (go1.26.1→1.26.2)Unit tests (
pkg/bundler/deployer/helm/helm_test.go):New assertions verify:
HAS_JQ)check_release_for_stuck_crdsper componenthelm get manifestManual Kind cluster test (cert-manager + Issuer with fake finalizer):
Risk Assessment
Rollout notes: The pre-flight is additive — existing undeploy behavior is unchanged when no CRs with finalizers are found.
--skip-preflightprovides an escape hatch. The jq hard requirement could block users without jq, but jq was already effectively requiredfor correct operation.
Checklist
make testwith-race)make lint)git commit -S)