Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
byrnedo committed Jul 21, 2024
1 parent e28a863 commit da7d57c
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,15 @@ impl DefaultExecutor {
}
}

fn write_to_file(manifest: &str) -> Result<String, Box<dyn Error>> {
fn write_manifest_to_file(manifest: &str) -> Result<String, Box<dyn Error>> {
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");
Ok(file_path)
}

fn reload_ingress(&self) -> Result<(), Box<dyn Error>> {

// 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"])?;
Expand All @@ -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;

Expand All @@ -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/<name>/systemd.service
////////////////////////////////////////////////////

//TODO

////////////////////////////////////////////////////
// template cron-pod.timer to /var/lib/state/store/cronjob/<name>/systemd.timer
////////////////////////////////////////////////////

//TODO

// load via systemd

//TODO

Ok(())
}

Expand All @@ -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": ""
Expand All @@ -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
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit da7d57c

Please sign in to comment.