Repository navigation
Merged
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
This was referenced Oct 15, 2026
Merged
Make the stranded Spot replacement alarm actionable; record why the reaper cannot end it (#984)
#996
Merged
…terminate (#922) A --spot launch always made a one-time Spot request (interruption behaviour terminate), and EC2 refuses to stop an instance from one. So the idle timeout's default stop, --on-idle, --on-complete stop|hibernate, spawn stop and spawn hibernate could never work on Spot, while spawn status promised "stops the instance when idle". - A Spot launch whose lifecycle stops or hibernates (idle timeout, --on-complete stop|hibernate, --hibernate) now makes a persistent request with InstanceInterruptionBehavior=stop (hibernate when configured). The request is tagged like the instance; the instance carries spawn:spot-request-type. Terminate-only --spot launches stay one-time. - Every terminate path cancels the Spot request before terminating, so a persistent request cannot launch a replacement: pkg/aws Client.Terminate (all CLI paths; refuses if a persistent request cannot be cancelled), spored's self-terminate and the TTL reaper (best-effort, logged), and the dashboard. Shared in pkg/spotrequest. - ec2:CancelSpotInstanceRequests on the spawn:managed rail for the spored role baseline, the DCV spored role, the portal onboarding role, and the reaper's scan-self and cross-account roles. - spawn stop / hibernate on a one-time Spot instance refuse up front with an explanation instead of "Saving remaining TTL" then UnsupportedOperation. - spawn status describes the real idle action for one-time Spot. Fixes #922 (#922)
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.
Fixes #922
Problem
Every
--spotlaunch made a one-time Spot request, whose interruption behaviour isterminate. EC2 refuses to stop an instance from a one-time request. So none of these could work on Spot:--on-idle stop|hibernate--on-complete stop|hibernatespawn stopandspawn hibernateMeanwhile
spawn statussaid "stops the instance when idle".Fix (issue option 1, plus options 3 and the status line)
Launch (
pkg/aws/spot_lifecycle.go)SpotInstanceType=persistentwithInstanceInterruptionBehavior=stop(hibernatewhen--hibernateconfigures it). "Stops or hibernates" means any of: an idle timeout greater than 0,--on-complete stop|hibernate, or--hibernate. The rule ispkg/spotrequest.NeedsStoppable.spawn:managed=trueincluded, so it can be found and the tag-conditioned cancel grants match it.spawn:spot-request-type=persistent|one-time.--spotlaunch is unchanged: one-time, no interruption behaviour, no request tags.Cancelling the persistent request on every terminate path. It is cancelled before the terminate; terminating first reopens the request. The shared code is in
pkg/spotrequest.terminate,cleanup, cohorts/taskpool/mpicohort, launch rollback,service, arraygroup, job arrayspkg/awsClient.Terminateaws ec2 cancel-spot-instance-requestscommand. A one-time request only warns, since it closes with its instance.pkg/providerEC2Provider.Terminatelambda/ttl-reaperterminate(); the request id comes from the scan, with no extra DescribeSPOT_CANCEL_FAILEDwith the request id (hard-deadline guarantee, #72).lambda/dashboard-apiSweep and pipeline orchestrator instances are launched one-time by the Lambdas themselves and are out of scope.
IAM.
ec2:CancelSpotInstanceRequestsis added, conditioned onec2:ResourceTag/spawn:managed=true, to:CreateOrGetInstanceProfilere-applies it on every launch, which heals existing roles;scripts/setup-spawnd-iam-role.sh;cmd/onboard.go);pkg/reaperiam,lambda/ttl-reaper/template.yaml) and the cross-account role (deployment/cloudformation/ttl-reaper-cross-account-role.yaml).The reaper drift gates (
TestPolicyCoversEveryReaperAPICall,TestCrossAccountRoleCoversEveryReaperAPICall) failed until those grants were added.The reaper role doesn't allow the cancel yet. The live
spawn-ttl-reaper-ec2roles in onboarded accounts don't have the new grant until their stacks are redeployed. Until then the reaper still reaps; it logsSPOT_CANCEL_FAILEDand the request stays open. Every request spawn creates persistent is tagged, so the condition will match once the roles are updated. #950 tracks a sweep for orphaned requests.spawn stop/spawn hibernateon a one-time Spot instance now refuse before printing or calling anything. The message explains why, and suggestsspawn terminateor a stop-based lifecycle at launch. The job-array path skips such instances with a message.spawn statusgives the real idle action: "cannot act: a one-time Spot instance can't be stopped …" for one-time Spot, and "hibernates" for--on-idle hibernate. Only the idle line changed, which keeps clear of #916's edits to the same function.Tests
Each test was watched failing against a revert that compiles (16 reverts; all ran and failed):
pkg/aws,TestLaunch_SpotRequestShapeForEachLifecycle: runs the realClient.Launchagainst a fake EC2/STS endpoint and asserts theRunInstanceswire parameters for 10 lifecycle combinations: SpotInstanceType, InstanceInterruptionBehavior, the request tag spec, and the type tag. AlsoTestLaunch_SpotMaxPriceKept.pkg/aws,TestTerminate_*: describe, cancel, terminate in that order; refusal on a persistent request that can't be cancelled; one-time and untagged still terminate; on-demand makes no cancel call.pkg/provider,TestEC2Provider_Terminate_*: spored cancels its own request first, and terminates even when the cancel is refused.lambda/ttl-reaper,TestReap_*: driven throughrun(); cancel happens before terminate, a refused cancel still reaps and logs, on-demand makes no call.lambda/dashboard-api,TestTerminateCancellingSpot_*.cmd,TestStop_OneTimeSpotExplainsUpFront: no "Saving remaining TTL", zero AWS calls, and the message content.TestStop_PersistentSpotIsStopped,TestIdleActionDescription.pkg/aws,TestSporedPoliciesGrantSpotCancelOnManagedRail;pkg/spotrequestunit tests.make check: all green except the known Docker-onlyTestGenerateWrapper_ChownFixesCrossUIDStickyUnlink_Docker.make check-nested: all 9 nested modules clean. No AWS resources were touched.Deploy needs
ttl-reaperLambda (code), and thespawn-ttl-reaper-ec2cross-account role stack in each onboarded account. Re-apply the scan-self policy wherever scan-self is used.Notes
pkg/aws's exported surface is unchanged, so no snapshot update was needed. Downstream callers ofClient.Terminate(lagotto, calque, spore-host-mcp) get the cancel, and the strict refusal, when they bump.CHANGELOG.md(both add an[Unreleased] ### Fixedgroup).cmd/status.go,pkg/aws/client.goandpkg/provider/ec2.goauto-merge.--on-idle/--on-complete hibernatenever configure hibernation), Nothing reclaims an orphaned persistent Spot request (instance terminated outside spawn); consider a reaper sweep #950 (orphaned persistent requests; possibleValidUntilbound).