feat: add cert-manager module and helm repo support
- Implemented a new `cert-manager` module for deploying cert-manager. - Added support for specifying a Helm repository in module configurations. - Introduced `cert_manager` module in `modules/mod.rs`. - Created `src/modules/cert_manager` directory and its associated code. - Implemented `add_repo` function in `src/modules/helm.rs` for adding Helm repositories. - Updated `LAMPInterpret` and `lamp.rs` to integrate the new module. - Added logging for Helm command execution. - Updated k8s deployment file to remove unused DeepMerge dependency.
This commit is contained in:
@@ -6,13 +6,31 @@ use crate::topology::{HelmCommand, Topology};
|
||||
use async_trait::async_trait;
|
||||
use helm_wrapper_rs;
|
||||
use helm_wrapper_rs::blocking::{DefaultHelmExecutor, HelmExecutor};
|
||||
use log::info;
|
||||
use log::{debug, error, info, warn};
|
||||
pub use non_blank_string_rs::NonBlankString;
|
||||
use serde::Serialize;
|
||||
use std::collections::HashMap;
|
||||
use std::path::Path;
|
||||
use std::process::{Command, Output, Stdio};
|
||||
use std::str::FromStr;
|
||||
use temp_file::TempFile;
|
||||
use url::Url;
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct HelmRepository {
|
||||
name: String,
|
||||
url: Url,
|
||||
force_update: bool,
|
||||
}
|
||||
impl HelmRepository {
|
||||
pub(crate) fn new(name: String, url: Url, force_update: bool) -> Self {
|
||||
Self {
|
||||
name,
|
||||
url,
|
||||
force_update,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct HelmChartScore {
|
||||
@@ -26,6 +44,7 @@ pub struct HelmChartScore {
|
||||
|
||||
/// Wether to run `helm upgrade --install` under the hood or only install when not present
|
||||
pub install_only: bool,
|
||||
pub repository: Option<HelmRepository>,
|
||||
}
|
||||
|
||||
impl<T: Topology + HelmCommand> Score<T> for HelmChartScore {
|
||||
@@ -44,6 +63,77 @@ impl<T: Topology + HelmCommand> Score<T> for HelmChartScore {
|
||||
pub struct HelmChartInterpret {
|
||||
pub score: HelmChartScore,
|
||||
}
|
||||
impl HelmChartInterpret {
|
||||
fn add_repo(&self) -> Result<(), InterpretError> {
|
||||
let repo = match &self.score.repository {
|
||||
Some(repo) => repo,
|
||||
None => {
|
||||
info!("No Helm repository specified in the score. Skipping repository setup.");
|
||||
return Ok(());
|
||||
}
|
||||
};
|
||||
info!(
|
||||
"Ensuring Helm repository exists: Name='{}', URL='{}', ForceUpdate={}",
|
||||
repo.name, repo.url, repo.force_update
|
||||
);
|
||||
|
||||
let mut add_args = vec!["repo", "add", &repo.name, repo.url.as_str()];
|
||||
if repo.force_update {
|
||||
add_args.push("--force-update");
|
||||
}
|
||||
|
||||
let add_output = run_helm_command(&add_args)?;
|
||||
let full_output = format!(
|
||||
"{}\n{}",
|
||||
String::from_utf8_lossy(&add_output.stdout),
|
||||
String::from_utf8_lossy(&add_output.stderr)
|
||||
);
|
||||
|
||||
match add_output.status.success() {
|
||||
true => {
|
||||
return Ok(());
|
||||
}
|
||||
false => {
|
||||
return Err(InterpretError::new(format!(
|
||||
"Failed to add helm repository!\n{full_output}"
|
||||
)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn run_helm_command(args: &[&str]) -> Result<Output, InterpretError> {
|
||||
let command_str = format!("helm {}", args.join(" "));
|
||||
debug!("Running Helm command: `{}`", command_str);
|
||||
|
||||
let output = Command::new("helm")
|
||||
.args(args)
|
||||
.stdout(Stdio::piped())
|
||||
.stderr(Stdio::piped())
|
||||
.output()
|
||||
.map_err(|e| {
|
||||
InterpretError::new(format!(
|
||||
"Failed to execute helm command '{}': {}. Is helm installed and in PATH?",
|
||||
command_str, e
|
||||
))
|
||||
})?;
|
||||
|
||||
if !output.status.success() {
|
||||
let stdout = String::from_utf8_lossy(&output.stdout);
|
||||
let stderr = String::from_utf8_lossy(&output.stderr);
|
||||
warn!(
|
||||
"Helm command `{}` failed with status: {}\nStdout:\n{}\nStderr:\n{}",
|
||||
command_str, output.status, stdout, stderr
|
||||
);
|
||||
} else {
|
||||
debug!(
|
||||
"Helm command `{}` finished successfully. Status: {}",
|
||||
command_str, output.status
|
||||
);
|
||||
}
|
||||
|
||||
Ok(output)
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl<T: Topology + HelmCommand> Interpret<T> for HelmChartInterpret {
|
||||
@@ -67,6 +157,8 @@ impl<T: Topology + HelmCommand> Interpret<T> for HelmChartInterpret {
|
||||
None => None,
|
||||
};
|
||||
|
||||
self.add_repo()?;
|
||||
|
||||
let helm_executor = DefaultHelmExecutor::new();
|
||||
|
||||
let mut helm_options = Vec::new();
|
||||
|
||||
Reference in New Issue
Block a user