Skip to content

Wait out the server's drain when quiescing for an upgrade - #2171

Merged
davidmckayv merged 2 commits into
mainfrom
fix/quiesce-wait-covers-grace-period
Nov 25, 2026
Merged

davidmckayv merged 2 commits into
mainfrom
fix/quiesce-wait-covers-grace-period

Conversation

@davidmckayv

Copy link
Copy Markdown
Contributor

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 with maintenance: false, so they never quiesce; the failure paths scale to zero without waiting; rollout status waits do not wait for terminating pods. The maintenance window does not use this bound. Neither runner kills the kubectl wait before its own --timeout (no timeoutMs is passed for it).

Where it runs

  • New state that outlives a request? None. One extra kubectl get deployment during quiescing.
  • What happens on the second replica? Not applicable: the management agent and the operator tool run once per install, outside the server.
  • Anything serialised? No.
  • Anything fanned out to a browser? No.
  • New listener, port, or schedule? No.

Boundary and audit

  • Every acting call still goes through the gateway: not touched.
  • New refusals and new failures each write a row: none added.
  • Nothing new is trusted from the client.

API and database

  • This changes nothing under api/, no app's requests, no database change and no release-policy.json.

Changelog

  • A line in CHANGELOG.md under Unreleased, Kubernetes.

Proof

Regression test in shared/tests/kubernetes-promotion.test.ts drives runPromotion with 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, and kubectl wait --for=delete --timeout=<n>s fails as kubectl does ("timed out waiting for the condition") when n seconds pass first.

  • A server with a 1845 s grace period draining a run for 1830 s. Before the fix the promotion ends failed with error: timed out waiting for the condition on pods/.... After it the promotion is accepted, the backup runs only at 1830 s once the pods are gone, and the wait's --timeout is at least 1845 s.
  • A server with the default grace period still waits 900 s (the floor).

Locally: bun test of shared/tests/kubernetes-promotion.test.ts, tests/promote-kubernetes.test.ts, tests/promote-kubernetes-gitops.test.ts and management-agent/tests/agent-only.test.ts pass; biome format, biome lint --error-on-warnings and bun run typecheck are clean. The kind suites run in CI.

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
davidmckayv merged commit 9e1751e into main Nov 25, 2026
66 of 68 checks passed
@davidmckayv
davidmckayv deleted the fix/quiesce-wait-covers-grace-period branch November 25, 2026 04:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant