← Back to Pull requests

ARO-27732 - Remove the orphaned resources #5652

Closed
unknown closed this pull request without merging on Jun 25, 2026 11:21 UTC
View on GitHub
unknown unknown commented on Jun 15, 2026 13:56 UTC
Author

<!-- Link to Jira issue -->

What

Implement a new periodic controller to identify and clean up orphaned Azure cluster managed resource groups.

The controller:

  • Watches subscriptions using the shared SubscriptionWatchingController pattern.

  • Lists Azure resource groups in the subscription.

  • Filters only resource groups that:

  • - have a ManagedBy value;
    - are in the backend Azure location;
    - are managed by an HCP OpenShift cluster resource ID.
  • Lists HCP clusters from the database for the same subscription.

  • Builds a set of existing HCP cluster resource IDs.

  • Identifies managed resource groups whose ManagedBy resource ID points to an HCP cluster that no longer exists.

  • Uses structured Azure resource ID parsing and case-insensitive resource ID comparison.

  • Checks the current resource group state before attempting deletion.

  • Skips resource groups that are already being deleted.

  • Handles subscription processing independently so a failure in one subscription does not prevent processing of others.

  • Logs detected orphaned managed resource groups and cleanup actions for observability.

  • Emits metrics for detected orphaned managed resource groups and deletion failures.

  • Adds Prometheus alerts for orphaned managed resource group detection and cleanup failures.
  • Environment variables

    The controller is guarded behind environment variables so it can be rolled out safely:

  • CLEAN_ORPHANED_MANAGED_RESOURCE_GROUPS=enabled

  • - Enables the orphaned managed resource group cleanup controller.
    - If this variable is not set to enabled, the controller is not started.

  • CLEAN_ORPHANED_MANAGED_RESOURCE_GROUPS_MODE=readwrite

  • - Allows the controller to initiate deletion of orphaned managed resource groups.
    - By default, the controller runs in read-only mode and only logs what would be deleted.

    This allows the controller to be deployed first in detection/read-only mode, observed through logs, metrics, and alerts, and then switched to read-write mode once we are confident in the results.

    Alerts and metrics

    The PR adds Prometheus metrics for:

  • orphaned managed resource groups found;

  • orphaned managed resource group deletion failures.
  • The PR also adds alerts for:

  • orphaned managed resource groups being detected;

  • orphaned managed resource group deletion failures.
  • Why

    A previously identified race condition could leave Azure managed resource groups orphaned when cluster resources were not cleaned up correctly.

    Although the underlying race condition has been resolved, orphaned managed resource groups may still exist in customer subscriptions as a result of the historical bug.

    This controller provides the foundation for detecting and eventually removing those orphaned resources, helping reduce resource sprawl and unnecessary Azure consumption.

    Testing

    <!--
    Testing is required for feature completion and tests should
    be part of the pull request along with the feature changes.
    Describe the testing provided (unit, integration, e2e).

    If you did not add tests, provide a clear justification.
    -->

    Special notes for your reviewer

    The controller relies on the ManagedBy resource ID to determine whether a managed resource group is still associated with an existing HCP OpenShift cluster.

    A managed resource group is considered orphaned only when:

  • The resource group has a ManagedBy value.

  • The ManagedBy value points to an HCP OpenShift cluster resource ID.

  • That HCP OpenShift cluster no longer exists in the set of clusters listed from the database.
  • The commit history is intentionally granular to make the review easier. It will be squashed before merge.

    PR Checklist


  • PR is scoped to a single task (no mixed concerns)

  • Title follows Conventional Commits format

  • Summary explains the "Why" behind the change

  • Linked to relevant ticket/issue

  • Screenshots included (if graph/UI/metrics changes)

  • Self-reviewed the diff

  • CI/CD checks are passing (ignore Tide)

  • Draft PR used for WIP (if applicable)

  • Commit history is clean (rebased/squashed)

  • Tricky code blocks are commented

  • Specific reviewers tagged

  • All comment threads resolved before merge
  • Diff: 547 lines (+410 / -137) across 6 files Reviewer: ziccardi Review duration: 14244m
    All Vouch review confidence checks passed
    Residual risk 0.19 = Change Risk (0.48) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.48 · 547 lines diff across 6 files
    0.48
    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.377
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #5652"
    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: 48% (MEDIUM) · Higher = larger blast radius
    48%
    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: 19.0% · Safe to merge
    19.0%
    Repository