Skip to content

Commit

Permalink
Fix not auto picking the newest version of ArgoCD helm Chart (#86)
Browse files Browse the repository at this point in the history
* Run "helm repo update" before installing argocd

* Print helm chart version and app version after argocd installation
  • Loading branch information
dag-andersen authored Jan 5, 2025
1 parent 3639990 commit c40ef39
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 12 deletions.
36 changes: 35 additions & 1 deletion src/argocd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::{
};
use base64::prelude::*;
use log::{debug, error, info};
use serde_yaml::Value;
use std::error::Error;

pub struct ArgoCDInstallation {
Expand Down Expand Up @@ -58,6 +59,12 @@ impl ArgoCDInstallation {
CommandError::new(e)
})?;

// helm update
run_command("helm repo update").map_err(|e| {
error!("❌ Failed to update helm repo");
CommandError::new(e)
})?;

let helm_install_command = format!(
"helm install argocd argo/argo-cd -n {} {} {} {}",
self.namespace,
Expand All @@ -84,7 +91,31 @@ impl ArgoCDInstallation {
Ok(_) => info!("🦑 Argo CD is now available"),
Err(_) => {
error!("❌ Failed to wait for argocd-server");
return Err("Failed to wait for argocd-server".to_string().into());
return Err("Failed to wait for argocd-server".into());
}
}

match run_command("helm list -A -o yaml") {
Ok(o) => {
let as_yaml: Value = serde_yaml::from_str(&o.stdout)?;
match (
as_yaml[0]["chart"].as_str(),
as_yaml[0]["app_version"].as_str(),
) {
(Some(chart_version), Some(app_version)) => {
info!(
"🦑 Installed Chart version: '{}' and App version: '{}'",
chart_version, app_version
);
}
_ => {
error!("❌ Failed to get chart version");
}
}
}
Err(e) => {
error!("❌ Failed to list helm charts");
return Err(Box::new(CommandError::new(e)));
}
}

Expand Down Expand Up @@ -167,6 +198,9 @@ impl ArgoCDInstallation {
}
}

// Add extra permissions to the default AppProject
let _ = self.run_argocd_command("argocd proj add-source-namespace default *");

info!("🦑 Argo CD installed successfully");
Ok(())
}
Expand Down
17 changes: 6 additions & 11 deletions src/extract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,14 @@ pub async fn get_resources(

loop {
let command = "kubectl get applications -A -oyaml".to_string();
let applications: Result<Value, serde_yaml::Error> = match run_command(&command) {
Ok(o) => serde_yaml::from_str(&o.stdout),
let yaml_output: Value = match run_command(&command) {
Err(e) => return Err(format!("❌ Failed to get applications: {}", e.stderr).into()),
};

let applications = match applications {
Ok(applications) => applications,
Err(_) => {
return Err(format!("❌ Failed to parse yaml from command: {}", command).into());
}
};
Ok(o) => serde_yaml::from_str(&o.stdout).inspect_err(|_e| {
error!("❌ Failed to parse yaml from command: {}", command);
}),
}?;

let applications = match applications["items"].as_sequence() {
let applications = match yaml_output["items"].as_sequence() {
None => break,
Some(apps) if apps.is_empty() => break,
Some(apps) if apps.len() == processed_apps.len() => break,
Expand Down

0 comments on commit c40ef39

Please sign in to comment.