@@ -53,6 +53,7 @@ import (
53
53
apstore "github.com/argoproj-labs/argocd-autopilot/pkg/store"
54
54
aputil "github.com/argoproj-labs/argocd-autopilot/pkg/util"
55
55
argocdv1alpha1 "github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
56
+ argocdv1alpha1cs "github.com/argoproj/argo-cd/v2/pkg/client/clientset/versioned"
56
57
aev1alpha1 "github.com/argoproj/argo-events/pkg/apis/eventsource/v1alpha1"
57
58
58
59
"github.com/Masterminds/semver/v3"
@@ -743,7 +744,7 @@ func createGitSources(ctx context.Context, opts *RuntimeInstallOptions) error {
743
744
mpCloneOpts .Parse ()
744
745
745
746
createGitSrcMessgae := fmt .Sprintf ("Creating %s" , store .Get ().MarketplaceGitSourceName )
746
-
747
+
747
748
err = RunGitSourceCreate (ctx , & GitSourceCreateOptions {
748
749
InsCloneOpts : opts .InsCloneOpts ,
749
750
GsCloneOpts : mpCloneOpts ,
@@ -796,7 +797,7 @@ func removeGitIntegrations(ctx context.Context, opts *RuntimeUninstallOptions) e
796
797
for _ , intg := range integrations {
797
798
if err = RunGitIntegrationRemoveCommand (ctx , appProxyClient , intg .Name ); err != nil {
798
799
command := util .Doc (fmt .Sprintf ("\t <BIN> integration git remove %s" , intg .Name ))
799
-
800
+
800
801
return fmt .Errorf (`%w. You can try to remove it manually by running: %s` , err , command )
801
802
}
802
803
}
@@ -1264,9 +1265,13 @@ func NewRuntimeUninstallCommand() *cobra.Command {
1264
1265
createAnalyticsReporter (ctx , reporter .UninstallFlow )
1265
1266
1266
1267
err := runtimeUninstallCommandPreRunHandler (cmd , args , & uninstallationOpts )
1267
- handleCliStep (reporter .UninstallPhasePreCheckFinish , "Finished pre installation checks" , err , false )
1268
+ handleCliStep (reporter .UninstallPhasePreCheckFinish , "Finished pre run checks" , err , false )
1268
1269
if err != nil {
1269
- return fmt .Errorf ("pre installation error: %w" , err )
1270
+ if errors .Is (err , promptui .ErrInterrupt ) {
1271
+ return fmt .Errorf ("uninstallation canceled by user" )
1272
+ }
1273
+
1274
+ return fmt .Errorf ("pre run error: %w" , err )
1270
1275
}
1271
1276
1272
1277
finalParameters = map [string ]string {
@@ -1339,6 +1344,13 @@ func RunRuntimeUninstall(ctx context.Context, opts *RuntimeUninstallOptions) err
1339
1344
return err
1340
1345
}
1341
1346
1347
+ subCtx , cancel := context .WithCancel (ctx )
1348
+ go func () {
1349
+ if err := printApplicationsState (subCtx , opts .RuntimeName , opts .KubeFactory ); err != nil {
1350
+ log .G (ctx ).WithError (err ).Debug ("failed to print uninstallation progress" )
1351
+ }
1352
+ }()
1353
+
1342
1354
err = apcmd .RunRepoUninstall (ctx , & apcmd.RepoUninstallOptions {
1343
1355
Namespace : opts .RuntimeName ,
1344
1356
Timeout : opts .Timeout ,
@@ -1347,6 +1359,7 @@ func RunRuntimeUninstall(ctx context.Context, opts *RuntimeUninstallOptions) err
1347
1359
Force : opts .Force ,
1348
1360
FastExit : opts .FastExit ,
1349
1361
})
1362
+ cancel () // to tell the progress to stop displaying even if it's not finished
1350
1363
if opts .Force {
1351
1364
err = nil
1352
1365
}
@@ -1372,6 +1385,115 @@ func RunRuntimeUninstall(ctx context.Context, opts *RuntimeUninstallOptions) err
1372
1385
return nil
1373
1386
}
1374
1387
1388
+ func printApplicationsState (ctx context.Context , runtime string , f kube.Factory ) error {
1389
+ apps := map [string ]* argocdv1alpha1.Application {}
1390
+ lock := sync.Mutex {}
1391
+
1392
+ rc , err := f .ToRESTConfig ()
1393
+ if err != nil {
1394
+ return err
1395
+ }
1396
+
1397
+ cs , err := argocdv1alpha1cs .NewForConfig (rc )
1398
+ if err != nil {
1399
+ return err
1400
+ }
1401
+
1402
+ appIf := cs .ArgoprojV1alpha1 ().Applications (runtime )
1403
+ componentsLabelSelector := fmt .Sprintf ("%s=%s" , store .Get ().LabelKeyCFType , store .Get ().CFComponentType )
1404
+
1405
+ curApps , err := appIf .List (ctx , metav1.ListOptions {LabelSelector : componentsLabelSelector })
1406
+ if err != nil {
1407
+ return err
1408
+ }
1409
+
1410
+ if len (curApps .Items ) == 0 {
1411
+ // all apps already deleted nothing to wait for
1412
+ return nil
1413
+ }
1414
+
1415
+ for i , a := range curApps .Items {
1416
+ apps [a .Name ] = & curApps .Items [i ]
1417
+ }
1418
+
1419
+ // refresh components state
1420
+ go func () {
1421
+ t := time .NewTicker (time .Second )
1422
+ for {
1423
+ select {
1424
+ case <- ctx .Done ():
1425
+ return
1426
+ case <- t .C :
1427
+ }
1428
+
1429
+ curApps , err := appIf .List (ctx , metav1.ListOptions {LabelSelector : componentsLabelSelector })
1430
+ if err != nil {
1431
+ log .G (ctx ).WithError (err ).Debug ("failed to refresh components state" )
1432
+ continue
1433
+ }
1434
+
1435
+ newApps := make (map [string ]* argocdv1alpha1.Application , len (curApps .Items ))
1436
+ for i , a := range curApps .Items {
1437
+ newApps [a .Name ] = & curApps .Items [i ]
1438
+ }
1439
+
1440
+ lock .Lock ()
1441
+ // update existing
1442
+ for i , a := range curApps .Items {
1443
+ apps [a .Name ] = & curApps .Items [i ]
1444
+ }
1445
+
1446
+ // clear deleted apps
1447
+ for name := range apps {
1448
+ if _ , ok := newApps [name ]; ! ok {
1449
+ delete (apps , name )
1450
+ }
1451
+ }
1452
+ lock .Unlock ()
1453
+ }
1454
+ }()
1455
+
1456
+ checkers := make ([]checklist.Checker , len (curApps .Items ))
1457
+ for i , a := range curApps .Items {
1458
+ name := a .Name
1459
+ checkers [i ] = func (ctx context.Context ) (checklist.ListItemState , checklist.ListItemInfo ) {
1460
+ lock .Lock ()
1461
+ defer lock .Unlock ()
1462
+ return getApplicationChecklistState (name , apps [name ], runtime )
1463
+ }
1464
+ }
1465
+
1466
+ cl := checklist .NewCheckList (
1467
+ os .Stdout ,
1468
+ checklist.ListItemInfo {"COMPONENT" , "STATUS" },
1469
+ checkers ,
1470
+ & checklist.CheckListOptions {
1471
+ WaitAllReady : true ,
1472
+ },
1473
+ )
1474
+
1475
+ if err := cl .Start (ctx ); err != nil && ctx .Err () == nil {
1476
+ return err
1477
+ }
1478
+
1479
+ return nil
1480
+ }
1481
+
1482
+ func getApplicationChecklistState (name string , a * argocdv1alpha1.Application , runtime string ) (checklist.ListItemState , checklist.ListItemInfo ) {
1483
+ state := checklist .Waiting
1484
+ name = strings .TrimPrefix (name , fmt .Sprintf ("%s-" , runtime ))
1485
+ status := "N/A"
1486
+
1487
+ if a == nil {
1488
+ status = "Deleted"
1489
+ state = checklist .Ready
1490
+ } else if string (a .Status .Health .Status ) != "" {
1491
+ status = string (a .Status .Health .Status )
1492
+ }
1493
+
1494
+ return state , []string {name , status }
1495
+ }
1496
+
1375
1497
func deleteRuntimeFromPlatform (ctx context.Context , opts * RuntimeUninstallOptions ) error {
1376
1498
log .G (ctx ).Infof ("Deleting runtime \" %s\" from the platform" , opts .RuntimeName )
1377
1499
_ , err := cfConfig .NewClient ().V2 ().Runtime ().Delete (ctx , opts .RuntimeName )
@@ -1414,9 +1536,12 @@ func NewRuntimeUpgradeCommand() *cobra.Command {
1414
1536
createAnalyticsReporter (ctx , reporter .UpgradeFlow )
1415
1537
1416
1538
err := runtimeUpgradeCommandPreRunHandler (cmd , args , & opts )
1417
- handleCliStep (reporter .UpgradePhasePreCheckFinish , "Finished pre installation checks" , err , false )
1539
+ handleCliStep (reporter .UpgradePhasePreCheckFinish , "Finished pre run checks" , err , false )
1418
1540
if err != nil {
1419
- return fmt .Errorf ("Pre installation error: %w" , err )
1541
+ if errors .Is (err , promptui .ErrInterrupt ) {
1542
+ return fmt .Errorf ("upgrade canceled by user" )
1543
+ }
1544
+ return fmt .Errorf ("Pre run error: %w" , err )
1420
1545
}
1421
1546
1422
1547
finalParameters = map [string ]string {
0 commit comments