Skip to content

Conversation

@Giwook-Han
Copy link
Contributor

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

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update
  • Other (please describe):

Checklist

  • I have tested my changes
  • I have updated documentation if needed
  • I have reviewed my code for best practices

@Giwook-Han Giwook-Han requested a review from sfroment as a code owner November 18, 2025 04:43
@Giwook-Han Giwook-Han changed the title feat: Leader election with kube api and send through k8s feat: leader election with kube api and send through k8s Nov 18, 2025
@sfroment sfroment requested a review from Copilot November 21, 2025 09:00
Copy link
Contributor

Copilot AI left a 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.rs that 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.

@sfroment sfroment force-pushed the dev/giwook-Han/sequencer-failover branch from 561425b to 941f2cf Compare November 24, 2025 11:36
Giwook-Han and others added 18 commits November 25, 2025 18:40
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>
@sfroment sfroment force-pushed the dev/giwook-Han/sequencer-failover branch from a398ffd to b4c895f Compare November 25, 2025 17:43
sfroment and others added 3 commits December 3, 2025 09:53
* 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>
Copy link
Contributor

Copilot AI left a 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.

sfroment and others added 2 commits December 3, 2025 10:20
Signed-off-by: Sacha Froment <sfroment42@gmail.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Contributor

Copilot AI commented Dec 3, 2025

@sfroment I've opened a new pull request, #281, to work on those changes. Once the pull request is ready, I'll request review from you.

Copy link
Contributor

Copilot AI commented Dec 3, 2025

@sfroment I've opened a new pull request, #282, to work on those changes. Once the pull request is ready, I'll request review from you.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Contributor

Copilot AI commented Dec 3, 2025

@sfroment I've opened a new pull request, #283, to work on those changes. Once the pull request is ready, I'll request review from you.

Copy link
Contributor

Copilot AI commented Dec 3, 2025

@sfroment I've opened a new pull request, #284, to work on those changes. Once the pull request is ready, I'll request review from you.

Copilot AI and others added 5 commits December 3, 2025 10:32
* 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>
@sfroment sfroment merged commit 67bc8ce into main Dec 3, 2025
7 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.

Leader election with kube api and send through k8s

3 participants