← Back to Pull requests

SPLAT-2703: Add durable VMotion execution and recovery state #231

Open
unknown opened this pull request with 650 lines diff across 8 files
View on GitHub
unknown unknown commented on Oct 29, 2026 22:15 UTC
Author

Dependency and review scope

Depends on #228. Merge the read-only VMotion planning foundation first.

This implements PR 3 — Durable execution and recovery state machine from the UPI cross-vCenter VMotion implementation plan, under SPLAT-2703 / epic SPLAT-2901.

This branch includes PR #228 planning head 4f530a1bbeab0145cf29f77ae8e33baa28134507 through a history-preserving merge. Because #228 is still open and this PR targets upstream main, GitHub includes its prerequisite commits. The initial PR 3 implementation starts with the following two commits; review-fix commits are listed below:

1. 2cb78df53 — durable execution/recovery implementation and regression tests.
2. 208ce0717 — implementation rationale, runtime boundaries, and PR 3 checklist.

Review only the PR 3 changes.

SPLAT-2703 covers both planning and durable execution. SPLAT-2704's title currently mentions durable execution, but its description and acceptance criteria describe the separate PR 4 vSphere adapter; SPLAT-2703 is the confirmed attribution here.

Summary and motivation

Add the bounded controller component that records and observes external VM actions safely across reconciliation, conflicts, pause, restart/leader takeover, late results, recovery requests, and deletion handoff.

Kubernetes status updates and vCenter operations do not share an atomic transaction. Leader election alone cannot fence a previous external submission. Consequently, a claimed action whose submission outcome is unknown must be observed or escalated, never automatically replayed. This PR implements that conservative boundary using the existing migration CR and shared backend contract rather than adding lock resources, an external workflow service, or an unbounded journal.

This does not enable production VMotion submission. The new submission helper has no production workflow caller. The production recovery verifier is also intentionally unconfigured until later orchestration supplies the required live evidence.

Implementation and rationale

1. Single-winner claims and identity-bound writes

internal/controller/vmotion_execution.go reads the authoritative CR through APIReader and applies resourceVersion-protected status updates with bounded conflict retries.

  • Bind updates to CR UID, execution ID, plan fingerprint, frozen source/destination, and frozen per-node identity/placement.

  • Require the canonical namespace/name, expected generation, Running, no deletion, no intervention, and the expected prior action when claiming new work.

  • Recheck those gates after every conflict instead of assuming a conflict is unrelated.

  • Allow only the reconcile that successfully acknowledges a newly persisted claim to reach the mutating backend.

  • Treat a lost claim acknowledgement conservatively even if Kubernetes may have stored the claim. A successor observing that claim cannot submit it again.

  • Carry the claimed operation snapshot into submission, so a later spec edit cannot silently change the submitted inputs.
  • This is a claim-once/observe protocol, not an exactly-once execution guarantee. A crash between acknowledged claim and external request can deliberately require administrator intervention.

    2. Observation is separate from mutation permission

    Handle an existing VMotion action before normal pause/spec-selection and deletion workflow gates. Matching observations can be persisted after pause or generation changes, including removal of the VMotion selector, while the existing general executionContext mutation guard stays strict.

    Results are conditional on the same action/task snapshot. A stale writer cannot replace a newer action, concurrent task binding, or terminal result; unrelated status fields survive conflict retries. This prevents stale observations from becoming replay authority.

    3. Independent outcomes and owning-vCenter task scope

  • Store shutdown, relocation, and power-on results in separate per-node outcome fields.

  • Preserve successful relocation if destination power-on later fails.

  • Require acknowledged task-based submissions to provide a bounded task ID owned by the action's vCenter; reject wrong-owner or missing references.

  • Keep ShutdownGuest taskless and observe the frozen VM's actual power state. A successful request return alone does not establish shutdown completion.

  • Keep missing task evidence, contradictory acknowledgement/error responses, and uncertain submissions explicitly uncertain.

  • Persist controller-owned reason text instead of raw backend errors, task output, credentials, or SDK objects.
  • Task success is not Node completion: destination placement, preserved identity, fresh Node heartbeat, and applicable etcd recovery remain later workflow gates.

    4. Deadlines, bounded reads, and polling

    Start shutdown, relocation, and power-on action deadlines at six hours, with TODO(SPLAT-2703) beside the constant requiring qualification of that initial value.

    Expiry blocks further actions and retains intervention while observation continues. A late successful result updates its independent outcome without automatically clearing intervention or permitting the next action.

    Use separate 30-second read budgets and polling intervals, following the existing long-wait cadence:

  • Bound each observation and recovery-verification call so an unavailable backend can return control to reconciliation and subsequent deletion handoff.

  • Throttle observations using persisted observation time, because the controller's own status writes also generate CR watch events. RequeueAfter alone does not prevent those events from immediately polling again.

  • State the backend/verifier cancellation obligations in the shared contract. A mutation adapter must check cancellation before initiating a request, including after internal waits; cancellation of an already-sent request is not proof of external inactivity.
  • 5. Evidence-gated, action-bound recovery

    internal/controller/vmotion_recovery.go treats a recovery request as an instruction to revalidate, not a force-clear flag.

  • Require matching request/execution/action identity and a matching intervention; reject stale or already-consumed requests for another action.

  • Block recovery of a still-Claimed action until its persisted submission deadline expires. External inactivity alone cannot fence an original claimant suspended before sending its request.

  • Require a read-only verifier to establish claimant quiescence, authoritative outcome/inactivity, unique expected VM identity/location/power, preserved Node identity, applicable health, and unchanged live plan/inventory.

  • Treat missing, unavailable, conflicting, or nonterminal evidence as blocked; deadline expiry alone does not consume a request.

  • Reject verification if resourceVersion changes before acknowledgement consumption, forcing a fresh recheck.

  • Consume a verified request once, preserve committed terminal evidence, and require a new action ID for an explicitly authorized retry through normal admission gates.

  • Preserve pause policy A: acknowledgement never bypasses the Running requirement for a new mutation.
  • The nil production verifier fails closed. Later orchestration must supply and qualify those evidence checks before recovery is enabled.

    6. Deletion retention and explicit handoff

    Continue observing an existing action while deletion retains the execution record. Do not run legacy progression, preparation, new VM actions, cancellation, rollback, or VM deletion from that path.

    Unresolved VMotion actions prevent completion-based finalizer release. Preserve the existing explicit migration.openshift.io/allow-deletion: "true" administrator handoff even when the backend is unavailable; handoff is not proof of success or permission to recover a VM or clean up source references.

    Tests and review fixes

    The implementation and review fixes include 35 focused test functions, including table-driven cases, exercising the real controller status logic against Kubernetes fake-client conflict behavior and fake external backends:

    | Area | Evidence covered |
    | --- | --- |
    | Claims and crash windows | Competing reconciles, resourceVersion conflicts, lost claim acknowledgement, crash after claim/before request, failed task persistence, restart without a task reference, and no blind duplicate submission |
    | Identity and stale writes | Replaced CR/execution/plan/Node identity, newer actions, terminal results, concurrent unrelated status, and wrong-owner task references |
    | Pause and results | Pause before claim and after a winning claim, generation changes, independent relocation/power-on outcomes, and no recovery bypass of pause |
    | Deadlines | Graceful-shutdown timeout and late completion, task success after six hours, and intervention retained after late success |
    | Recovery | Action-bound requests, one-time consumption, stale evidence, unavailable verifier, expired claims, new retry IDs, and a suspended original claimant that must not be outrun |
    | Reconciliation liveness | Bounded observation/verification, deletion handoff after read timeout or without a backend, and self-generated status watch events that must not create an immediate polling loop |

    A fresh review identified three important issues: recovery could race an original claimant, reads were initially unbounded, and status writes could bypass the polling interval. Each was reproduced by a failing regression test, fixed, and followed by passing focused and repository verification. Timeout/polling tests use Go virtual time rather than real six-hour waits.

    Documentation and compatibility

  • Add docs/dev/vmotion-execution.md with the protocol, design rationale, dependency boundaries, and qualification limits.

  • Update the API runtime description and mark the implemented PR 3 checklist items complete.

  • Reuse the existing bounded action status and shared backend contract. The review fixes add optional per-node targetDatacenter status and synchronize the direct-install/bundle CRD schemas. No RBAC, packaging-layout or dependency changes are required.

  • Preserve the legacy mutation guard and existing omitted-selection / Recreate paths.

  • Retain one outcome per operation kind and the bounded consumed-request identity, rather than an attempt-history journal.
  • Validation

    Run successfully on the committed source tree before publication:

  • make test — repository unit, envtest, and simulator suites

  • make lint — repository-pinned golangci-lint, 0 issues

  • make build

  • go test -race ./internal/controller -run TestVMotion -count=1

  • git diff --check
  • The generated direct-install and bundle CRD schemas include the bounded targetDatacenter field for both roles. DeepCopy generation produced no additional changes for this scalar field; RBAC is unchanged.

    Remaining qualification / delivery boundary

    The real vSphere adapter, SDK retry/cancellation/session-cache semantics, fresh workflow admission and recovery evidence, control-plane health integration, availability packaging, and guarded cleanup remain their planned follow-ups. The six-hour deadlines and exact platform combinations still require qualification. No real cross-vCenter lab or cluster E2E qualification was performed; fake-backend, envtest, and simulator success is not release qualification.

    <!-- This is an auto-generated comment: release notes by coderabbit.ai -->
    <!-- coderabbit-ai-generated:v1 -->

    Summary by CodeRabbit

    New Features
    Migration progress can record a destination datacenter for each node; changes to the recorded destination are detected as plan drift.
    Recovery status distinguishes blocked requests from verified recovery. Existing VMotion actions can be observed and recorded across pauses and spec changes, with safeguards against uncertain outcomes.
    Bug Fixes
    Deletion safeguards retain migration resources while VMotion actions remain unresolved, unless the administrator uses the deletion override.
    Documentation
    * Updated VMotion documentation to clarify safeguards and remaining limitations, including that production action submission is not enabled.
    <!-- end of auto-generated comment: release notes by coderabbit.ai -->

    Review follow-up: review 5705746848

    All three findings in the linked review are addressed in focused commits with detailed messages:

  • 43eceb8cb: require successful graceful-shutdown evidence before a Cold relocation claim; absent, failed and unknown evidence cannot create a claim or reach the backend. Hot relocation still requires no shutdown.

  • 303242c78: persist the destination datacenter per node, use only frozen placement for relocation/power-on, protect it in stability checks and reject old records missing the value. Regenerate the direct-install CRD and synchronize the bundle schema; verify real API status round-trip and empty-value validation.

  • fb35e2a5b: report expected recovery refusals through the bounded VMotionRecovery condition while retaining 30-second observation polling. Keep refusal writes/events idempotent and identity-bound, record successful verification atomically with acknowledgement consumption, and continue propagating operational read/write failures.
  • Each finding has a regression reproduced before its fix. After all fixes, make test, make lint (0 issues), make build, the focused VMotion/frozen-node race suite and git diff --check pass. Replies in all three inline review threads describe the changes and evidence. Production submission and the qualified recovery verifier remain disconnected; the six-hour qualification TODO remains in place.

    Planning dependency synchronization

    Merge commit 4bde47205 carries PR #228 planning fixes 5d7e4dd50 and 4f530a1bb into this branch without rewriting published commits. These fix nested-datacenter scope and implement the approved Machine API B/C ownership/provisioning policy: complete parent/remediation evidence, resolved-absent annotations only after all other checks, IP-only/contradictory evidence vetoes, terminating-Node and malformed-reference rejection, and fresh eligibility reads after inventory.

    Engine-switch flaw A remains explicitly deferred, CAPI is outside release scope, and snapshots are not external-operation fencing. The execution submission/recovery boundaries and existing frozen target-datacenter field remain intact. See docs/dev/vmotion-eligibility.md and PR #228 for the detailed policy and regression evidence.

    The combined branch passes make test, make lint (0 issues), make build, focused VMotion/frozen-node/reference-parser controller race tests, inventory simulator race tests, and diff checks. No actual cross-vCenter qualification was performed.

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: jcpowermac Review duration: 45762m
    All Vouch review confidence checks passed
    Residual risk 0.33 = Change Risk (0.59) × (1 − Review Confidence (0.45)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.59 · 650 lines diff across 8 files
    0.59
    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%
    44%
    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 #231"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 44.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: 59% (MEDIUM) · Higher = larger blast radius
    59%
    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: 44.7% · Lower = rushed or shallow review
    44.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: 32.6% · Safe to merge
    32.6%