krab-controllers 0.2.2

Scheduler, kubelet and controllers for krabkube
Documentation
pub mod deployment;
pub mod endpoints;
pub mod kubelet;
pub mod node;
pub mod pvc;
pub mod replicaset;
pub mod scheduler;
pub mod util;

#[cfg(test)]
mod fake;

use krab_runtime::Runtime;
use krab_store::MemStore;
use std::sync::Arc;
use tokio::task::JoinHandle;

pub use kubelet::Config;
pub use util::Recorder;

pub struct Tasks(pub Vec<JoinHandle<()>>);

impl Drop for Tasks {
    fn drop(&mut self) {
        for t in &self.0 {
            t.abort();
        }
    }
}

pub async fn run_all<R: Runtime>(store: Arc<MemStore>, rt: Arc<R>, node_name: String) {
    run_with(store, rt, Config::new(node_name)).await
}

pub async fn run_with<R: Runtime>(store: Arc<MemStore>, rt: Arc<R>, cfg: Config) {
    let rec = Arc::new(Recorder::new("krab"));
    let node = cfg.node_name.clone();
    let mut tasks = Tasks(vec![
        tokio::spawn(scheduler::run(store.clone(), rec.clone(), node.clone())),
        tokio::spawn(replicaset::run(store.clone(), rec.clone())),
        tokio::spawn(deployment::run(store.clone(), rec.clone())),
        tokio::spawn(endpoints::run(store.clone())),
        tokio::spawn(node::run(store.clone(), rt.clone(), node)),
        tokio::spawn(pvc::run(
            store.clone(),
            rec.clone(),
            cfg.volume_root.clone(),
        )),
        tokio::spawn(kubelet::run(store, rt, rec, cfg)),
    ]);
    for t in tasks.0.iter_mut() {
        let _ = t.await;
    }
}