Repository navigation
Instrument ate-apiserver so that it can shutdown gracefully. - #523
Benjamin Elder (BenTheElder) merged 1 commit into
Conversation
|
Thanks, this is what I am defining for the upgrade model - the old instances need to be gracefully drained before shutdown. |
| if err := mux.Serve(lis); err != nil { | ||
| serverboot.Fatal(ctx, "Failed to serve", err) | ||
| } | ||
| slog.InfoContext(ctx, "Shutdown complete") |
There was a problem hiding this comment.
Nothing waits on this to complete right? Should the main function wait for the drainOnShutdown to complete?
e.g
drainFinished := drainOnShutdown(shutdownCtx, mux, readiness)
if err := mux.Serve(lis); err != nil {
serverboot.Fatal(ctx, "Failed to serve", err)
}
<-drainFinished
There was a problem hiding this comment.
Added. FWIW, I don't think this is a correctness thing as .Serve will only unblock once we are done with the shutdown, but there is one subtlety, the last log line in drainOnShutdown.
Not sure if it's worth the complexity tbh, but I added it as I like the log line discriminating a interrupted drain from a drain that completed gracefully.
| @@ -141,6 +146,15 @@ spec: | |||
| port: 9090 | |||
| initialDelaySeconds: 5 | |||
| periodSeconds: 2 | |||
There was a problem hiding this comment.
Won't this run 3 times before the pod is marked unhealthy in the apiserver? That means that it would take ~6s to mark the pod unhealthy. Won't we start rejecting traffic at 5s in the ate-apiserver? That would mean we still aren't graceful unless we tweak some limits. I'd just test this in a kind cluster and make sure that the graceful shutdown timeouts are enough.
There was a problem hiding this comment.
hah, your comment hadn't loaded yet, AI review suggests ~ the same #523 (comment)
There was a problem hiding this comment.
From manual follow-up this is what jumps out the most.
There was a problem hiding this comment.
Adjusted. It was off by a few seconds.
| - --session-id-ca-pool=/run/session-id-ca-pool/pool.json | ||
| - --workerpool-ca-certs=/run/workerpool-ca-certs/trust-bundle.pem | ||
| # Graceful shutdown knobs. The sum must fit within terminationGracePeriodSeconds. | ||
| - --drain-delay=5s |
There was a problem hiding this comment.
🤖 should-fix 🟡 – The readiness signal can't land within this 5s window. The readinessProbe above sets periodSeconds: 2 and leaves failureThreshold at its default of 3, so kubelet needs ~6s of consecutive 503s before it marks the pod NotReady — after the drain has already closed the listener. As configured, MarkNotReady contributes nothing and removal from Endpoints rests entirely on the deletionTimestamp path.
Setting failureThreshold: 1 on the readinessProbe makes the probe react in ~2s, inside the drain delay.
There was a problem hiding this comment.
Adjusted.
| slog.InfoContext(ctx, "Shutdown complete") | ||
| } | ||
|
|
||
| func drainOnShutdown(ctx context.Context, srv *grpc.Server, readiness *serverboot.Readiness) { |
There was a problem hiding this comment.
🤖 nit 🟢 – drainOnShutdown reads the flag globals directly, so the sequence it orchestrates (mark unready → delay → graceful stop → force stop on timeout) can't be unit tested. Passing the two durations as parameters would make it testable, like metricsMux was split out for the same reason.
0627fc5 to
a64eb56
Compare
Make the server trap SIGTERM and initiate a graceful shutdown process. This involves reporting the Pod as not ready, and draining all in-flight gRPC requests so they can complete.
a64eb56 to
3d243db
Compare
04aee6c
into
agent-substrate:main
Make the server trap SIGTERM and initiate a graceful shutdown process. This involves reporting the Pod as not ready, and draining all in-flight gRPC requests so they can complete.
Part of #181