lava-operator 0.5.11

lava-operator — typed Kubernetes controller for the LavaArchitecture CRD. Operators submit a LavaArchitecture manifest naming a .tlisp source + bindings + gate; the controller renders via magma-lava + applies via the embedded magma path (or shells out to tofu/terraform). Status conditions track Synthesized / Planned / Applied / Failed phases. Pangea-operator analog for the lava + tatara-lisp stack.
Documentation
//! lava-operator binary.
//!
//! Subcommands:
//!   - `crd`  — emit the LavaArchitecture CRD YAML to stdout
//!   - `run`  — start the kube-rs controller loop (requires the
//!              `controller` feature at build time)
//!
//! With no args, defaults to `crd` for backward compatibility with
//! `lava-operator > crd.yaml` pipelines.

fn main() {
    let cmd = std::env::args().nth(1).unwrap_or_else(|| "crds".to_string());
    match cmd.as_str() {
        // Single CRD (LavaArchitecture) — backwards compat for any
        // existing `lava-operator > crd.yaml` pipeline.
        "crd" => print!("{}", lava_operator::crd_yaml()),
        // Every CRD the operator owns (LavaArchitecture +
        // RemediationPolicy + LavaArchitectureDependency).
        "crds" => print!("{}", lava_operator::crd_yaml_all()),
        "run" => run_controller(),
        other => {
            eprintln!("unknown subcommand `{other}` (expected: crd | crds | run)");
            std::process::exit(2);
        }
    }
}

#[cfg(feature = "controller")]
fn run_controller() {
    #[allow(unused_imports)]
    use std::sync::Arc;
    tracing_subscriber::fmt()
        .with_env_filter(
            tracing_subscriber::EnvFilter::try_from_default_env()
                .unwrap_or_else(|_| "info".into()),
        )
        .init();
    let rt = tokio::runtime::Builder::new_multi_thread()
        .enable_all()
        .build()
        .expect("tokio runtime");
    let synthesize: lava_operator::controller::SynthesizeFn = {
        #[cfg(feature = "magma-bridge")]
        {
            lava_operator::magma_bridge::magma_lava_synthesize()
        }
        #[cfg(not(feature = "magma-bridge"))]
        {
            Arc::new(|_src, _b, _g| {
                // Built without magma-bridge — stub so the loop runs
                // end-to-end against a cluster, but synth is a no-op.
                Ok(serde_json::json!({ "resource": {} }))
            })
        }
    };
    if let Err(e) = rt.block_on(lava_operator::controller::run(synthesize)) {
        eprintln!("controller exited with error: {e}");
        std::process::exit(1);
    }
}

#[cfg(not(feature = "controller"))]
fn run_controller() {
    eprintln!(
        "lava-operator was built without the `controller` feature. \
         Rebuild with `cargo build --features controller` to enable the \
         kube-rs reconcile loop."
    );
    std::process::exit(2);
}