A crate to implement leader election for Kubernetes workloads in Rust.

Overview

Kubernetes Leader Election in Rust

CI workflow crates.io version License: MIT

This library provides simple leader election for Kubernetes workloads.

[dependencies]
kube-leader-election = "0.1"

Example

Acquire leadership on a Kubernetes Lease called some-operator-lock, in the default namespace and promise to renew the lock every 15 seconds:

// See https://github.com/hendrikmaus/kube-leader-election/blob/master/examples/shared-lease.rs let lease = leadership.try_acquire_or_renew().await?; log::info!("currently leading: {}", lease.acquired_lease); ">
let leadership = LeaseLock::new(
    kube::Client::try_default().await?,
    "default",
    LeaseLockParams {
        holder_id: "some-operator".into(),
        lease_name: "some-operator-lock".into(),
        lease_ttl: Duration::from_secs(15),
    },
);

// Run this in a background task every 5 seconds
// Share the result with the rest of your application; for example using Arc
// See https://github.com/hendrikmaus/kube-leader-election/blob/master/examples/shared-lease.rs
let lease = leadership.try_acquire_or_renew().await?;

log::info!("currently leading: {}", lease.acquired_lease);

Please refer to the examples for runnable usage demonstrations.

Features

Kubernetes Lease Locking

A very basic form of leader election without fencing, i.e., only use this if your application can tolerate multiple replicas acting as leader for a short amount of time.

This implementation uses a Kubernetes Lease resource from the API group coordination.k8s.io, which is locked and continuously renewed by the leading replica. The leaseholder, as well as all candidates, use timestamps to determine if a lease can be acquired. Therefore, this implementation is volatile to datetime skew within a cluster.

Only use this implementation if you are aware of its downsides, and your workload can tolerate them.

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT

Comments
Releases(v0.18.0)
  • v0.18.0(Dec 15, 2022)

  • v0.17.0(Oct 31, 2022)

  • v0.16.0(Oct 7, 2022)

    0.16.0 (2022-10-07)

    ⚠ BREAKING CHANGES

    • do not enable chrono default features since that results in a dependency on a vulerable crate (#45)

    Features

    • do not enable chrono default features since that results in a dependency on a vulerable crate (#45) (4bc1940)
    Source code(tar.gz)
    Source code(zip)
  • v0.15.0(Sep 22, 2022)

  • v0.14.0(Jul 28, 2022)

  • v0.13.0(May 26, 2022)

  • v0.12.0(May 18, 2022)

  • v0.11.0(Apr 14, 2022)

  • v0.10.2(Feb 15, 2022)

  • v0.10.1(Feb 15, 2022)

  • 0.10.0(Feb 15, 2022)

    What's Changed

    • Update kube requirement from 0.68 to 0.69 by @dependabot in https://github.com/hendrikmaus/kube-leader-election/pull/23

    Full Changelog: https://github.com/hendrikmaus/kube-leader-election/compare/0.8.0...0.10.0

    Source code(tar.gz)
    Source code(zip)
  • 0.8.0(Feb 3, 2022)

    What's Changed

    • Update kube requirement from 0.67 to 0.68 by @dependabot in https://github.com/hendrikmaus/kube-leader-election/pull/22

    Full Changelog: https://github.com/hendrikmaus/kube-leader-election/compare/0.7.0...0.8.0

    Source code(tar.gz)
    Source code(zip)
  • 0.7.0(Jan 26, 2022)

    What's Changed

    • Update kube requirement from 0.66 to 0.67 by @dependabot in https://github.com/hendrikmaus/kube-leader-election/pull/21

    Full Changelog: https://github.com/hendrikmaus/kube-leader-election/compare/0.6.0...0.7.0

    Source code(tar.gz)
    Source code(zip)
  • 0.6.0(Jan 18, 2022)

    What's Changed

    • Update kube requirement from 0.65 to 0.66 by @dependabot in https://github.com/hendrikmaus/kube-leader-election/pull/20

    Full Changelog: https://github.com/hendrikmaus/kube-leader-election/compare/0.5.3...0.6.0

    Source code(tar.gz)
    Source code(zip)
  • 0.5.3(Dec 18, 2021)

  • 0.5.2(Dec 18, 2021)

  • 0.5.1(Dec 18, 2021)

    What's Changed

    • Use latest version of checkout action by @hendrikmaus in https://github.com/hendrikmaus/kube-leader-election/pull/17
    • Use cached release workflow by @hendrikmaus in https://github.com/hendrikmaus/kube-leader-election/pull/19

    Full Changelog: https://github.com/hendrikmaus/kube-leader-election/compare/0.5.0...0.5.1

    Source code(tar.gz)
    Source code(zip)
  • 0.5.0(Dec 18, 2021)

    What's Changed

    • Create dependabot.yaml by @hendrikmaus in https://github.com/hendrikmaus/kube-leader-election/pull/12
    • Run Clippy check in the CI workflow by @hendrikmaus in https://github.com/hendrikmaus/kube-leader-election/pull/16
    • Update kube requirement from 0.64 to 0.65 by @dependabot in https://github.com/hendrikmaus/kube-leader-election/pull/15

    New Contributors

    • @dependabot made their first contribution in https://github.com/hendrikmaus/kube-leader-election/pull/15

    Full Changelog: https://github.com/hendrikmaus/kube-leader-election/compare/0.4.0...0.5.0

    Source code(tar.gz)
    Source code(zip)
  • 0.4.0(Nov 19, 2021)

    What's Changed

    • 0.4.0: update kube to 0.64 by @jbg in https://github.com/hendrikmaus/kube-leader-election/pull/11

    Full Changelog: https://github.com/hendrikmaus/kube-leader-election/compare/0.3.0...0.4.0

    Source code(tar.gz)
    Source code(zip)
  • 0.3.0(Nov 16, 2021)

    What's Changed

    • Update kube dependency to 0.63 by @jbg in https://github.com/hendrikmaus/kube-leader-election/pull/10

    Full Changelog: https://github.com/hendrikmaus/kube-leader-election/compare/0.2.0...0.3.0

    Source code(tar.gz)
    Source code(zip)
  • 0.2.0(Sep 11, 2021)

  • 0.1.2(Jul 26, 2021)

  • 0.1.1(Jul 25, 2021)

Rust Kubernetes runtime helpers. Based on kube-rs.

kubert Rust Kubernetes runtime helpers. Based on kube-rs. Features clap command-line interface support; A basic admin server with /ready and /live pro

Oliver Gould 63 Dec 17, 2022
Detects orphan configmaps and secrets in a Kubernetes cluster

KubExplorer Warning: Proof of concept. Feedback is much welcome. Discovers and prints out any Configmaps and Secrets not linked to any of the followin

Pavel Pscheidl 56 Oct 21, 2022
💫 Small microservice to handle state changes of Kubernetes pods and post them to Instatus or Statuspages

?? Kanata Small microservice to handle state changes of Kubernetes pods and post to Instatus ?? Why? I don't really want to implement and repeat code

Noel ʕ •ᴥ•ʔ 4 Mar 4, 2022
kubernetes openapi unmangler

kopium A kubernetes openapi unmangler. Creates rust structs from a named crd by converting the live openapi schema. ⚠️ WARNING: ALPHA SOFTWARE ⚠️ Inst

kube-rs 48 Jan 3, 2023
Continuous Delivery for Declarative Kubernetes, Serverless and Infrastructure Applications

Continuous Delivery for Declarative Kubernetes, Serverless and Infrastructure Applications Explore PipeCD docs » Overview PipeCD provides a unified co

PipeCD 650 Dec 29, 2022
engula-operator creates/configures/manages engula clusters atop Kubernetes

Engula Operator The engula operator manages engula clusters deployed to Kubernetes and automates tasks related to operating an engula cluster. Backgro

小母牛坐飞机 12 Apr 27, 2022
Ultralight, security-first service mesh for Kubernetes. Main repo for Linkerd 2.x.

Linkerd ?? Welcome to Linkerd! ?? Linkerd is an ultralight, security-first service mesh for Kubernetes. Linkerd adds critical security, observability,

Linkerd 9.2k Jan 1, 2023
Northstar is a horizontally scalable and multi-tenant Kubernetes cluster provisioner and orchestrator

Northstar Northstar is a horizontally scalable and multi-tenant Kubernetes cluster provisioner and orchestrator. Explore the docs » View Demo · Report

Lucas Clerisse 1 Jan 22, 2022
The last kubernetes tool you'll ever need.

Neatkube The last kubernetes tool you'll ever need. Kubernetes is a mess. Everthing ships it's own command line tools that you need to install and tra

git repositories with lazers 5 Aug 3, 2022
Kubernetes + wasmCloud

KasmCloud Managing and Running Actors, Providers, and Links in Kubernetes ⚠️ Warning This is a contributor-led experimental project and is not recomme

wasmcloud 22 Oct 8, 2023
KFtray - A tray application that manages port forwarding in Kubernetes.

Ktray is written in Rust and React, with Tauri framework. The app simplifies the process of starting and stopping multiple port forwarding configurations through a user-friendly interface.

Henrique Cavarsan 42 Dec 17, 2023
Rust crate which provides direct access to files within a Debian archive

debarchive This Rust crate provides direct access to files within a Debian archive. This crate is used by our debrep utility to generate the Packages

Pop!_OS 11 Dec 18, 2021
Granular locking crate for Rust

Granular locking crate for Rust. Instead of using coarse-grained Mutex or RwLock which can be used to lock an entire structure, glock provides more granular locking.

Ayman Madkour 9 Jul 22, 2022
This crate allows writing a struct in Rust and have it derive a struct of arrays layed out in memory according to the arrow format.

Arrow2-derive - derive for Arrow2 This crate allows writing a struct in Rust and have it derive a struct of arrays layed out in memory according to th

Jorge Leitao 29 Dec 27, 2022
Tiny Rust crate to iterate bit combinations

bit_combi_iter bit_combi_iter is a small dependency-free crate to enumerate all bit combinations less than given unsigned integer value keeping 1s in

Linda_pp 5 Apr 11, 2022
Membrane is an opinionated crate that generates a Dart package from a Rust library. Extremely fast performance with strict typing and zero copy returns over the FFI boundary via bincode.

Membrane is an opinionated crate that generates a Dart package from a Rust library. Extremely fast performance with strict typing and zero copy returns over the FFI boundary via bincode.

Jerel Unruh 70 Dec 13, 2022
Rust crate for reading SER files used in astrophotography

Rust crate for reading SER files used in astrophotography.

Andy Grove 2 Oct 4, 2021
A Rust crate for handling URNs.

URN A Rust crate for handling URNs. Parsing and comparison is done according to the spec (meaning only part of the URN is used for equality checks). S

null 7 Jun 25, 2022
The efficient and elegant crate to count variants of Rust's Enum.

variant-counter The efficient and elegant crate to count variants of Rust's Enum. Get started #[derive(VariantCount)] #[derive(VariantCount)] pub enum

Folyd 16 Sep 29, 2022