fix(tools): unblock cleanup when workloads outlive their operator #3448
All Vouch review confidence checks passed
Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #3448"
general
weight: 0.35
yuanchen8911
Summary
tools/cleanupno longer leaves AICR namespaces and CRDs stuckTerminatingwhen a user workload holds objects of an AICR CRD across a cleanup. It also stops reporting "complete" when something is still terminating.Motivation / Context
Phase 1 uninstalls the operators, and phase 3 then deletes their CRDs. When a user workload outside the AICR namespaces still holds instances, such as a
DynamoGraphDeploymentor a GrovePodClique, the deletion hangs:Terminatingand the next install of that operator fails on it;TerminatingCRD still names the operator's conversion webhook, so every list of the kind fails. The namespace controller lists every kind, so an empty AICR namespace staysTerminatingwithNamespaceDeletionContentFailure.Cleanup still printed "AICR cleanup complete", and the next
deploy.shfailed its pre-flight check.Fixes: #3422
Related: N/A
Type of Change
Component(s) Affected
cmd/aicr,pkg/cli)cmd/aicrd,pkg/server)pkg/recipe)pkg/bundler,pkg/component)pkg/collector,pkg/snapshotter)pkg/validator)pkg/errors,pkg/k8s)docs/,examples/)tools/cleanup,DEVELOPMENT.mdImplementation Notes
Phase 3, for the CRDs it deletes:
Webhook, it sets the strategy toNone, so the kind can still be listed once the operator is gone. Only CRDs being deleted are touched. If the delete then fails, the CRD is not counted as deleted, and cleanup warns that its webhook was left disabled.Terminating, it clears the finalizers of instances the deletion has already marked. Instances in--exclude-nsnamespaces are left alone, matching the existing namespace rescue. These objects are already being deleted with the CRD; nothing else would ever clear their finalizers.--keep-crds: a kept CRD must keep its webhook for the reinstalled operator, since Helm does not update CRDs that already exist. Cleanup leaves it alone and warns about each kept AICR CRD whose webhook Service is gone. It recommends reinstalling the operator before deleting namespaces, or adding--keep-namespaces.Final report: cleanup waits once more after phase 4, then names each CRD and namespace it tried to delete that still exists, with the namespace's deletion-failure condition. A namespace with no deletion timestamp, whose delete RBAC or admission refused, is reported as not deleted rather than as terminating. Only NotFound counts as gone; any other error is reported as "could not confirm" and counted as remaining. It ends with "AICR cleanup finished with resources still terminating" instead of "AICR cleanup complete". The exit status stays 0.
--dry-runlogs the conversion change and skips the rescue and the final check.Testing
tools/cleanuppasses with-race. New tests intools/cleanup/crds_test.gocover:- the conversion switch happens before the delete, with the expected patch body; excluded CRDs and dry runs are untouched;
- a failed CRD delete is not reported as deleted and warns that the webhook was left disabled;
- the instance rescue clears only instances already marked for deletion, and skips excluded namespaces;
- the
--keep-crdswarning fires only for an AICR CRD whose webhook Service is gone. The fixture carries theportthe API server defaults, which the first version of the check failed on;- the final report for stuck, refused-delete, all-gone and dry-run cases, a Get error counted as not confirmed, and a full run that ends with "still terminating" instead of "complete".
golangci-lint: 0 issues.make qualifypasses, including lint, e2e, scan and the API diffs. Total coverage is 86.2% against the 83% threshold.Risk Assessment
Rollout notes: Developer tool only. Clearing finalizers applies only to instances already being deleted with their CRD.
Checklist
make testwith-race)make lint)git commit -s -S) — GPG signing info