Repository navigation
fix(kubernetes): compare-and-swap lifecycle writes on the bootstrap claim - #6109
Open
matthewgrossman wants to merge 5 commits into
Conversation
github-actions
Bot
requested review from
FrostGod,
TaylorMutch,
drew,
elezar,
krishicks,
mrunalp,
pimlock,
purp and
russellb
December 1, 2026 00:25
6 tasks
…laim Create and restart patches to the Sandbox CR reread it on a conflict and reapplied the patch whatever its state, so a restart on one replica could overwrite a suspension the lease holder started. - The patch builder now receives the current Sandbox and may refuse. - A restart claims the Sandbox only if it is stopped and no other transition is in progress. - The Running, fence-binding and Released writes of create and restart require their claim (operation, generation, Preparing) to still hold; otherwise the request fails and rolls back. - Type bootstrap operations with an enum. - Return an error instead of using an empty name when a Pod or Sandbox has no name. Signed-off-by: Matthew Grossman <mgrossman@nvidia.com>
A restart whose claimed write failed rolled back with a full stop, which deleted the supervisor Pod by name and wrote the suspension blindly. If another replica's restart had taken over the claim, the rollback tore that restart down. The rollback now writes the suspension as a claimed write. If the claim no longer holds, it leaves the Sandbox to the transition that replaced it and deletes only the supervisor Pod this request created, by UID. A claim in the Released phase still counts as held, so a rollback after a Released write that timed out but landed still stops the sandbox. Signed-off-by: Matthew Grossman <mgrossman@nvidia.com>
Signed-off-by: Matthew Grossman <mgrossman@nvidia.com>
Signed-off-by: Matthew Grossman <mgrossman@nvidia.com>
The claim types, annotation accessors, compare-and-swap patch, and by-UID supervisor deletion move from driver.rs to bootstrap_claim.rs. The claim is now the only write path for create and restart: begin, patch, and release. Writes without a claim call compare_and_patch_dynamic_object directly, so the resourceVersion retry wrapper and patch_claimed_sandbox are gone. A missing resourceVersion is now an error instead of an unconditional write. A failed restart now returns the supervisor Pod it created with its error instead of setting a captured variable, and the rollback is split into suspend_if_claimed and delete_created_supervisor_pod. Create builds its claim from the generation it already has. The README states the remaining concurrent-stop window. Signed-off-by: Matthew Grossman <mgrossman@nvidia.com>
matthewgrossman
force-pushed
the
fix/ha-lifecycle-claim-cas/matthewgrossman
branch
from
December 1, 2026 01:34
a493aae to
dd4adce
Compare
5 of 6 tasks
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Create and restart writes to the Sandbox CR now compare against the request's bootstrap claim instead of retrying blindly on resourceVersion conflicts. A create or restart whose claim was superseded mid-flight, for example by a suspension the lease holder started or another replica's restart, now fails instead of overwriting the other transition. A superseded restart's rollback leaves the Sandbox to that transition and deletes only the supervisor Pod it created.
Stacked on #6103 and should merge after it. GitHub retargets this PR to
mainwhen #6103 merges.Related Issue
Closes #6108
Changes
src/bootstrap_claim.rsholds the claim and the writes that respect it: the phase and operation enums, the bootstrap annotation accessors,compare_and_patch_dynamic_object, anddelete_supervisor_pod_and_wait(by UID).driver.rsshrinks by about 300 lines.compare_and_patch_dynamic_objectis the single retry loop. It passes the current Sandbox to the patch builder, which may refuse the write. Writes without a claim (stop, suspension, suspension completion) call it directly. A Sandbox without a resourceVersion is now an error instead of an unconditional write.SandboxRuntimeBootstrapClaim(Sandbox UID, operation, generation) is the only write path for create and restart:begin: a restart claims the Sandbox only if it is stopped and no other transition is in progress.patchandrelease: the Running, fence-binding, andReleasedwrites require the claim to still be held (phasePreparingorReleased, perSandboxRuntimeBootstrapPhase::held_by_claimant) with the same UID, operation, and generation. Otherwise they returnPrecondition, and the request takes its rollback path.roll_back_restart): the restart returns the supervisor Pod it created along with its error (RestartFailure). The rollback runssuspend_if_claimed, a claimed suspension write, thendelete_created_supervisor_pod.Released, so aReleasedwrite that timed out but landed still counts): suspend, delete this request's supervisor Pod by UID, then stop as before.stop_sandbox_inner, which deletes the supervisor Pod by name and writes the suspension unconditionally. That tore down another replica's restart that had taken over the claim.roll_back_restartdoc comment and the README: once the rollback has suspended the Sandbox, the stop that follows is not claim-aware. If another start finishes the same stop and claims the Sandbox before this stop's final poll, this stop can still remove that start's supervisor Pod. Any two concurrent stops have the same window. This is the remaining known gap; feat: fence sandbox lifecycle actions with a gateway-issued epoch #6110 proposes fencingStopSandbox/SuspendSandboxby runtime generation to close it.SandboxRuntimeBootstrapOperationenum replaces the bare"create"/"restart"/"stop"strings.delete_supervisor_pod_and_waitreturns an error for a nameless Pod instead of using an empty name.crates/openshell-driver-kubernetes/README.md: the HA paragraph states the rule (create/restart CR writes compare-and-swap against the claim, and supervisor Pods are deleted by UID), describes how each request type rolls back, links feat: fence sandbox lifecycle actions with a gateway-issued epoch #6110 for stop and suspend along with the concurrent-stop window that remains, and no longer lists the overwrite as a limitation.Across replicas, the gateway already serializes
StartSandbox: every start, including a retry of a sandbox alreadyStarting(crates/openshell-server/src/compute/mod.rs:2960-2975), goes throughclaim_provisioning_operation(provisioning_operation.rs:194-251), which refuses while a driver operation is pending. Only pre-upgrade rows without a provisioning attempt ID skip that claim (provisioning_operation.rs:195-198), because every gatewayStartingwrite mints one (apply_lifecycle_phase→new_preparation_record). Stop and suspend have no such claim. Concurrent stops can reach the driver through stop/suspend retries (QuiesceAdmission::RetryforStopping/Suspending,mod.rs:524-532), through startup recovery on every replica (recover_persisted_lifecycle_transitions,mod.rs:5010, which re-sends the stop without the lease), and through the provisioning-timeout reclaim (provisioning_deadline.rs:692), which sends STOP while a START may still be pending, by design.Open questions from #6108
Stale claims. A retried start is not refused. In
start_sandbox_runtime_generation, a Sandbox with a bootstrap in progress whose operation isrestart(or whose phase isSuspending) goes through the in-progress branch, which callsstop_sandbox_innerbefore claiming. That stop writes without a claim, suspends the Sandbox, waits for the stop to complete, and appliessandbox_runtime_suspension_completion_patch, which clears the bootstrap annotations. The refreshed Sandbox is then stopped and unclaimed, soclaim.beginsucceeds. A request may therefore already take over an abandoned restart claim without waiting for the 300 s grace period; no change was needed. If the abandoned claim was still live on another replica, that replica's next claimed write fails and rolls back. An abandoned create claim is still refused with "initial sandbox bootstrap has not completed" until reconciliation reaps it, which is the existing behavior and unchanged here.Helper shape. Collapsed after code review: claimed writes go through
claim.patch, which always checks the claim, and unclaimed writes callcompare_and_patch_dynamic_objectdirectly. The resourceVersion-only wrapper andpatch_claimed_sandboxare gone.Testing
cargo fmt --checkcleancargo test -p openshell-driver-kubernetes --lib: 348 passedcargo clippy -p openshell-driver-kubernetes --all-targets: no warningsclaimed_writes_do_not_overwrite_another_transition: a claimed write conflicts, rereads a suspension, and fails without writing again; a held claim retries the conflict and succeeds.restart_claims_only_an_unclaimed_stopped_sandbox: the claim is refused on another restart, our own claim, a stop, and a running Sandbox, and succeeds on a stopped one.superseded_restart_rollback_spares_the_other_restart: a restart whose claim another replica's restart took over rolls back without writing to the Sandbox and without deleting the other restart's supervisor Pod. It fails against the oldstop_sandbox_innerrollback.reconciliation_preserves_a_supervisor_another_replica_is_restartingnow asserts at least two Sandbox reads instead of exactly two, so it checks the reread without pinning the read count.Checklist