kube
Rust client for Kubernetes API forking ynqa/kubernetes-rust.
This version has more error handling and a Reflector
for easy caching of CRD state. It aims to cater to the more common controller case, but allows you sticking in dependencies like k8s-openapi for accurate struct representations.
Examples
See the examples directory for how to watch over resources in a simplistic way.
See controller-rs for a full example with actix.
Reflector
The main abstraction exposed in this client is Reflector<T, U>
. This is a struct with the internal behaviour for watching kube resources, and updating internal state.
Ideally, you just feed in T
as a Spec
struct and U
as a Status
struct, which can be as complete or incomplete as you like. Here, using the complete structs via k8s-openapi:
use ;
let resource = Pods;
let rf : = new?;
then you can poll()
the reflector, and read()
to get the current cached state:
rf.poll?; // blocks and updates state
// read state and use it:
rf.read?.into_iter.for_each;
The reflector itself is responsible for acquiring the write lock and update the state as long as you call poll()
periodically.
Handling Events
Event handling is also exposed via the reflector at the moment:
let events = rf.events?;
reconcile?; // pass them on somewhere
you can use the exposed events however you wish:
Note that once you have called .events()
the events are considered handled, and are removed from the internal state.
License
Apache 2.0 licensed. See LICENSE for details.