Repository navigation
feat(ttl-reaper): graceful pre-stop flush via SSM before terminate (#187) - #190
Merged
Merged
Conversation
) The out-of-band reaper called TerminateInstances directly, so whenever it was the one terminating (spored dead/wedged), the instance's --pre-stop hook never ran and the user's data flush was skipped — a data-loss path once the reaper runs in enforce mode. Add an opt-in graceful tier (REAPER_GRACEFUL=true): before the hard kill, if the candidate is running, has a spawn:pre-stop tag, and the account exposes an SSM client, run the hook via SSM AWS-RunShellScript as spawn:local-username (#63), bounded by min(pre-stop-timeout, REAPER_GRACEFUL_MAX_WAIT [default 2m]). Poll to a terminal status, then terminate REGARDLESS of the outcome — strictly best-effort, swallows all errors, never blocks or skips the terminate, so the hard-deadline guarantee (#72) is preserved. - candidate carries running/preStop/preStopTimeout/localUsername from tags. - account gains ssmFor (parallel to ec2For) across all three builders. - reaper.go.mod: add aws-sdk-go-v2/service/ssm. Tests: evaluate populates the graceful fields; stopped instances aren't marked running (graceful skips them); shellQuote escapes the su -c argument. Refs #187
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
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.
Implements #187 (follow-up to #184). The out-of-band ttl-reaper called
TerminateInstancesdirectly — so whenever it was the one terminating (spored dead/wedged), the instance's--pre-stophook never ran and the user's flush was skipped. Harmless today (reaper is dry-run) but a data-loss path once it runs in enforce mode.Change — opt-in graceful tier (
REAPER_GRACEFUL=true)Before the hard terminate, if the candidate is running, has a
spawn:pre-stoptag, and the account exposes an SSM client:AWS-RunShellScript, asspawn:local-username(su - <user> -c, mirroring --pre-stop runs as root, should run as the instance user #63),min(spawn:pre-stop-timeout, REAPER_GRACEFUL_MAX_WAIT)(default cap 2m — it's a backstop, not a babysitter),Strictly best-effort / fail-open: every error (not SSM-managed, command failed, timed out, agent missing) is logged and swallowed; the terminate always runs. The hard-deadline guarantee (#72) is never weakened. Off by default.
Mechanics
candidatecarriesrunning/preStop/preStopTimeout/localUsernamefrom tags (populated inevaluate).accountgainsssmForalongsideec2Foracross all three builders (scan-self, cross-account assume-role, fallback-self).go.modaddsaws-sdk-go-v2/service/ssm.shellQuoteescapes thesu -cargument.Tests
evaluatepopulates the graceful fields; a stopped instance isn't marked running (graceful skips it — SSM RunCommand needs a running target);shellQuoteescaping. Existing reaper tests still green after theevaluaterefactor.go build/vet/gofmtclean.Refs #187, #184, #63.