Our own Helm Command/Resource/Executor #13
@ -1,8 +1,10 @@
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
use std::env::temp_dir;
|
||||||
use std::ffi::OsStr;
|
use std::ffi::OsStr;
|
||||||
use std::io::ErrorKind;
|
use std::io::ErrorKind;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::process::{Command, Output};
|
use std::process::{Command, Output};
|
||||||
|
use temp_dir::{self, TempDir};
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct HelmCommandExecutor {
|
pub struct HelmCommandExecutor {
|
||||||
@ -18,8 +20,8 @@ pub struct HelmCommandExecutor {
|
|||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct HelmGlobals {
|
pub struct HelmGlobals {
|
||||||
chart_home: PathBuf,
|
pub chart_home: Option<PathBuf>,
|
||||||
config_home: PathBuf,
|
pub config_home: Option<PathBuf>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
@ -42,12 +44,16 @@ pub struct HelmChart {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl HelmCommandExecutor {
|
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
|
if self
|
||||||
.clone()
|
.clone()
|
||||||
.chart
|
.chart
|
||||||
.clone()
|
.clone()
|
||||||
.chart_exists_locally(self.clone().globals.chart_home)
|
.chart_exists_locally(self.clone().globals.chart_home.unwrap())
|
||||||
.is_none()
|
.is_none()
|
||||||
{
|
{
|
||||||
if self.chart.repo.is_none() {
|
if self.chart.repo.is_none() {
|
||||||
@ -59,14 +65,14 @@ impl HelmCommandExecutor {
|
|||||||
self.clone().run_command(
|
self.clone().run_command(
|
||||||
self.chart
|
self.chart
|
||||||
.clone()
|
.clone()
|
||||||
.pull_command(self.globals.chart_home.clone()),
|
.pull_command(self.globals.chart_home.clone().unwrap()),
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.clone().run_command(
|
self.clone().run_command(
|
||||||
self.chart
|
self.chart
|
||||||
.clone()
|
.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(
|
self.env.insert(
|
||||||
"HELM_CONFIG_HOME".to_string(),
|
"HELM_CONFIG_HOME".to_string(),
|
||||||
self.globals.config_home.to_str().unwrap().to_string(),
|
config_home.to_str().unwrap().to_string(),
|
||||||
);
|
);
|
||||||
self.env.insert(
|
self.env.insert(
|
||||||
"HELM_CACHE_HOME".to_string(),
|
"HELM_CACHE_HOME".to_string(),
|
||||||
self.globals.config_home.to_str().unwrap().to_string(),
|
config_home.to_str().unwrap().to_string(),
|
||||||
);
|
);
|
||||||
self.env.insert(
|
self.env.insert(
|
||||||
"HELM_DATA_HOME".to_string(),
|
"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()
|
Command::new(self.path).envs(self.env).args(args).output()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user