#kubernetes #election #lease #consensus #coordination #api-bindings

kube-coordinate

使用coordination.k8s.io API进行Kubernetes领导者选举

6个版本

0.2.1 2024年3月6日
0.2.0 2024年3月6日
0.1.3 2023年12月11日

#149 in 异步

Download history 13/week @ 2024-03-27 210/week @ 2024-04-03 2014/week @ 2024-04-10 6992/week @ 2024-04-17 12327/week @ 2024-04-24 11491/week @ 2024-05-01 11166/week @ 2024-05-08 15348/week @ 2024-05-15 14956/week @ 2024-05-22 16504/week @ 2024-05-29 13330/week @ 2024-06-05 12836/week @ 2024-06-12 13157/week @ 2024-06-19 15667/week @ 2024-06-26 8289/week @ 2024-07-03 6658/week @ 2024-07-10

每月48,119次下载

MIT/Apache

33KB
423

Kube Coordinate

docs.rs Build Status

使用coordination.k8s.io API进行Kubernetes领导者选举。

Kube Coordinate基于kube-rs生态系统,并实现了一个精简版的client-go领导者选举系统。此实现仅使用Lease对象进行协调。

// Spawn a leader elector task, and get a handle to the state channel.
let handle = LeaderElector::spawn(/* ... */);
let state_chan = handle.state();

// Before taking action as a leader, just check the channel to ensure
// the lease is currently held by this process.
if state_chan.borrow().is_leader() {
    // Only perform leader actions if in leader state.
}

// Or, for a more sophisticated pattern, watch the state channel for changes,
// and use it to drive your application's state machine.
let state_stream = tokio_stream::wrappers::WatchStream::new(state_chan);
loop {
    tokio::select! {
        Some(state) = state_stream.next() => match state {
            LeaderState::Leader => (), // Leader tasks.
            _ => (), // Non-leader tasks.
        },
    }
}

安装

cargo add kube-coordinate

许可证

kube-coordinate根据您选择,受MIT许可证或Apache许可证2.0条款的约束。

依赖项

~73MB
~1M SLoC