Skip to content

Commit

Permalink
Add sleep after Argo CD Install (#89)
Browse files Browse the repository at this point in the history
  • Loading branch information
dag-andersen authored Jan 5, 2025
1 parent a3f0fbe commit ee668a7
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 12 deletions.
8 changes: 3 additions & 5 deletions src/argocd.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
error::{CommandError, CommandOutput},
utils::{run_command, run_command_with_envs, StringPair},
utils::{self, run_command, run_command_with_envs, StringPair},
};
use base64::prelude::*;
use log::{debug, error, info};
Expand Down Expand Up @@ -140,7 +140,7 @@ impl ArgoCDInstallation {
}
Err(_) => {
counter += 1;
tokio::time::sleep(tokio::time::Duration::from_secs(2)).await;
utils::sleep(2).await;
debug!("⏳ Retrying to get secret {}", secret_name);
None
}
Expand All @@ -156,11 +156,9 @@ impl ArgoCDInstallation {
})?
};

// sleep for 5 seconds
tokio::time::sleep(tokio::time::Duration::from_secs(5)).await;
utils::sleep(5).await;

// log into Argo CD

let username = "admin";
debug!(
"Logging in to Argo CD with username, {} and password, {}",
Expand Down
10 changes: 5 additions & 5 deletions src/extract.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::argocd::ArgoCDInstallation;
use crate::error::CommandError;
use crate::utils::{run_command, spawn_command, write_to_file};
use crate::utils::{self, run_command, spawn_command, write_to_file};
use crate::{apply_manifest, Branch};
use log::{debug, error, info};
use serde_yaml::Value;
Expand Down Expand Up @@ -159,7 +159,7 @@ pub async fn get_resources(
}

if applications.len() == processed_apps.len() {
tokio::time::sleep(tokio::time::Duration::from_secs(5)).await;
utils::sleep(5).await;
continue;
}

Expand Down Expand Up @@ -204,7 +204,7 @@ pub async fn get_resources(
);
}

tokio::time::sleep(tokio::time::Duration::from_secs(5)).await;
utils::sleep(5).await;
}

info!(
Expand Down Expand Up @@ -237,7 +237,7 @@ pub async fn delete_applications() -> Result<(), Box<dyn Error>> {
debug!("🗑 Deleting Applications");

let mut child = spawn_command("kubectl delete applications.argoproj.io --all -A", None);
tokio::time::sleep(tokio::time::Duration::from_secs(5)).await;
utils::sleep(5).await;
if run_command("kubectl get applications -A --no-headers")
.map(|e| e.stdout.trim().is_empty())
.unwrap_or_default()
Expand All @@ -246,7 +246,7 @@ pub async fn delete_applications() -> Result<(), Box<dyn Error>> {
break;
}

tokio::time::sleep(tokio::time::Duration::from_secs(5)).await;
utils::sleep(5).await;
if run_command("kubectl get applications -A --no-headers")
.map(|e| e.stdout.trim().is_empty())
.unwrap_or_default()
Expand Down
4 changes: 3 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,8 @@ async fn run() -> Result<(), Box<dyn Error>> {

argocd.install_argo_cd(debug).await?;

utils::sleep(5).await;

let temp_folder = "temp";
create_folder_if_not_exists(temp_folder)?;

Expand Down Expand Up @@ -377,7 +379,7 @@ async fn run() -> Result<(), Box<dyn Error>> {
extract::get_resources(&argocd, &base_branch, timeout, output_folder, temp_folder).await?;
if found_target_apps {
extract::delete_applications().await?;
tokio::time::sleep(tokio::time::Duration::from_secs(5)).await;
utils::sleep(5).await;
}
}
if found_target_apps {
Expand Down
5 changes: 4 additions & 1 deletion src/parsing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,10 @@ fn from_resource_to_application(
filtered_apps.len()
);
} else {
info!("🤖 Found {} Application[Sets]", number_of_apps_before_filtering);
info!(
"🤖 Found {} Application[Sets]",
number_of_apps_before_filtering
);
}

filtered_apps
Expand Down
5 changes: 5 additions & 0 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,8 @@ pub fn write_to_file(file_name: &str, content: &str) -> Result<(), Box<dyn Error
fs::write(file_name, content)?;
Ok(())
}

pub async fn sleep(seconds: u64) {
debug!("Sleeping for {} seconds", seconds);
tokio::time::sleep(tokio::time::Duration::from_secs(seconds)).await;
}

0 comments on commit ee668a7

Please sign in to comment.