← Back to Pull requests

feat(mgmt-agent): add guarded SWIFT router Pod mitigation (AROSLSRE-2322) #7296

Open
unknown opened this pull request with 650 lines diff across 8 files
View on GitHub
unknown unknown commented on Oct 01, 2026 14:17 UTC
Author

AROSLSRE-2322

What

Add one controller to mgmt-agent for router Pods stuck creating their initial SWIFT network sandbox. It uses Kubernetes eviction to give the router Deployment a chance to create a working replacement. It does not cordon, drain or delete the Node.

Eligibility and safety

  • Selected routers only: the namespace, Pod and Deployment must match the opt-in policy, with a live Pod -> ReplicaSet -> stable router Deployment owner chain.

  • Initial sandbox failures only: no container has started, matching failures span at least 60 seconds, and activity is within the last 60 seconds.

  • Availability and capacity: router Pods on healthy Nodes must individually satisfy the Deployment's minReadySeconds and meet the configured floor. Replacement placement must fit within resource and scheduling limits. The search holds after 4,096 Pod/node attempts.

  • Safe replacement: the ReplicaSet template must meet the same safety rules, match the Pod's RuntimeClass, placement constraints and labels, and request no more resources than the Pod. Unsupported or mismatched templates hold eviction.
  • Admission allows canonical SWIFT-NIC and memory-pressure tolerations plus binding-added region/zone labels that match the source Node. Hard scheduling selectors depending on region/zone Pod labels hold admission rather than treating source labels as replacement labels. Eligibility logging is configuration-fenced.

    Eviction flow

    flowchart TD
        A["Router Pod with sustained SWIFT sandbox failures"] --> B{"Evidence, ownership, availability,<br/>placement and limits pass?"}
        B -- No --> H["Hold without eviction"]
        B -- Yes --> M{"Runtime mode"}
        M -- Audit --> L["Log eligibility, no writes"]
        M -- Enforce --> C["Claim the Pod and refresh live checks"]
        C --> R{"Still eligible and owned?"}
        R -- No --> H
        R -- Yes --> P["Persist the eviction attempt"]
        P -- Write failed --> H
        P -- Saved --> E["Request eviction for the exact Pod<br/>with UID and resourceVersion preconditions"]
        E --> O["Log the result<br/>Denied or uncertain attempts still count"]
    

    Configuration and accounting

    Disabled by default. The deployment flag gates controller construction, event-handler registration and the configuration informer. In an enabled deployment, runtime audit checks eligibility without writes, enforce permits guarded eviction, and disabled stops mitigation without a rollout.

    Eviction history lives in a separately initialized ConfigMap, survives restarts, and is never created or reset by the controller or Helm. Missing or invalid history blocks action. Denied, timed-out and uncertain attempts consume allowance.

    Why

    A management Node can be Ready while an individual router Pod keeps failing to create its network sandbox. This needs a Pod-level recovery action, not Node disruption.

    The safety checks matter even for a Pod that has never run: Kubernetes can evict Pending Pods without enforcing their PDB. The controller therefore checks router availability itself and accounts for other pending Pods and outstanding SWIFT NIC allocations when assessing capacity. There is no direct Pod deletion fallback.

    Testing

  • Full mgmt-agent race suite, executable build and lint pass.

  • Regression tests cover failure evidence, ownership and availability, configuration changes during admission, restart, durable limits, and denied or uncertain eviction. Placement tests cover pending demand, resource resizing, NIC accounting, scheduling constraints and the exact 4,096-attempt search limit.

  • Template-demand regressions cover CPU, memory, init containers and Pod-level requests in audit and enforce modes, plus a template change after the ownership claim. All nine hold cases detect the missing guard; matching templates and admission-injected NIC requests remain supported.

  • Template-safety regressions cover unsupported Pod settings, scheduling and label differences, storage policy and replacement ownership labels. All 60 hold cases detect the missing checks, including changes after the ownership claim. Default scheduler names and admission-added finite NoExecute tolerations remain supported.

  • Six RuntimeClass hold regressions detect added, removed or changed classes, including audit and pre/post-claim admission. Matching classes retain admitted overhead. Snapshot coverage checks per-node evidence, unscheduled and unknown-node Pods, and mismatched Event hosts.

  • Six Helm cases cover deployment enablement and all three runtime modes, including permissions and the absence of a rendered accounting ConfigMap. Helm test module lint and clean YAML/configuration generation checks pass.

  • Startup regression covers both deployment-flag values and preserves node-health and shared informers. The disabled case detects construction of the mitigation controller and its configuration informer.

  • Availability regressions cover missing/future Ready timestamps, the exact minReadySeconds boundary, disjoint healthy/available replicas, and readiness resets in audit and pre/post-claim admission. Eight hold cases detect the missing per-Pod check; zero-delay and mature replicas remain supported.
  • Admission compatibility and audit-fence regressions pass in the full mgmt-agent race suite and fail against the unfixed implementation. Audit and enforce tests cover the combined injected fields through admission and post-claim checks.

    Reconcile logs use the standard controller_name field. A worker regression checks the controller, inherited component and Pod fields on the emitted audit log.

    Personal DEV audit: one full passing run against the real Kubernetes API in westus3, using a local controller with a read-only transport and one isolated router fixture.

    | Check | Result |
    | --- | --- |
    | Floor 1, zero available replicas | Held |
    | Floor 0, synthetic sustained SWIFT evidence | Eligible |
    | Disabled mode, corrupt accounting, stale evidence | Held |
    | Re-enabled audit, fresh evidence | Eligible |
    | Same Pod recovered after fixture RuntimeClass repair | Not eligible |
    | Controller transport | 239 reads, zero write attempts |
    | Pod/ledger identity and cleanup | Preserved, fixtures removed, installed mgmt-agent unchanged |

    DEV audit evidence and harness include source provenance and local validation logs for clean commit e9bb2a5b1. The sandbox failure was real; the SWIFT Event was synthetic. This does not validate live eviction, SWIFT recovery or a production availability floor. Disabled, stale and recovered observations lasted 10 seconds each.

    Accounting conflict tests inject fake-client errors; a separate HTTP test checks the MTPNC resource path.

    Special notes for your reviewer

    Start with mgmt-agent/pkg/controller/swiftpod/eviction.go for the mitigation flow. The controller lives in mgmt-agent/pkg/controller/swiftpod:

    | File | Responsibility |
    | --- | --- |
    | controller.go | Pod-keyed scheduling, retries and the configuration fence. |
    | candidate.go | Initial sandbox-failure evidence, using shared node-health primitives without changing node-health behavior. |
    | workloads.go | Workload ownership, availability and replacement-template admission. |
    | placement.go | Bounded replacement capacity and scheduling checks. |
    | snapshot.go | Fresh cluster and delegated NIC reads, with single-pass Pod and Event indexes by Node for fault evaluation. |
    | budget.go | Durable eviction limits and attempt accounting. |
    | eviction.go | Ownership claim, fresh admission, attempt recording and guarded eviction. |
    | config.go | Runtime policy defaults, parsing and validation. |

    Each admission uses its own fresh snapshot. Startup wiring is in mgmt-agent/cmd/options.go; Helm, schema, generated configuration and module dependencies are included. The two conditional Helm templates are excluded from plain-YAML lint and covered by rendered Helm tests.

    Out of scope: generic mitigation frameworks, custom accounting APIs, never-ready mitigation, Node disruption, Azure operations and environment enablement. There are no pipeline, Dockerfile or Makefile changes.

    Limits: placement does not reserve capacity or guarantee a different destination Node or successful recovery. Operations documentation covers the full safety checks, configuration, accounting initialization and migration.

    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 dashboards or other UI 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
  • If E2E tests are included:

  • E2E tests follow Principles of Good E2E Test Case Design

  • If new E2E use case is covered (via a new test or new check/verifier),

  • demonstrate that the test is able to detect a defect/error and fail with
    proper error message and logs which communicates nature of the problem.

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: deads2k Review duration: 35690m
    All Vouch review confidence checks passed
    Residual risk 0.28 = Change Risk (0.52) × (1 − Review Confidence (0.47)). 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.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    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.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #7296"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% 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: 46.7% · Lower = rushed or shallow review
    46.7%
    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: 27.7% · Safe to merge
    27.7%
    Repository