diff --git a/src/extract.rs b/src/extract.rs index b1f8917..a42add8 100644 --- a/src/extract.rs +++ b/src/extract.rs @@ -16,7 +16,11 @@ static ERROR_MESSAGES: [&str; 6] = [ "Unknown desc = `helm template .", ]; -static TIMEOUT_MESSAGES: [&str; 2] = ["Client.Timeout", "failed to get git client for repo"]; +static TIMEOUT_MESSAGES: [&str; 3] = [ + "Client.Timeout", + "failed to get git client for repo", + "rpc error: code = Unknown desc = Get \"https" +]; pub async fn get_resources( branch_type: &Branch, @@ -106,6 +110,7 @@ pub async fn get_resources( break; } + // TIMEOUT let time_elapsed = start_time.elapsed().as_secs(); if time_elapsed > timeout as u64 { error!("❌ Timed out after {} seconds", timeout); @@ -117,6 +122,7 @@ pub async fn get_resources( return Err("Timed out".into()); } + // ERRORS if !set_of_failed_apps.is_empty() { for (name, msg) in &set_of_failed_apps { error!( @@ -127,6 +133,7 @@ pub async fn get_resources( return Err("Failed to process applications".into()); } + // TIMED OUT APPS if !list_of_timed_out_apps.is_empty() { info!( "💤 {} Applications timed out.", diff --git a/src/kind.rs b/src/kind.rs index baf73dc..8f63147 100644 --- a/src/kind.rs +++ b/src/kind.rs @@ -4,7 +4,7 @@ use std::error::Error; use crate::{run_command, utils::spawn_command}; pub async fn is_installed() -> bool { - match run_command("kind version", None).await { + match run_command("which kind", None).await { Ok(_) => true, Err(_) => false, } diff --git a/src/main.rs b/src/main.rs index ba00bab..71deafc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -159,7 +159,7 @@ async fn main() -> Result<(), Box> { info!("✨ - secrets-folder: {}", secrets_folder); info!("✨ - output-folder: {}", output_folder); info!("✨ - git-repo: {}", repo); - info!("✨ - timeout: {}", timeout); + info!("✨ - timeout: {} seconds", timeout); if let Some(a) = file_regex.clone() { info!("✨ - file-regex: {}", a.as_str()); } diff --git a/src/minikube.rs b/src/minikube.rs index 15e43d5..9ea6173 100644 --- a/src/minikube.rs +++ b/src/minikube.rs @@ -4,7 +4,7 @@ use std::error::Error; use crate::{run_command, utils::spawn_command}; pub async fn is_installed() -> bool { - match run_command("minikube status", None).await { + match run_command("which minikube", None).await { Ok(_) => true, Err(_) => false, } diff --git a/src/parsing.rs b/src/parsing.rs index 58c9775..8eb3e23 100644 --- a/src/parsing.rs +++ b/src/parsing.rs @@ -4,6 +4,8 @@ use std::{error::Error, io::BufRead}; use log::{debug, info}; +type K8sResource = serde_yaml::Value; + pub async fn get_applications( directory: &str, branch: &str, @@ -15,7 +17,10 @@ pub async fn get_applications( Ok(output) } -async fn parse_yaml(directory: &str, regex: &Option) -> Result, Box> { +async fn parse_yaml( + directory: &str, + regex: &Option, +) -> Result, Box> { use walkdir::WalkDir; info!("🤖 Fetching all files in dir: {}", directory); @@ -34,15 +39,14 @@ async fn parse_yaml(directory: &str, regex: &Option) -> Result = yaml_files + let k8s_resources: Vec = yaml_files .flat_map(|f| { debug!("Found file: {}", f); - let file = std::fs::File::open(f).unwrap(); + let file = std::fs::File::open(&f).unwrap(); let reader = std::io::BufReader::new(file); let lines = reader.lines().map(|l| l.unwrap()); - // split list of strings by "---" - let string_lists: Vec = lines.fold(vec!["".to_string()], |mut acc, s| { + let mut raw_yaml_chunks: Vec = lines.fold(vec!["".to_string()], |mut acc, s| { if s == "---" { acc.push("".to_string()); } else { @@ -52,9 +56,19 @@ async fn parse_yaml(directory: &str, regex: &Option) -> Result = raw_yaml_chunks.iter_mut().enumerate().map(|(i,r)| { + let yaml = match serde_yaml::from_str(r) { + Ok(r) => r, + Err(e) => { + debug!("⚠️ Failed to parse element number {}, in file '{}', with error: '{}'", i, f, e); + serde_yaml::Value::Null + } + }; + yaml + }).collect(); + yaml_vec }) - .collect::>(); + .collect(); match regex { Some(r) => info!( @@ -69,7 +83,7 @@ async fn parse_yaml(directory: &str, regex: &Option) -> Result, + yaml_chunks: Vec, branch: &str, repo: &str, ) -> Result> { @@ -100,18 +114,8 @@ async fn patch_argocd_applications( } }; - let applications = yaml_chunks - .iter_mut() - .map(|r| { - let resource: serde_yaml::Value = match serde_yaml::from_str(r) { - Ok(r) => r, - Err(e) => { - debug!("⚠️ Failed to parse resource with error: {}", e); - serde_yaml::Value::Null - } - }; - resource - }) + let applications: Vec = yaml_chunks + .into_iter() .map(|mut r| { r["metadata"]["namespace"] = serde_yaml::Value::String("argocd".to_string()); r @@ -151,7 +155,7 @@ async fn patch_argocd_applications( ); r }) - .collect::>(); + .collect(); info!( "🤖 Patching {} Argo CD Application[Sets] for branch: {}",