← Back to Pull requests

feat(backend): manage cluster role assignments through deployment stacks #7536

Closed
unknown closed this pull request without merging on Oct 15, 2026 01:56 UTC
View on GitHub
unknown unknown commented on Oct 14, 2026 18:56 UTC
Author

Why

Separate cluster role-assignment policy from Azure execution using durable Cosmos stack intent. A single authoritative deployment stack manages the desired assignments and removes assignments omitted from subsequent templates.

No tracking ticket was supplied; this PR implements the requested mechanism and its first producer together.

What

  • Add cluster-rooted StackDesire documents, typed storage/listers/informers, and a dedicated controller watching only those documents.

  • Call the standard Deployment Stacks SDK directly from the controller for Apply/Delete at resource-group, subscription, and management-group scopes, with explicit FPA/SMI authentication and existing build-derived telemetry. Credential builders return concrete SDK clients; no custom stack client or dedicated client mocks remain.

  • Use one typed Spec.Stack for Apply and Delete; deletion settings come from its Properties.ActionOnUnmanage policy.

  • Keep one current typed outcome: spec hash, SDK stack or rejection error, observation timestamp, and SuccessfullyApplied/SuccessfullyDeleted/Degraded conditions. No historical-success reuse or duplicated target/correlation fields.

  • Factor immutable input-to-action decisions from explicit Apply and Delete execution. Apply creates an absent stack immediately, without an observation checkpoint. Each status-write pass makes one original-ETag Cosmos replacement and exits; Azure submission plus recording its result is the sole exception. Conflicts return errors rather than merging into newer intent.

  • Require explicit actions, including NoOp; reject zero-valued decisions. Initial Apply responses and associated GETs share Apply-state interpretation without conflating it with the current desired action or Delete acceptance. Action-focused logs explain submission attempts and changed observations; unchanged polls and cooldowns stay silent.

  • Capture the initial Apply response because the SDK poller cannot expose its typed stack until completion. Retain the body correlation in the typed stack for later Apply observations. Delete uses ordinary SDK returns, observes progress with GET, and succeeds on confirmed absence; it has no separate correlation tracking.

  • Compute success and invalid-intent cooldowns from the document's spec hash, recorded outcome timestamp, and configured interval, regardless of the event source. Read failures only return errors; pending operations request polling; execution errors retry through the queue. Changed intent bypasses the bounded cooldown.

  • Aggregate current-spec StackDesire degradation directly into cluster health, independently of producer reconciliation health.

  • Refactor IdentityRoleAssignments to publish one complete MRG stack with stable assignment names and consume current-outcome success for readiness. Purging the desire stops reconciliation; MRG deletion owns Azure cleanup.
  • Status is a last observation, not instantaneous live truth. Unknown submission outcomes recover by observation and, when needed, redundant application. Bounded stale observations across crashes and intent reversions are accepted until periodic repair. Producers own sequencing, target immutability, and avoiding competing desires.

    Testing

  • Full backend tests and internal core API/database tests passed.

  • Focused race tests and scoped lint passed.

  • make generate completed without additional changes; make verify-json-format passed. make tidy is stable, and independent readonly dependency resolution passed across workspace modules.

  • Pure decision and executor tests cover input immutability, one mutation per pass, original-ETag conflicts, failed reads without writes, polling, rejection stability, correlation recovery, current-outcome readiness, and cooldown behavior.

  • Direct SDK HTTP-transport tests cover scope routing and unified Apply/Delete policy. Regression tests cover bounded invalid-intent retries, disjoint action validation, no-write GET failures, condition construction, and current-spec health aggregation.

  • Manual isolated Azure CLI probes supply nine sanitized response fixtures covering malformed templates, validation, nested failures, permission failure and same-intent recovery after permission correction. Offline verification checks fixtures, unchanged request hashes, sanitization, and cleanup evidence. A separate Delete probe observed 202 with an empty body, a subsequent GET in deleting, and then 404. Probe resources were deleted and verified absent.

  • The included probe scripts are operator-run and opt-in, not CI. This PR adds executable scripts to a testdata directory. Manual human review recommended before merge, particularly for temporary identity creation, narrowly scoped role assignments, credential handling, and cleanup.

  • Unit and Azure API characterization coverage do not establish deployed end-to-end cluster lifecycle correctness; existing-role adoption, managed omissions and teardown require rollout validation.
  • Retry Contract

    An unchanged invalid-intent outcome is eligible again only after its configured interval, using persisted state and time rather than event filtering. New rejected attempts renew that interval even when diagnostics are identical; unchanged GET observations do not write. Completed-operation metadata does not restart the interval, and condition transition timestamps change only when their truth value changes.

    Invalid intent is narrowly identified by InvalidTemplate or InvalidRequestContent, directly or as all direct causes beneath DeploymentStackDeploymentFailed. Broad/nested errors remain retryable. Real responses demonstrate that InvalidTemplateDeployment, including HTTP 400, can represent a permission failure without a structured authorization code, so neither that code nor HTTP 400 alone establishes invalid intent.

    Pending work requests fixed 30-second polling. Execution failures use ordinary workqueue errors; other events may reconcile earlier. No manual Retry-After parsing or additional retry gate is imposed.

    Operational Notes

    Existing eligible clusters migrate automatically. Historical assignments never adopted by a stack are intentionally left alone. Existing-cluster adoption, production FPA permissions, and SMI execution still require rollout validation. No shared role-definition, CI/CD, or image-configuration changes are included. Personal-environment documentation changes remain outside this PR.

    Two commits separate the generic machinery from the role-assignment migration.

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: stevekuznetsov Review duration: 419m
    All Vouch review confidence checks passed
    Residual risk 0.30 = Change Risk (0.75) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.75 · 650 lines diff across 8 files
    0.75
    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
    Sensitive Paths sensitive_paths
    0.075
    Real PR Conversation Timeline
    1 comments
    "Review active on #7536"
    general weight: 0.35
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed sensitive_module
    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: 75.2% (HIGH) · Higher = larger blast radius
    75.2%
    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: 29.7% · Safe to merge
    29.7%
    Repository