6个版本
0.2.1 | 2024年3月6日 |
---|---|
0.2.0 | 2024年3月6日 |
0.1.3 | 2023年12月11日 |
#149 in 异步
每月48,119次下载
33KB
423 行
Kube Coordinate
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