← Back to Pull requests

fix(tools): unblock cleanup when workloads outlive their operator #3448

Closed
unknown closed this pull request without merging on Oct 28, 2026 12:58 UTC
View on GitHub
unknown unknown commented on Oct 27, 2026 19:08 UTC
Author

Summary

tools/cleanup no longer leaves AICR namespaces and CRDs stuck Terminating when 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 DynamoGraphDeployment or a Grove PodClique, the deletion hangs:

  • the instances keep finalizers only the uninstalled operator would remove, so the CRD stays Terminating and the next install of that operator fails on it;

  • the Terminating CRD 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 stays Terminating with NamespaceDeletionContentFailure.
  • Cleanup still printed "AICR cleanup complete", and the next deploy.sh failed its pre-flight check.

    Fixes: #3422
    Related: N/A

    Type of Change

  • Bug fix (non-breaking change that fixes an issue)

  • New feature (non-breaking change that adds functionality)

  • Breaking change (fix or feature that would cause existing functionality to change)

  • Documentation update

  • Refactoring (no functional changes)

  • Build/CI/tooling
  • Component(s) Affected

  • CLI (cmd/aicr, pkg/cli)

  • API server (cmd/aicrd, pkg/server)

  • Recipe engine / data (pkg/recipe)

  • Bundler and deployers (pkg/bundler, pkg/component)

  • Collectors / snapshotter (pkg/collector, pkg/snapshotter)

  • Validator (pkg/validator)

  • Core libraries (pkg/errors, pkg/k8s)

  • Docs/examples (docs/, examples/)

  • Other: tools/cleanup, DEVELOPMENT.md
  • Implementation Notes

    Phase 3, for the CRDs it deletes:

  • Before deleting a CRD whose conversion strategy is Webhook, it sets the strategy to None, 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.

  • After the existing short wait, for each CRD still Terminating, it clears the finalizers of instances the deletion has already marked. Instances in --exclude-ns namespaces 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-run logs the conversion change and skips the rescue and the final check.

    Testing

    go test -race ./tools/cleanup/
    golangci-lint run -c .golangci.yaml ./tools/cleanup/...
    make check-docs-filenames
    

  • tools/cleanup passes with -race. New tests in tools/cleanup/crds_test.go cover:

  • - 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-crds warning fires only for an AICR CRD whose webhook Service is gone. The fixture carries the port the 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".
  • With the conversion switch and the rescue calls removed, the phase 3 tests fail.

  • golangci-lint: 0 issues.

  • Not verified on a live cluster.

  • make qualify passes, including lint, e2e, scan and the API diffs. Total coverage is 86.2% against the 83% threshold.
  • Risk Assessment

  • Low — Isolated change, well-tested, easy to revert

  • Medium — Touches multiple components or has broader impact

  • High — Breaking change, affects critical paths, or complex rollout
  • Rollout notes: Developer tool only. Clearing finalizers applies only to instances already being deleted with their CRD.

    Checklist

  • Tests pass locally (make test with -race)

  • Linter passes (make lint)

  • I did not skip/disable tests to make CI green

  • I added/updated tests for new functionality

  • I updated docs if user-facing behavior changed

  • Changes follow existing patterns in the codebase

  • Commits are signed off and cryptographically signed (git commit -s -S) — GPG signing info
  • Diff: 650 lines (+487 / -163) across 8 files Reviewer: yuanchen8911 Review duration: 1069m
    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
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 20.5% · Safe to merge
    20.5%
    Repository