Skip to content

fix(cli): follow the quorum leader through the kates ports forward - #703

Merged
bmscomp merged 1 commit into
mainfrom
fix/cli-follow-quorum-leader
Nov 19, 2026
Merged

bmscomp merged 1 commit into
mainfrom
fix/cli-follow-quorum-leader

Conversation

@bmscomp

@bmscomp bmscomp commented Nov 19, 2026

Copy link
Copy Markdown
Owner

Why

kubectl port-forward service/kates resolves the Service to one pod when it starts. The Service selects the quorum leader (kates.io/quorum-role=leader), but once leadership moves, the forward keeps reaching the former leader, and every write is refused:

✖ Failed to create test: [503] Service Unavailable: This Kates member does not lead its quorum: kates-0 does, so send it the request

The only way out was to run kates ports again by hand.

What

  • client: when a member refuses a request with a 503 that names another member as the leader, the client calls the new OnNotLeader hook once, drops pooled connections, and sends the request again with its body. QuorumGate refuses before doing any work, so the resend cannot run a write twice. No resend when no leader is known yet, on a drain refusal, or when the resend is refused too.
  • cmd: followLeaderPortForward is that hook. It acts only in the ports context on a loopback URL (the same guards as the dead-forward repair, now shared as localAPIPort). It stops the kubectl forwards of this cluster that listen on the API's local port, and only those, then starts a new one to service/kates, which reaches the leader.

Deliberately not done

  • gRPC (localhost:9090) and the SSE disruption stream are not followed.
  • A forward started by hand, outside kates ports, is left alone.
  • Reads still go to whichever member the forward reaches; followers answer them.

Tests

  • TestNotLeaderFollowsAndResendsOnce: leader named, no leader known, failed follow, second refusal, drain refusal; checks hook calls, requests sent and the resent body.
  • TestStopPortForwardsOnPortStopsOnlyThatPort, TestFollowLeaderPortForwardOnlyForThePortsContext.
  • Locally: go vet ./..., go test ./..., golangci-lint run --new-from-rev=origin/main ./... (0 issues), govulncheck ./..., scripts/check-cli-style.sh, scripts/check-cli-compat.sh, backend ./mvnw test -Dquarkus.grpc.codegen.skip=true -Dquarkus.http.test-port=0 (1,945 tests, 0 failures).
  • Live on a three-member operator-mode kind cluster with a forward pinned to a follower: kates test create --type LOAD --records 100000 printed "The Kates leader moved: forwarded port 8080 to it again", created one run, and the forward process was replaced.

kubectl port-forward resolves service/kates to one pod when it starts. The
Service selects the leader, but once leadership moves the forward keeps
reaching the former leader, and every write comes back 503: "This Kates
member does not lead its quorum: kates-0 does, so send it the request".

When a member refuses a request that way and names a leader, the client now
calls OnNotLeader once and sends the request again. In the ports context the
hook stops the kubectl forwards of this cluster on the API's local port and
starts a new one to service/kates, which reaches the leader. QuorumGate
refuses before any work, so the resend cannot run a write twice. No resend
when no leader is known, on a drain refusal, or when the resend is refused
too.
@graphify-labs

graphify-labs Bot commented Nov 19, 2026

Copy link
Copy Markdown

Graphify reviews are paused for this workspace because nobody has used it in 7 days. A workspace owner can resume reviews from the Repositories page: https://app.graphify.com/said-s-workspace-a98683/repositories

@bmscomp
bmscomp merged commit 8bb301c into main Nov 19, 2026
65 checks passed
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