kubus

Crates.iokubus
lib.rskubus
version0.6.0
created_at2025-10-06 08:02:43.141324+00
updated_at2026-01-20 00:22:12.067241+00
descriptionDerive based kubernetes operator framework
homepagehttps://github.com/juliamertz/kubus
repositoryhttps://github.com/juliamertz/kubus
max_upload_size
id1869911
size102,238
Julia (juliamertz)

documentation

README

Kubus

A small Rust library for building Kubernetes operators with less boilerplate.

Example

use std::{sync::Arc};

use k8s_openapi::api::core::v1::Pod;
use kube::{Client, ResourceExt, runtime::controller::Action};
use kubus::{Context, HandlerError, Operator, kubus};

struct State {}

#[tokio::main]
async fn main() -> Result<(), kubus::Error> {
    let client = Client::try_default().await?;
    let state = State {};

    Operator::builder()
        .with_context((client, state))
        .handler(on_pod_apply)
        .run()
        .await
}

#[kubus(event = Apply, finalizer = "kubus.io/cleanup")]
async fn on_pod_apply(pod: Arc<Pod>, _ctx: Arc<Context<State>>) -> Result<(), HandlerError> {
    let name = pod.name_unchecked();
    let namespace = pod.namespace().unwrap();

    println!("apply event for pod {name} in {namespace}");

    Ok(())
}

The #[kubus] attribute handles the watcher setup, reconciliation loop, and finalizer management. You just write functions that handle events.

Status

Experimental - the API will probably change as I figure out what works.

Thanks to

  • kopf For the inspiration
  • kube-rs For the amazing library
Commit count: 40

cargo fmt