working on ensure_ready to check helm is available #17
@ -1,3 +1,5 @@
|
||||
use std::process::Command;
|
||||
|
||||
use async_trait::async_trait;
|
||||
use inquire::Confirm;
|
||||
use log::{info, warn};
|
||||
@ -11,7 +13,7 @@ use crate::{
|
||||
topology::LocalhostTopology,
|
||||
};
|
||||
|
||||
use super::{Topology, k8s::K8sClient};
|
||||
use super::{HelmCommand, Topology, k8s::K8sClient};
|
||||
|
||||
struct K8sState {
|
||||
_client: K8sClient,
|
||||
@ -28,6 +30,29 @@ pub struct K8sAnywhereTopology {
|
||||
}
|
||||
|
||||
impl K8sAnywhereTopology {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
k8s_state: OnceCell::new(),
|
||||
}
|
||||
}
|
||||
|
||||
fn is_helm_available(&self) -> Result<(), String> {
|
||||
let version_result = Command::new("helm")
|
||||
.arg("version")
|
||||
|
||||
.output()
|
||||
.map_err(|e| format!("Failed to execute 'helm -version': {}", e))?;
|
||||
|
||||
if !version_result.status.success() {
|
||||
return Err("Failed to run 'helm -version'".to_string());
|
||||
}
|
||||
|
||||
// Print the version output
|
||||
let version_output = String::from_utf8_lossy(&version_result.stdout);
|
||||
println!("Helm version: {}", version_output.trim());
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn try_load_system_kubeconfig(&self) -> Option<K8sClient> {
|
||||
todo!("Use kube-rs default behavior to load system kubeconfig");
|
||||
}
|
||||
@ -126,15 +151,25 @@ impl Topology for K8sAnywhereTopology {
|
||||
}
|
||||
|
||||
async fn ensure_ready(&self) -> Result<Outcome, InterpretError> {
|
||||
match self
|
||||
let k8s_state = self
|
||||
.k8s_state
|
||||
.get_or_try_init(|| self.try_get_or_install_k8s_client())
|
||||
.await?
|
||||
{
|
||||
Some(k8s_state) => Ok(Outcome::success(k8s_state.message.clone())),
|
||||
None => Err(InterpretError::new(
|
||||
.await?;
|
||||
|
||||
let k8s_state: &K8sState = k8s_state
|
||||
.as_ref()
|
||||
.ok_or(InterpretError::new(
|
||||
"No K8s client could be found or installed".to_string(),
|
||||
)),
|
||||
))?;
|
||||
|
||||
match self.is_helm_available() {
|
||||
Ok(()) => Ok(Outcome::success(format!(
|
||||
"{} + helm available",
|
||||
k8s_state.message.clone()
|
||||
))),
|
||||
Err(_) => Err(InterpretError::new("helm unavailable".to_string())),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl HelmCommand for K8sAnywhereTopology {}
|
||||
|
Loading…
Reference in New Issue
Block a user
Helm doesn't have
-version
it would beversion
or something like.args(vec!["version", "-c", "--short"])
for a shorter output