ensure charthome is set

This commit is contained in:
tahahawa 2025-05-08 08:51:17 -04:00
parent b7aee6289d
commit ecb2b3f893

View File

@ -1,8 +1,10 @@
use std::collections::HashMap;
use std::env::temp_dir;
use std::ffi::OsStr;
use std::io::ErrorKind;
use std::path::{Path, PathBuf};
use std::process::{Command, Output};
use temp_dir::{self, TempDir};
#[derive(Clone)]
pub struct HelmCommandExecutor {
@ -18,8 +20,8 @@ pub struct HelmCommandExecutor {
#[derive(Clone)]
pub struct HelmGlobals {
chart_home: PathBuf,
config_home: PathBuf,
pub chart_home: Option<PathBuf>,
pub config_home: Option<PathBuf>,
}
#[derive(Clone)]
@ -42,12 +44,16 @@ pub struct HelmChart {
}
impl HelmCommandExecutor {
pub fn generate(&self) -> Result<Output, std::io::Error> {
pub fn generate(mut self) -> Result<Output, std::io::Error> {
if self.globals.chart_home.is_none() {
self.globals.chart_home = Some(PathBuf::from("charts"));
}
if self
.clone()
.chart
.clone()
.chart_exists_locally(self.clone().globals.chart_home)
.chart_exists_locally(self.clone().globals.chart_home.unwrap())
.is_none()
{
if self.chart.repo.is_none() {
@ -59,14 +65,14 @@ impl HelmCommandExecutor {
self.clone().run_command(
self.chart
.clone()
.pull_command(self.globals.chart_home.clone()),
.pull_command(self.globals.chart_home.clone().unwrap()),
)?;
}
self.clone().run_command(
self.chart
.clone()
.helm_args(self.globals.chart_home.clone()),
.helm_args(self.globals.chart_home.clone().unwrap()),
)
}
@ -85,17 +91,22 @@ impl HelmCommandExecutor {
}
}
let config_home = match self.globals.config_home {
Some(p) => p,
None => PathBuf::from(TempDir::new()?.path()),
};
self.env.insert(
"HELM_CONFIG_HOME".to_string(),
self.globals.config_home.to_str().unwrap().to_string(),
config_home.to_str().unwrap().to_string(),
);
self.env.insert(
"HELM_CACHE_HOME".to_string(),
self.globals.config_home.to_str().unwrap().to_string(),
config_home.to_str().unwrap().to_string(),
);
self.env.insert(
"HELM_DATA_HOME".to_string(),
self.globals.config_home.to_str().unwrap().to_string(),
config_home.to_str().unwrap().to_string(),
);
Command::new(self.path).envs(self.env).args(args).output()