Repository navigation
Conversation
Add `python3 -m taskbroker_client.drain <seconds>`, which creates the worker drain file and then sleeps. Pods currently do this with `/bin/sh -c "touch /tmp/taskworker-draining && sleep N"`, which does not work on distroless images that have no shell, touch or sleep. The client owns the drain file path, so the hook no longer has to duplicate it. The module imports only the constants, so the hook starts in milliseconds instead of loading the worker. Co-Authored-By: Claude <noreply@anthropic.com>
Replace the module docstring with a short one on drain(), since no other client module has one. Drop the test for touching an existing file, which the worker never relies on, and the import-weight test, which guarded about 0.5 s inside a 15 s hook. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
evanh
reviewed
Oct 8, 2026
| which must finish before Kubernetes sends SIGTERM. | ||
| """ | ||
| Path(path).touch() | ||
| time.sleep(seconds) |
Member
There was a problem hiding this comment.
Why does this need to sleep? Can't it just exit immediately after writing the file?
Member
Author
There was a problem hiding this comment.
This is an equivalent of the old touch /tmp/taskworker-draining && sleep 15. There is no sleep (because of no shell) outside of the subcommand, so we have to sleep here.
Initially that 15 sec sleep was added in https://github.com/getsentry/ops/pull/23208
evanh
approved these changes
Oct 8, 2026
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.
Add
python3 -m taskbroker_client.drain <seconds>. It creates the worker drain file (/tmp/taskworker-draining), which stops the worker from publishing occupancy, then waits forseconds.getsentry is moving to a distroless image, and the taskworker preStop hook (
/bin/sh -c "touch /tmp/taskworker-draining && sleep 15") needs a shell. The drain file has to stay: it is how brokers stop routing to the pod before SIGTERM. That's why Kubernetes' nativepreStop: sleepisn't enough on its own. The client already owns both sides of this contract: the worker reads the file and clears a stale one at startup. The command keeps the writer next to them, so ops no longer copies the path.Running a command shipped with the application is the usual way to drain without a shell:
vroom drain 25s, the same change for vroomenvoy-gateway envoy shutdown/bin/contour envoy shutdownpilot-agent request POST drainpreStop: sleepso hooks work "without needing a sleep binary in my image" (KEP-3960)secondsis a plain number, likesleepand Kubernetes'preStop.sleep.seconds, so the existingworker_prestop_sleepvalue passes through unchanged.Merge order: a getsentry image with this release must be live in a region before its hook switches to
["python3", "-m", "taskbroker_client.drain", "15"]. On an older image the hook fails and the pod gets SIGTERM without draining.Refs SEC-1112