Repository navigation
Wait out the server's drain when quiescing for an upgrade - #2171
Merged
Merged
Conversation
Before the backup of a database-changing upgrade, the promotion scales the server to zero and waits for its pods to be deleted. That wait used the promotion timeout (900 s on the management agent). A stopping server keeps serving, then drains its in-flight runs for up to its termination grace period, and an install may set that far above 900 s. A server still draining a run then timed out the wait: the promotion was undone and retried 30 minutes later, after serving nothing for 15 minutes. The wait now covers the server Deployment's own terminationGracePeriodSeconds, read when quiescing (Kubernetes' 30 s default when unset), plus a minute, and never less than the promotion timeout. The drain is never shortened.
davidmckayv
requested review from
MikeRyanDev,
dustywusty,
guidovizoso,
mxmzb,
samjulien and
tylerslaton
as code owners
November 25, 2026 01:45
This was referenced Nov 25, 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.
What this changes
Before the backup of an upgrade that changes the database, the promotion (run by the management agent, and by
bun scripts/update.ts kubernetes) scales the server to zero and waits for its pods to be deleted. That wait was bounded by the promotion timeout: 900 s on the management agent.A stopping server keeps serving, then drains its in-flight Bot runs for up to its termination grace period, and an install may set that grace period far above 900 s (30 s of serving on, a 30-minute drain and a margin comes to 1845 s). With a run still draining, the wait timed out while the pods were still stopping as they should: the promotion was marked failed, the quiescing was undone, and the agent tried again 30 minutes later. The server had served nothing for those 15 minutes, for no gain.
The wait now lasts the server Deployment's own
terminationGracePeriodSeconds, read from its pod template when quiescing (Kubernetes' 30 s default when it sets none), plus 60 s for the kubelet to stop the pod and the deletion to reach the API, and never less than the promotion timeout. The drain itself is not shortened.Other places checked: this is the only wait on the server pods going away. The recovery path (
converge) and rollback run withmaintenance: false, so they never quiesce; the failure paths scale to zero without waiting;rollout statuswaits do not wait for terminating pods. The maintenance window does not use this bound. Neither runner kills thekubectl waitbefore its own--timeout(notimeoutMsis passed for it).Where it runs
kubectl get deploymentduring quiescing.Boundary and audit
API and database
api/, no app's requests, no database change and norelease-policy.json.Changelog
CHANGELOG.mdunderUnreleased, Kubernetes.Proof
Regression test in
shared/tests/kubernetes-promotion.test.tsdrivesrunPromotionwith maintenance on and a 900 s timeout, as the management agent runs it, against a simulated namespace: scaled to zero, each server pod stops when its drain ends or its grace period runs out, andkubectl wait --for=delete --timeout=<n>sfails as kubectl does ("timed out waiting for the condition") when n seconds pass first.failedwitherror: timed out waiting for the condition on pods/.... After it the promotion isaccepted, the backup runs only at 1830 s once the pods are gone, and the wait's--timeoutis at least 1845 s.Locally:
bun testofshared/tests/kubernetes-promotion.test.ts,tests/promote-kubernetes.test.ts,tests/promote-kubernetes-gitops.test.tsandmanagement-agent/tests/agent-only.test.tspass;biome format,biome lint --error-on-warningsandbun run typecheckare clean. The kind suites run in CI.