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