2026-01-26 08:26:15 +01:00
|
|
|
use std::{io, process::Stdio};
|
2025-12-01 12:48:39 +01:00
|
|
|
|
|
|
|
|
use thiserror::Error;
|
|
|
|
|
use tokio::process::Command;
|
2025-12-11 10:08:49 +01:00
|
|
|
use tracing::{debug, info};
|
2025-12-01 12:48:39 +01:00
|
|
|
|
2026-01-26 08:26:15 +01:00
|
|
|
use crate::infrastructure::assets::{RunnerAssets, cfgsync_port_value, workspace_root};
|
2025-12-01 12:48:39 +01:00
|
|
|
|
|
|
|
|
/// Errors returned from Helm invocations.
|
|
|
|
|
#[derive(Debug, Error)]
|
|
|
|
|
pub enum HelmError {
|
|
|
|
|
#[error("failed to spawn {command}: {source}")]
|
|
|
|
|
Spawn {
|
|
|
|
|
command: String,
|
|
|
|
|
#[source]
|
|
|
|
|
source: io::Error,
|
|
|
|
|
},
|
|
|
|
|
#[error("{command} exited with status {status:?}\nstderr:\n{stderr}\nstdout:\n{stdout}")]
|
|
|
|
|
Failed {
|
|
|
|
|
command: String,
|
|
|
|
|
status: Option<i32>,
|
|
|
|
|
stdout: String,
|
|
|
|
|
stderr: String,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Install the Helm release for the provided topology counts.
|
|
|
|
|
pub async fn install_release(
|
|
|
|
|
assets: &RunnerAssets,
|
|
|
|
|
release: &str,
|
|
|
|
|
namespace: &str,
|
2026-01-26 08:26:15 +01:00
|
|
|
nodes: usize,
|
2025-12-01 12:48:39 +01:00
|
|
|
) -> Result<(), HelmError> {
|
2025-12-11 10:08:49 +01:00
|
|
|
info!(
|
|
|
|
|
release,
|
|
|
|
|
namespace,
|
2026-01-26 08:26:15 +01:00
|
|
|
nodes,
|
2025-12-11 10:08:49 +01:00
|
|
|
image = %assets.image,
|
|
|
|
|
cfgsync_port = cfgsync_port_value(),
|
|
|
|
|
values = %assets.values_file.display(),
|
|
|
|
|
"installing helm release"
|
|
|
|
|
);
|
2025-12-01 12:48:39 +01:00
|
|
|
|
2025-12-19 01:41:07 +01:00
|
|
|
let command = format!("helm install {release}");
|
2026-01-26 08:26:15 +01:00
|
|
|
let cmd = build_install_command(assets, release, namespace, nodes, &command);
|
2025-12-19 01:41:07 +01:00
|
|
|
let output = run_helm_command(cmd, &command).await?;
|
|
|
|
|
|
|
|
|
|
maybe_log_install_output(&command, &output);
|
|
|
|
|
|
|
|
|
|
info!(release, namespace, "helm install completed");
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn build_install_command(
|
|
|
|
|
assets: &RunnerAssets,
|
|
|
|
|
release: &str,
|
|
|
|
|
namespace: &str,
|
2026-01-26 08:26:15 +01:00
|
|
|
nodes: usize,
|
2025-12-19 01:41:07 +01:00
|
|
|
command: &str,
|
|
|
|
|
) -> Command {
|
2025-12-01 12:48:39 +01:00
|
|
|
let mut cmd = Command::new("helm");
|
|
|
|
|
cmd.arg("install")
|
|
|
|
|
.arg(release)
|
|
|
|
|
.arg(&assets.chart_path)
|
|
|
|
|
.arg("--namespace")
|
|
|
|
|
.arg(namespace)
|
|
|
|
|
.arg("--create-namespace")
|
|
|
|
|
.arg("--wait")
|
|
|
|
|
.arg("--timeout")
|
|
|
|
|
.arg("5m")
|
|
|
|
|
.arg("--set")
|
|
|
|
|
.arg(format!("image={}", assets.image))
|
|
|
|
|
.arg("--set")
|
2026-01-26 08:26:15 +01:00
|
|
|
.arg(format!("nodes.count={nodes}"))
|
2025-12-01 12:48:39 +01:00
|
|
|
.arg("--set")
|
2025-12-09 17:34:34 +01:00
|
|
|
.arg(format!("cfgsync.port={}", cfgsync_port_value()))
|
2025-12-01 12:48:39 +01:00
|
|
|
.arg("-f")
|
|
|
|
|
.arg(&assets.values_file)
|
|
|
|
|
.arg("--set-file")
|
|
|
|
|
.arg(format!("cfgsync.config={}", assets.cfgsync_file.display()))
|
|
|
|
|
.arg("--set-file")
|
|
|
|
|
.arg(format!(
|
|
|
|
|
"scripts.runCfgsyncSh={}",
|
|
|
|
|
assets.run_cfgsync_script.display()
|
|
|
|
|
))
|
|
|
|
|
.arg("--set-file")
|
|
|
|
|
.arg(format!(
|
|
|
|
|
"scripts.runNomosNodeSh={}",
|
|
|
|
|
assets.run_nomos_node_script.display()
|
|
|
|
|
))
|
2025-12-09 16:24:05 +01:00
|
|
|
.arg("--set-file")
|
|
|
|
|
.arg(format!(
|
|
|
|
|
"scripts.runNomosSh={}",
|
|
|
|
|
assets.run_nomos_script.display()
|
|
|
|
|
))
|
2025-12-01 12:48:39 +01:00
|
|
|
.stdout(Stdio::piped())
|
|
|
|
|
.stderr(Stdio::piped());
|
|
|
|
|
|
|
|
|
|
if let Ok(root) = workspace_root() {
|
|
|
|
|
cmd.current_dir(root);
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-19 01:41:07 +01:00
|
|
|
cmd.stdout(Stdio::piped()).stderr(Stdio::piped());
|
|
|
|
|
debug!(command, "prepared helm install command");
|
|
|
|
|
cmd
|
|
|
|
|
}
|
2025-12-01 12:48:39 +01:00
|
|
|
|
2025-12-19 01:41:07 +01:00
|
|
|
fn maybe_log_install_output(command: &str, output: &std::process::Output) {
|
|
|
|
|
if std::env::var("K8S_RUNNER_DEBUG").is_err() {
|
|
|
|
|
return;
|
2025-12-01 12:48:39 +01:00
|
|
|
}
|
|
|
|
|
|
2025-12-19 01:41:07 +01:00
|
|
|
debug!(
|
|
|
|
|
command,
|
|
|
|
|
stdout = %String::from_utf8_lossy(&output.stdout),
|
|
|
|
|
"helm install stdout"
|
|
|
|
|
);
|
|
|
|
|
debug!(
|
|
|
|
|
command,
|
|
|
|
|
stderr = %String::from_utf8_lossy(&output.stderr),
|
|
|
|
|
"helm install stderr"
|
|
|
|
|
);
|
2025-12-01 12:48:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Uninstall the release and namespace resources.
|
|
|
|
|
pub async fn uninstall_release(release: &str, namespace: &str) -> Result<(), HelmError> {
|
|
|
|
|
let mut cmd = Command::new("helm");
|
|
|
|
|
cmd.arg("uninstall")
|
|
|
|
|
.arg(release)
|
|
|
|
|
.arg("--namespace")
|
|
|
|
|
.arg(namespace)
|
|
|
|
|
.stdout(Stdio::piped())
|
|
|
|
|
.stderr(Stdio::piped());
|
|
|
|
|
|
2025-12-11 10:08:49 +01:00
|
|
|
info!(release, namespace, "issuing helm uninstall");
|
2025-12-01 12:48:39 +01:00
|
|
|
run_helm_command(cmd, &format!("helm uninstall {release}")).await?;
|
2025-12-11 10:08:49 +01:00
|
|
|
info!(release, namespace, "helm uninstall completed successfully");
|
2025-12-01 12:48:39 +01:00
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async fn run_helm_command(
|
|
|
|
|
mut cmd: Command,
|
|
|
|
|
command: &str,
|
|
|
|
|
) -> Result<std::process::Output, HelmError> {
|
|
|
|
|
cmd.stdout(Stdio::piped()).stderr(Stdio::piped());
|
|
|
|
|
let output = cmd.output().await.map_err(|source| HelmError::Spawn {
|
|
|
|
|
command: command.to_owned(),
|
|
|
|
|
source,
|
|
|
|
|
})?;
|
|
|
|
|
|
|
|
|
|
if output.status.success() {
|
|
|
|
|
Ok(output)
|
|
|
|
|
} else {
|
|
|
|
|
Err(HelmError::Failed {
|
|
|
|
|
command: command.to_owned(),
|
|
|
|
|
status: output.status.code(),
|
|
|
|
|
stdout: String::from_utf8_lossy(&output.stdout).into_owned(),
|
|
|
|
|
stderr: String::from_utf8_lossy(&output.stderr).into_owned(),
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|