feat(HelmScore): Add values yaml option to helm chart score (#23)

Co-authored-by: tahahawa <tahahawa@gmail.com>
Reviewed-on: #23
This commit is contained in:
2025-04-29 16:09:04 +00:00
parent db9c8d83e6
commit 254f392cb5
3 changed files with 51 additions and 29 deletions

View File

@@ -9,6 +9,8 @@ use helm_wrapper_rs::blocking::{DefaultHelmExecutor, HelmExecutor};
pub use non_blank_string_rs::NonBlankString;
use serde::Serialize;
use std::collections::HashMap;
use std::path::Path;
use temp_file::TempFile;
#[derive(Debug, Clone, Serialize)]
pub struct HelmChartScore {
@@ -17,6 +19,7 @@ pub struct HelmChartScore {
pub chart_name: NonBlankString,
pub chart_version: Option<NonBlankString>,
pub values_overrides: Option<HashMap<NonBlankString, String>>,
pub values_yaml: Option<String>,
}
impl<T: Topology + HelmCommand> Score<T> for HelmChartScore {
@@ -48,6 +51,16 @@ impl<T: Topology + HelmCommand> Interpret<T> for HelmChartInterpret {
.namespace
.as_ref()
.unwrap_or_else(|| todo!("Get namespace from active kubernetes cluster"));
let tf: TempFile;
let yaml_path: Option<&Path> = match self.score.values_yaml.as_ref() {
Some(yaml_str) => {
tf = temp_file::with_contents(yaml_str.as_bytes());
Some(tf.path())
}
None => None,
};
let helm_executor = DefaultHelmExecutor::new();
let res = helm_executor.install_or_upgrade(
&ns,
@@ -55,9 +68,10 @@ impl<T: Topology + HelmCommand> Interpret<T> for HelmChartInterpret {
&self.score.chart_name,
self.score.chart_version.as_ref(),
self.score.values_overrides.as_ref(),
None,
yaml_path,
None,
);
let status = match res {
Ok(status) => status,
Err(err) => return Err(InterpretError::new(err.to_string())),