Repository navigation
Let a Spot replacement terminate itself instead of being left stopped (#1080) - #1081
Merged
Merged
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Merged
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.
Closes #1080
Problem (observed live on v0.131.0). spored on a replacement EC2 launched from a leaked persistent Spot request (#1008) cancelled the request (good), then shut the OS down. spawn never sets
InstanceInitiatedShutdownBehavior, so EC2's defaultstopapplied, and the replacement was left stopped, untagged, its request cancelled:spawn list;Options considered:
InstanceInitiatedShutdownBehavior=terminate: rejected. It applies to the original instance too. A user'ssudo poweroffwould then terminate it with its persistent request still open, and EC2 would launch a replacement. That creates the leak.CreateTagsis scoped tospawn:managed=true, which the replacement lacks.Fix
--iam-policy) gains one statement,TerminateOnlySelf:ec2:TerminateInstances,Resource *,Condition StringEquals aws:ARN = ${ec2:SourceInstanceARN}. The tag-scoped grant is unchanged.spotrequest.RetireReplacement: cancel → terminate self via the API → only if that's refused, the OS shutdown. It returnsRetiredTerminatedorRetiredShutdown; the latter's error says "STOPPED and billing its EBS volume". Cancel-first is preserved: a failed cancel, or an empty instance ID, does nothing at all.aws ec2 terminate-instances --region R --instance-ids I, rather than implying the instance retired. Notification text updated.Proven on real AWS before and after writing it (#1069 is why a simulator pass isn't evidence):
PutRolePolicyaccepted and stored the policy variable. From an untagged instance, dry-runs showed terminating another instance →UnauthorizedOperation, itself →DryRunOperation, itself + another →UnauthorizedOperation. A real self-terminate succeeded and the other instance was untouched. Probe role, instance profile and instances deleted.spored-instance-role/spored-policynow storesTerminateOnlySelfexactly. Then two untagged raw instances withspored-instance-profile(a replacement's exact situation) repeated all four results. Leak check afterwards: 0 instances, volumes, open/active Spot requests, DNS records.Not yet proven end to end: the new spored retiring a real replacement. spored ships only via a release, so that's the post-release check: rerun the orphan test and expect the replacement
terminated, notstopped.Gates. 9 reverts, each kept compiling; every one fails:
CancelSpotInstanceRequests, filed as EC2: CancelSpotInstanceRequests / DescribeSpotInstanceRequests are not implemented (InvalidAction) scttfrdmn/substrate#1436.TestTheSelfTerminateGrantReachesIAMreads back what each writer stored.go vet, staticcheck (GOOS=linux), the hermetic suite, nested modules,pkg/reaperiamand semgrep all pass.pkg/spotrequestisn't public API; the API snapshot is unchanged.