Skip to main content

krab_controllers/
lib.rs

1pub mod deployment;
2pub mod endpoints;
3pub mod kubelet;
4pub mod node;
5pub mod pvc;
6pub mod replicaset;
7pub mod scheduler;
8pub mod util;
9
10#[cfg(test)]
11mod fake;
12
13use krab_runtime::Runtime;
14use krab_store::MemStore;
15use std::sync::Arc;
16use tokio::task::JoinHandle;
17
18pub use kubelet::Config;
19pub use util::Recorder;
20
21pub struct Tasks(pub Vec<JoinHandle<()>>);
22
23impl Drop for Tasks {
24    fn drop(&mut self) {
25        for t in &self.0 {
26            t.abort();
27        }
28    }
29}
30
31pub async fn run_all<R: Runtime>(store: Arc<MemStore>, rt: Arc<R>, node_name: String) {
32    run_with(store, rt, Config::new(node_name)).await
33}
34
35pub async fn run_with<R: Runtime>(store: Arc<MemStore>, rt: Arc<R>, cfg: Config) {
36    let rec = Arc::new(Recorder::new("krab"));
37    let node = cfg.node_name.clone();
38    let mut tasks = Tasks(vec![
39        tokio::spawn(scheduler::run(store.clone(), rec.clone(), node.clone())),
40        tokio::spawn(replicaset::run(store.clone(), rec.clone())),
41        tokio::spawn(deployment::run(store.clone(), rec.clone())),
42        tokio::spawn(endpoints::run(store.clone())),
43        tokio::spawn(node::run(store.clone(), rt.clone(), node)),
44        tokio::spawn(pvc::run(
45            store.clone(),
46            rec.clone(),
47            cfg.volume_root.clone(),
48        )),
49        tokio::spawn(kubelet::run(store, rt, rec, cfg)),
50    ]);
51    for t in tasks.0.iter_mut() {
52        let _ = t.await;
53    }
54}