Replace K8s Lease leader election with OpenRaft consensus#84
Merged
Conversation
Replace the Kubernetes-specific leader election (K8s Lease API) with OpenRaft-based consensus that works identically on bare-metal and Kubernetes. Closes #82. The existing WAL operations map directly to Raft log entries, making the integration natural. When `controller.peers` is configured, spurctld forms a Raft cluster for automatic leader election and state replication. Without peers, single-node mode works exactly as before. Changes: - New `raft.rs` module implementing OpenRaft storage, state machine, and network traits using the existing WalOperation type - Config: added `peers` and `node_id` to ControllerConfig - Removed `leader_election.rs` (K8s Lease-based, 172 lines) - Removed `kube` and `k8s-openapi` dependencies from spurctld - Removed `--enable-leader-election` and `--election-namespace` flags - Network transport returns Unreachable for now (gRPC transport implementation is the next step for multi-node testing) Configuration: [controller] peers = ["node1:6817", "node2:6817", "node3:6817"] node_id = 1 # optional, auto-assigned from peers list Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Replace Test 7 (K8s Lease leader election) with a single-node mode verification, since leader election now uses Raft consensus instead of K8s Leases. Remove Lease RBAC rule from operator role. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The spurctld container doesn't have curl installed. Check pod Running status instead. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The openraft dependency adds enough crates that unrestricted parallel compilation hits the file descriptor limit in CI Docker builders. Cap CARGO_BUILD_JOBS=4 to prevent "too many open files" errors. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.
Summary
peersconfigured) behaves exactly as beforeChanges
raft.rs: OpenRaft type config, in-memory log/state stores, network stubs. UsesWalOperationas the Raft log entry type (same as existing WAL)leader_election.rs: K8s Lease-based election (172 lines removed)kubeandk8s-openapidependencies from spurctld--enable-leader-electionand--election-namespaceCLI flagspeers(list of peer addresses) andnode_idto[controller]Configuration
Architecture
WalOperation→ Raft log entries (natural mapping)apply()→ calls samereplay_entry()as WAL recoveryTest plan
🤖 Generated with Claude Code