Cache kubeconfigs on all raft members and fix race condition with re-engagement#1439
Merged
andrewstucki merged 3 commits intomainfrom Apr 14, 2026
Merged
Cache kubeconfigs on all raft members and fix race condition with re-engagement#1439andrewstucki merged 3 commits intomainfrom
andrewstucki merged 3 commits intomainfrom
Conversation
d3b1a73 to
a71835e
Compare
RafalKorepta
approved these changes
Apr 14, 2026
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.
Note: this a stacked PR which will get rebased against main once its base branch is mergedProblem
Kubeconfigs only exist in-memory on the raft leader. When a raft leader is elected it fetches kubeconfigs from all peers via gRPC and holds them in memory. If that leader crashes, the new leader must reach every peer over gRPC before it can manage those clusters. If any peer's operator is also down (common during a rolling incident), the new leader cannot engage that cluster until the downed pod recovers -- a recovery dependency cycle.
Solution
Every raft member now runs a
startupKubeconfigFetcherat startup that unconditionally fetches each peer's kubeconfig via gRPC and stores it as aSecretin its own local cluster (<kubeconfigName>-<peerName>). Failed peers are retried every 5 seconds. When a node becomes raft leader, it reads from the local Secret cache first and only falls back to a live gRPC call if the Secret is absent, writing the result back to the cache on success.Additional fixes
Problem
Concurrent broadcaster notifications could be silently dropped.
wrapStartspawned a goroutine that listened on the broadcaster channel and re-randoEngageon each notification. If twonotify()calls fired in rapid succession (e.g. two clusters added during the same bootstrap sweep), the second notification could be lost: the goroutine woke on the first close, replacedchwith the fresh open channel, randoEngage, then re-read the channel — getting the already-replaced channel from the secondnotify(), which it would wait on indefinitely. One cluster would never be engaged after failover.Solution
Extracted
restartBroadcasterand the notification loop intobroadcaster.go. The drain loop now snapshots the channel reference before callingfn. Afterfnreturns, if the reference changed (anotify()fired duringfn) it callsfnagain, repeating until the reference stabilises. This guarantees no notification is dropped regardless of how many concurrentnotify()calls overlap with an in-flightfn.Tests
broadcaster_test.go— unit tests usingtesting/synctestto step goroutines deterministically through the concurrent-notification race.TestIntegrationKubeconfigCaching— three envtest instances in bootstrap mode. Verifies every node writes a kubeconfig Secret for each peer, then kills the raft leader and verifies the new leader engages the former leader's cluster from the local Secret cache alone, with the former leader's gRPC transport offline.