-
Notifications
You must be signed in to change notification settings - Fork 4
feat: leader election with kube api and send through k8s #271
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR implements leader election for the Mojave sequencer using Kubernetes to enable high availability through automated failover. The solution uses the kube-leader-election library with a 15-second TTL lease that is renewed every 3 seconds by the current leader.
Key changes:
- Added Kubernetes deployment manifests supporting 3-replica sequencer deployment with leader election
- Implemented leader election logic in
k8s_leader.rsthat coordinates task management based on leadership status - Added comprehensive documentation for local Minikube setup and testing
Reviewed Changes
Copilot reviewed 15 out of 16 changed files in this pull request and generated 19 comments.
Show a summary per file
| File | Description |
|---|---|
| k8s/setup.sh | Shell script to deploy sequencer resources to Kubernetes |
| k8s/ovh.setup.sh | OVH-specific deployment script with hardcoded kubeconfig path |
| k8s/service.sequencer.yaml | Service definition exposing HTTP and P2P ports |
| k8s/rbac.sequencer.yaml | RBAC configuration granting lease management permissions |
| k8s/pvc.yaml | Persistent volume configuration using hostPath (Minikube-specific) |
| k8s/ovh.pvc.yaml | OVH-specific PVC using Cinder storage |
| k8s/deploy.sequencer.yaml | Deployment with 3 replicas, environment variables, and volume mounts |
| docs/k8s.md | Comprehensive guide for Kubernetes deployment and failover testing |
| cmd/sequencer/src/main.rs | Refactored to detect K8s environment and delegate to leader election logic |
| cmd/sequencer/src/k8s_leader.rs | New module implementing Kubernetes leader election and task lifecycle management |
| cmd/sequencer/Cargo.toml | Added kube dependencies for K8s API interaction |
| Cargo.toml | Added workspace dependencies for k8s-openapi, kube, and kube-leader-election |
| crates/block-producer/src/block_producer.rs | Added error logging for block production failures |
| crates/batch-producer/Cargo.toml | Added mojave-utils dependency |
| justfile | Removed SKIP_BUILD environment variable check |
| Cargo.lock | Updated dependency versions and added K8s-related dependencies |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
561425b to
941f2cf
Compare
Signed-off-by: Sacha Froment <sfroment42@gmail.com>
Signed-off-by: Sacha Froment <sfroment42@gmail.com>
Signed-off-by: Sacha Froment <sfroment42@gmail.com>
Signed-off-by: Sacha Froment <sfroment42@gmail.com>
Signed-off-by: Sacha Froment <sfroment42@gmail.com>
Signed-off-by: Sacha Froment <sfroment42@gmail.com>
Signed-off-by: Sacha Froment <sfroment42@gmail.com>
a398ffd to
b4c895f
Compare
* chore: add health check Signed-off-by: Sacha Froment <sfroment42@gmail.com> * refactor: change the way the main is started Signed-off-by: Sacha Froment <sfroment42@gmail.com> * chore: nitpick * mod: k8s yaml * chore: remove command in justfile * chore: fix just sequencer & node , fix kill process in start.sh * chore: rm * refactor: coordination k8s (#276) * refactor: coordination k8s Signed-off-by: Sacha Froment <sfroment42@gmail.com> * chore: save Signed-off-by: Sacha Froment <sfroment42@gmail.com> * chore: keep health alive Signed-off-by: Sacha Froment <sfroment42@gmail.com> * fix: start Signed-off-by: Sacha Froment <sfroment42@gmail.com> * Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * chore: remove useless Signed-off-by: Sacha Froment <sfroment42@gmail.com> * chore: review comment Signed-off-by: Sacha Froment <sfroment42@gmail.com> * chore: add back save on shutdown Signed-off-by: Sacha Froment <sfroment42@gmail.com> --------- Signed-off-by: Sacha Froment <sfroment42@gmail.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update justfile Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update cmd/sequencer/src/main.rs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update cmd/sequencer/src/cli.rs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update cmd/node/src/cli.rs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update cmd/sequencer/src/cli.rs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update justfile Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * chore: fix 1st call Signed-off-by: Sacha Froment <sfroment42@gmail.com> * Refactor: Use idiomatic assert! in CLI tests (#277) * Initial plan * Replace if-panic patterns with assert! in CLI tests Co-authored-by: sfroment <7238385+sfroment@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: sfroment <7238385+sfroment@users.noreply.github.com> * Fix missing assert in CLI test for command parsing (#278) * Initial plan * Fix matches! macro usage in sequencer CLI tests Added assert! around matches! calls in parse_stop_and_get_pub_key test to properly verify command types instead of just evaluating the boolean. Co-authored-by: sfroment <7238385+sfroment@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: sfroment <7238385+sfroment@users.noreply.github.com> --------- Signed-off-by: Sacha Froment <sfroment42@gmail.com> Co-authored-by: Giwook-Han <hkw00011@gmail.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com> Co-authored-by: sfroment <7238385+sfroment@users.noreply.github.com>
Signed-off-by: Sacha Froment <sfroment42@gmail.com>
Signed-off-by: Sacha Froment <sfroment42@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 32 out of 33 changed files in this pull request and generated 14 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Signed-off-by: Sacha Froment <sfroment42@gmail.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* Initial plan * Fix StatefulSet name references in k8s documentation Co-authored-by: sfroment <7238385+sfroment@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: sfroment <7238385+sfroment@users.noreply.github.com>
…name (#282) * Initial plan * Fix documentation: update references from deploy.sequencer.yaml to stateful.sequencer.yaml Co-authored-by: sfroment <7238385+sfroment@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: sfroment <7238385+sfroment@users.noreply.github.com>
* Initial plan * Fix all references from deploy.sequencer.yaml to stateful.sequencer.yaml Co-authored-by: sfroment <7238385+sfroment@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: sfroment <7238385+sfroment@users.noreply.github.com>
* Initial plan * Call shutdown() on error paths to ensure consistent cleanup Co-authored-by: sfroment <7238385+sfroment@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: sfroment <7238385+sfroment@users.noreply.github.com>
Signed-off-by: Sacha Froment <sfroment42@gmail.com>
Why is this change necessary?
Add sequencer failover process by using k8s.
Description
Add k8s lease logic (leader election logic) so that make multiple sequencer run for HA.
the lease has 15 secs of TTL and leader will renew it's lease every 3 secs.
Closes #262
Type of change
Checklist