Repository navigation
fix(cli): follow the quorum leader through the kates ports forward - #703
Merged
Merged
Conversation
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 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 |
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.
Why
kubectl port-forward service/katesresolves 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:The only way out was to run
kates portsagain by hand.What
client: when a member refuses a request with a 503 that names another member as the leader, the client calls the newOnNotLeaderhook once, drops pooled connections, and sends the request again with its body.QuorumGaterefuses 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:followLeaderPortForwardis that hook. It acts only in theportscontext on a loopback URL (the same guards as the dead-forward repair, now shared aslocalAPIPort). It stops the kubectl forwards of this cluster that listen on the API's local port, and only those, then starts a new one toservice/kates, which reaches the leader.Deliberately not done
localhost:9090) and the SSE disruption stream are not followed.kates ports, is left alone.Tests
TestNotLeaderFollowsAndResendsOnce: leader named, no leader known, failed follow, second refusal, drain refusal; checks hook calls, requests sent and the resent body.TestStopPortForwardsOnPortStopsOnlyThatPort,TestFollowLeaderPortForwardOnlyForThePortsContext.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).kates test create --type LOAD --records 100000printed "The Kates leader moved: forwarded port 8080 to it again", created one run, and the forward process was replaced.