@@ -283,42 +283,39 @@ pub async fn delete_applications() -> Result<(), Box<dyn Error>> {
283
283
error ! ( "❌ Failed to remove delete finalizers from Applications" ) ;
284
284
} ) ?;
285
285
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
+ } ;
295
291
292
+ let mut counter = 0 ;
293
+ let retry_count = 3 ;
294
+ loop {
296
295
debug ! ( "🗑 Deleting Applications" ) ;
297
296
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 ( ) {
305
304
break ;
306
305
}
307
306
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 ( ) ) ;
315
313
}
316
314
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 ;
321
317
}
318
+
322
319
info ! ( "🧼 Removed applications successfully" ) ;
323
320
Ok ( ( ) )
324
321
}
0 commit comments