From da7d57c2148867287bd817b16526c1370404c245 Mon Sep 17 00:00:00 2001 From: Donal Byrne Date: Sun, 21 Jul 2024 19:07:53 +0200 Subject: [PATCH] WIP --- src/executor.rs | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/executor.rs b/src/executor.rs index bee42e0..fbc107c 100644 --- a/src/executor.rs +++ b/src/executor.rs @@ -34,7 +34,7 @@ impl DefaultExecutor { } } - fn write_to_file(manifest: &str) -> Result> { + fn write_manifest_to_file(manifest: &str) -> Result> { let file_path = format!("/tmp/skate-{}.yaml", hash_string(manifest)); let mut file = File::create(file_path.clone()).expect("failed to open file for manifests"); file.write_all(manifest.as_ref()).expect("failed to write manifest to file"); @@ -42,6 +42,7 @@ impl DefaultExecutor { } fn reload_ingress(&self) -> Result<(), Box> { + // trigger SIGHUP to ingress container // sudo bash -c "podman kill --signal HUP \$(podman ps --filter label=skate.io/namespace=skate --filter label=skate.io/daemonset=nginx-ingress -q)" let id = exec_cmd("podman", &["ps", "--filter", "label=skate.io/namespace=skate", "--filter", "label=skate.io/daemonset=nginx-ingress", "-q"])?; @@ -63,7 +64,9 @@ impl DefaultExecutor { let _systemd_timer_schedule = cron_to_systemd(&spec.schedule, &timezone)?; + //////////////////////////////////////////////////// // extract pod spec and add file /pod-manifest.yaml + //////////////////////////////////////////////////// let pod_template_spec = spec.job_template.spec.unwrap_or_default().template; @@ -73,12 +76,22 @@ impl DefaultExecutor { let pod_string = serde_yaml::to_string(&pod).map_err(|e| anyhow!(e).context("failed to serialize manifest to yaml"))?; self.store.write_file("cronjob", &metadata_name(&cron_job).name, "pod.yaml", pod_string.as_bytes())?; + //////////////////////////////////////////////////// // template cron-pod.service to /var/lib/state/store/cronjob//systemd.service + //////////////////////////////////////////////////// + //TODO + //////////////////////////////////////////////////// // template cron-pod.timer to /var/lib/state/store/cronjob//systemd.timer + //////////////////////////////////////////////////// + + //TODO + // load via systemd + //TODO + Ok(()) } @@ -97,6 +110,11 @@ impl DefaultExecutor { let _output = exec_cmd("mkdir", &["-p", "/var/lib/skate/ingress/services"])?; + + //////////////////////////////////////////////////// + // Template main nginx conf + //////////////////////////////////////////////////// + let main_template_data = json!({ "letsEncrypt": { "endpoint": "" @@ -120,6 +138,10 @@ impl DefaultExecutor { let _ns_name = metadata_name(&ingress); + //////////////////////////////////////////////////// + // Template service nginx confs for http/https + //////////////////////////////////////////////////// + for port in [80, 443] { // convert manifest to json // set "port" key @@ -165,7 +187,7 @@ impl DefaultExecutor { // check if object's hostNetwork: true then don't use network=podman - let file_path = DefaultExecutor::write_to_file(&serde_yaml::to_string(&object)?)?; + let file_path = DefaultExecutor::write_manifest_to_file(&serde_yaml::to_string(&object)?)?; let mut args = vec!["play", "kube", &file_path, "--start"]; if !object.host_network() {