Skip to content

Commit 15a1941

Browse files
committed
Chore | Removed ApplicationSet deletion code
1 parent 1d77c47 commit 15a1941

File tree

2 files changed

+29
-27
lines changed

2 files changed

+29
-27
lines changed

src/extract.rs

+24-27
Original file line numberDiff line numberDiff line change
@@ -283,42 +283,39 @@ pub async fn delete_applications() -> Result<(), Box<dyn Error>> {
283283
error!("❌ Failed to remove delete finalizers from Applications");
284284
})?;
285285

286-
loop {
287-
debug!("🗑 Deleting ApplicationSets");
288-
289-
match run_simple_command("kubectl delete applicationsets.argoproj.io --all -A") {
290-
Ok(_) => debug!("🗑 Deleted ApplicationSets"),
291-
Err(e) => {
292-
error!("❌ Failed to delete applicationsets: {}", &e.stderr)
293-
}
294-
};
286+
let verify_no_apps = || -> bool {
287+
run_simple_command("kubectl get applications -A --no-headers")
288+
.map(|e| e.stdout.trim().is_empty())
289+
.unwrap_or_default()
290+
};
295291

292+
let mut counter = 0;
293+
let retry_count = 3;
294+
loop {
296295
debug!("🗑 Deleting Applications");
297296

298-
let mut child = spawn_command("kubectl delete applications.argoproj.io --all -A", None);
299-
utils::sleep(5).await;
300-
if run_simple_command("kubectl get applications -A --no-headers")
301-
.map(|e| e.stdout.trim().is_empty())
302-
.unwrap_or_default()
303-
{
304-
let _ = child.kill();
297+
let _result =
298+
run_simple_command("kubectl delete applications.argoproj.io --all -A --timeout 10s")
299+
.inspect_err(|e| {
300+
debug!("Error: {}", e.stderr);
301+
});
302+
303+
if verify_no_apps() {
305304
break;
306305
}
307306

308-
utils::sleep(5).await;
309-
if run_simple_command("kubectl get applications -A --no-headers")
310-
.map(|e| e.stdout.trim().is_empty())
311-
.unwrap_or_default()
312-
{
313-
let _ = child.kill();
314-
break;
307+
if counter == retry_count {
308+
error!(
309+
"❌ Failed to delete applications after {} retries",
310+
retry_count
311+
);
312+
return Err("Failed to delete applications".into());
315313
}
316314

317-
match child.kill() {
318-
Ok(_) => debug!("Timed out. Retrying..."),
319-
Err(e) => error!("❌ Failed to delete applications: {}", e),
320-
};
315+
info!("⚠️ Failed to delete applications. Retrying...");
316+
counter += 1;
321317
}
318+
322319
info!("🧼 Removed applications successfully");
323320
Ok(())
324321
}

src/main.rs

+5
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,11 @@ async fn main() -> Result<(), Box<dyn Error>> {
142142
if !opt.keep_cluster_alive {
143143
cleanup_cluster(opt.local_cluster_tool, &opt.cluster_name);
144144
}
145+
if !opt.debug {
146+
error!("👀 Run with '--debug' for more details");
147+
} else {
148+
info!("If you think this error is caused by a bug, please open an issue on GitHub");
149+
}
145150
})
146151
}
147152

0 commit comments

Comments
 (0)