Skip to content

fix(agent): an agent restart stops waiting out retry ladders before it serves its node proxy (#1123) - #1135

Merged
bpalermo merged 6 commits into
mainfrom
fix/1123-agent-restart-gap
Oct 2, 2026
Merged

bpalermo merged 6 commits into
mainfrom
fix/1123-agent-restart-gap

Conversation

@bpalermo

@bpalermo bpalermo commented Oct 2, 2026 •

Copy link
Copy Markdown
Owner

Refs #1123

The target is not met yet, so this is Refs, not Closes. Across an agent roll the proxy-side gap is now median 5.5 s / p99 8.8 s on kind; the target is p99 < 5 s. Everything the agent itself waits on after its own SVID now takes about 0.1 s. What is left is pod replacement and SPIRE's first SVID, and neither is the agent's to remove: delete-then-create cannot start a sandbox, an init container and the agent in under a few seconds. Proposal 041 (in this PR) designs the surge roll that removes both. What remains is at the end.

Measured: where the gap goes

talos-main, before (read-only)

Source: VictoriaLogs agent lines and the kubelet log on main-worker-04. 10 restarts across the 2026-10-02 rolls at 03:05Z and 06:53Z. The proxy had no ADS stream for 7.6–15.8 s.

term range what it is
old agent exit 0.02–0.1 s SIGTERM to Wait completed. Shutdown is already prompt; no change needed
old exit → new agent's first log line 5.6–10.6 s DaemonSet replace (~0.8 s), sandbox + volumes (~1–2 s), two Always image checks (1.44 s per the kubelet's own totalImagesPullingTime), cni-install (0.2–0.4 s), container start
own SVID 0.15–2.0 s SPIRE attests the new pod
local listeners from storage 0.25–0.98 s ran after the SVID hold, serially
registrar reconnect after identity ~1.05 s on every node the wake's retry loses the redial race, then the loop sleeps a full 1 s backoff
client certificates 0–1.47 s broker streams retry on their own 1 s+ ladder after identity
proxy reconnect 0.06–0.9 s #1118's 0.1–1 s backoff

kind, before and after (e2e/agent-restart-gap.sh, new)

Setup: control plane + worker, SPIRE, etcd registry backend. A poller on each node reads control_plane.connected_state from the proxy admin every 50 ms. Each roll is rollout restart ds/aether-agent, and every node of every roll is one sample. Both arms ran the branch chart; only the agent and cni-install images differ.

seconds main (n=16) this branch (n=20)
gap: proxy without an ADS stream min 5.5 · median 12.0 · p99 17.9 min 4.1 · median 5.5 · p99 8.8
replace (gap start → agent start) 2.5 · 3.6 · 4.0 2.8 · 3.0 · 3.4
↳ cni-install init container 0.25 · 0.44 · 0.67 0.10 · 0.21 · 0.30
startup (agent start → serving) 2.1 · 8.0 · 13.3 1.1 · 2.2 · 5.3
↳ own SVID wait 1.0 · 4.0 · 7.1 1.0 · 2.1 · 5.2
↳ startup after the SVID ~1–6 ~0.1
reconnect (serving → stream) 0.10 · 0.39 · 0.81 0.04 · 0.30 · 0.70
client-certificate gate hit its 5 s bound 7 of 16 restarts 0 of 20
  • SVID wait on main: exactly 1.01 / 2.02 / 4.04 / 7.05 s. That is go-spiffe's linear Workload API retry ladder, not SPIRE.
  • SVID wait on the branch: 1.0–5.2 s. This is what the SPIRE agent's Kubernetes attestor takes to match the new container, which it can only do once the kubelet reports it.
  • On talos the same term was 0.15–2.0 s.

Changes, each with its number

  1. Registrar reconnect after identity (registry/internal/registrar).
    • deferReconnect now waits for the ClientConn to report READY, bounded by its backoff, instead of a fixed sleep.
    • The ~1.05 s that every talos node showed between identity and watch stream connected drops to the dial time.
    • On kind, registry wait after identity was 1.0 s on main and is 17 ms on the branch.
  2. Pod subscriptions retry when the agent's identity is served (agent/internal/spire).
  3. Workload API retry (common/spire/tls.go, which every binary uses).
    • The retry is now 200 ms, 400 ms, then every 500 ms. go-spiffe's default is 1 s, 2 s, 3 s and so on.
    • The SVID is picked up within 0.5 s of SPIRE issuing it. Before, pickup waited for the next whole-second rung.
  4. PreListen builds local listeners during the identity hold (agent/internal/xds/server).
  5. IfNotPresent for the agent and cni-install images (chart).
    • Both images are digest-pinned, so Always only added registry round trips: 1.44 s on a talos restart.
    • kind runs Never, so this term shows only in the talos number.
  6. cni-install is idempotent.
    • It leaves an identical plugin binary (size, mode, owner and bytes) alone.
    • It leaves an identical conflist and durable entry alone too, so there is no write, fsync or rename for them.
    • It still re-chains a stripped conflist and still replaces any binary that differs.
    • Run time on kind dropped from median 0.44 s to 0.21 s.
  7. Readiness probe (chart).
    • periodSeconds: 2, with no initial delay.
    • failureThreshold: 15 keeps 30 s to NotReady, which proposal 033's guard is tuned against.
    • Pod Ready now comes about 1 s after container start, down from about 10 s on talos (34 s → 44 s).
    • This speeds up the roll as a whole, not the per-node gap.

Not changed:

Surge verdict

Two agents cannot safely overlap on a node in this PR's scope. The concrete blockers:

  • hostNetwork ports. containerPort 8080 and 8082 default to hostPorts, so the scheduler's NodePorts filter keeps a surge pod Pending, and the process could not bind those ports anyway. Probes would have to move to a pod-local socket with an exec probe binary.
  • CNI ADD during the overlap. A surge agent that answers ADDs waits for an ACK from a proxy that is not its client (envoyAckTimeout 2 s), and the pod then starts without a listener. One that doesn't answer them misses what the old agent did, unless it reconciles from storage on takeover. LoadListenersFromStorage never removes anything.
  • Persisted state. Observed upstreams, QUIC pairs and the mesh-DNS snapshot would have two writers.
  • Socket unlink-on-close. Go's UnixListener.Close unlinks its path by name, so the old agent's exit would delete a new socket.

docs/proposals/041_agent-surge-handoff.md designs a standby agent:

  • It builds everything but binds nothing.
  • It reports Ready on a complete snapshot.
  • It takes the node over on the old process's flock release: diff-reconcile, bind, start the writers it held back.
  • Expected gap: the reconnect backoff plus the diff, about 0.1–0.4 s.

The proposal covers every hazard above and the open questions. Not implemented, and no chart value.

Evidence (unit tests, each seen red, then green)

test red (before the fix)
registry/internal/registrar TestWatchLoop_ReconnectWaitEndsWhenTheConnectionIsReady identity → stream 1.05–1.18 s in 5/5 runs
agent/internal/spire TestPodSubscriptionsRetryAsSoonAsTheAgentHasAnIdentity 0.72–0.77 s after a 0.3 s head start, 3/3
common/spire TestNewSourceWithTimeout_FollowsTheFirstSVIDClosely 1.50 s in 3/3 runs (option disabled); plus TestFirstSVIDBackoff
agent/internal/xds/server TestPreListen_LoadsLocalListenersWhileIdentityIsPending Condition never satisfied; also asserts no registry call and no return before identity
agent/internal/xds/cache TestTCPFloorWarningSparesTheStartupIdentityWait WARN emitted inside the grace
cni/internal/install TestCopyBinaries_LeavesAnIdenticalInstallAlone inode replaced
cni/internal/install TestWriteCNIConfigLeavesAnUnchangedChainAlone both files rewritten
cni/internal/install TestCopyBinaries_ReplacesAnyDifference (safety; green on both)
//charts/aether:aether_agent_restart_fast_path_test pins IfNotPresent ×2 and the probe

Checks:

  • bazel test --test_tag_filters=-integration over //agent/... //common/... //registry/... //cni/... //charts/... //registrar/... //controller/... //test/envoy_validate:all: 145/145 pass.
  • --config=race passes on registrar, spire bridge, common/spire, xds/server, xds/cache and install.
  • make gazelle and make format were run.
  • bazel build --config=lint --@aspect_rules_lint//lint:fail_on_violation //... is clean.
  • Chart bumped to 2.2.2 (main is 2.2.1 after fix(proxy): a hot-restart child with fewer workers than its parent no longer crashes on a forwarded UDP datagram (#1126) #1133).
  • Agent WARN/ERROR lines on kind, final arm compared with main: no new kinds. subscribing … failed; retrying went from 127 on main to 110 here, across more restarts.

The harness:

EWQ_IMAGE_TAG=<tag> EWQ_SKIP_BUILD=1 e2e/agent-restart-gap.sh up
ARG_ROLLS=10 ARG_EXPECT=report e2e/agent-restart-gap.sh measure   # green gates every gap at ARG_BOUND (5 s)
e2e/agent-restart-gap.sh swap <tag>; e2e/agent-restart-gap.sh down

What remains on #1123

  1. Pod replacement: 2.8–3.4 s on kind. On talos, about 5.6–10.6 s minus the 1.44 s of image checks removed here.
    • The cni-install init container still costs its own run plus the kubelet noticing its exit: 0.4–1.4 s on kind, the PLEG relist.
    • Folding it into a regular container would buy about 1 s. It would also give up the "conflist chained before the agent starts" ordering, so it is not done here.
  2. The first SVID: 1.0–5.2 s on kind, 0.15–2.0 s on talos. SPIRE's Kubernetes attestor waits for the kubelet to report the new container.
  3. Both are removed only by not stopping the old agent first: proposal 041.

Expected on talos with this PR: roughly 4–9 s, against 7.6–15.8 s before. That is not measured yet. The next soak's agent rolls are the check: agent registry connected … waited, client certificates … waited, and the proxy reconnect.

Risks

  • IfNotPresent: a user who overrides digest: "" with a mutable tag no longer re-pulls. The values comment says to set Always for that case.
  • Faster Workload API retry, in every binary: at most 2 fetches/s against the node-local SPIRE socket, and only while the fetch is failing. go-spiffe resets the backoff after each update.
  • Pod subscriptions now retry in a burst at identity: one subscribe per pod (12 on kind), where before they were staggered by jitter.
  • Readiness every 2 s: one local HTTP GET every 2 s, where before it was every 10 s. Time to NotReady is unchanged at 30 s.
  • Restart soak: the agent-roll path has not been soaked on talos yet.

🤖 Generated with Claude Code

https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr

bpalermo and others added 6 commits October 2, 2026 15:02
…t serves its node proxy (#1123)

The node proxy has no ADS stream from the old agent's exit until the new one
serves xDS. Measured on kind (e2e/agent-restart-gap.sh, proxy-side
control_plane.connected_state, 2 nodes, etcd backend): median 12.0 s / p99
17.9 s on main (n=16), median 5.5 s / p99 8.8 s on this branch (n=20).

Startup, after the agent's own SVID, drops from ~6 s to ~0.1 s:
- The registrar client's post-identity reconnect waits for the ClientConn to
  be READY instead of sleeping a whole 1 s backoff after the wake's first
  retry lost the redial race (the steady ~1.05 s on every talos node).
- The SPIRE bridge's pod subscriptions retry the moment the agent's own SVID
  is served (with the broker connection's backoff reset) instead of on their
  1 s+ doubling ladder; on main the client-certificate first-serve gate of
  #1118 hit its 5 s bound in 7 of 16 kind restarts.
- Every Workload API source retries 200 ms / 400 ms / then every 500 ms
  instead of go-spiffe's linear whole-second ladder.
- PreListen builds the local listeners from storage during the identity hold
  (the socket still opens only after identity, capture projection, registry
  load and client certificates); the #877 TCP-floor WARN gets a 1 min startup
  grace with SPIRE on so this does not log on every restart.

Pod replacement:
- agent and cni-install images default to IfNotPresent (digest-pinned; the
  kubelet counted 1.44 s of image checks on one talos restart).
- cni-install leaves an identical plugin binary, conflist and durable entry
  alone instead of rewriting and fsyncing them on every pod start.
- Readiness probed every 2 s from the start (Ready ~1 s after container
  start instead of ~10 s), failureThreshold 15 keeps 30 s to NotReady.

The remaining terms (pod replacement 2.8-3.4 s on kind, the SPIRE first SVID
1-5 s on kind / 0.15-2 s on talos) are not the agent's to remove; proposal 041
designs the surge roll with a standby agent that removes both.

Chart 2.2.0 -> 2.2.1.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
…go's subchannel map; redial on a 250 ms cap instead (#1123)

grpc-go's ClientConn.ResetConnectBackoff copies the map reference under cc.mu
and iterates it after unlocking, so it races newAddrConnLocked writing the
same map (the race job on #1135: TestBridgeSurvivesSubscribeFailures, 12 of
20 local runs). The broker connection is node-local; it now redials on a
50 ms base / 250 ms cap backoff, which bounds how long WaitReady takes after
the agent's SVID lands without touching the ClientConn's internals.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
@bpalermo
bpalermo merged commit 8f68ea0 into main Oct 2, 2026
24 checks passed
@bpalermo
bpalermo deleted the fix/1123-agent-restart-gap branch October 2, 2026 18:37
bpalermo added a commit that referenced this pull request Oct 2, 2026
…962a5716eee28319cf (#1138)

* chore(proxy): pin aether chart to aether-proxy:05b687b77741b8271a7c35962a5716eee28319cf

Pushed by the proxy-release run for 05b687b. Moves both tag: and digest: (aether.image prefers digest over tag) and bumps the chart patch version.

* chore(chart): bump to 2.2.3 for the proxy image pin (main took 2.2.2 with #1135)

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Claude Fable 5.1 <[email protected]>
bpalermo added a commit that referenced this pull request Oct 3, 2026
…hashResource in xds/cache) (#1162)

- agent/internal/spire.sleepCtx lost its last caller in #1135 (the bridge's
  retry ladder moved to a context-bounded wait).
- agent/internal/xds/cache.hashResource was added in #1114 alongside
  versionMemo.hash and was never called; every caller uses the memo.

Proof: golang.org/x/tools/cmd/deadcode run through rules_go's
gopackagesdriver over every first-party main package reports both as
unreachable, and `grep -rnw` finds no reference outside the definition in
any .go file (production or test), chart, doc, e2e script or workflow.


Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr

Co-authored-by: Claude Fable 5.1 <[email protected]>
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