fn main() {
let cmd = std::env::args().nth(1).unwrap_or_else(|| "crds".to_string());
match cmd.as_str() {
"crd" => print!("{}", lava_operator::crd_yaml()),
"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| {
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);
}