From cc249e8187066cb9ce7a15e6ce97e843c953a135 Mon Sep 17 00:00:00 2001 From: decentral1se Date: Sun, 5 Sep 2021 21:54:52 +0200 Subject: [PATCH] fix: check for deployment of app before removing Closes https://git.coopcloud.tech/coop-cloud/go-abra/pulls/61. Fix thanks to @knoflook! --- cli/app/remove.go | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/cli/app/remove.go b/cli/app/remove.go index 4fda2ae1..56d09e6d 100644 --- a/cli/app/remove.go +++ b/cli/app/remove.go @@ -49,7 +49,7 @@ var appRemoveCommand = &cli.Command{ logrus.Fatal(err) } if !response { - return errors.New("User aborted app removal") + logrus.Fatal("User aborted app removal") } } @@ -65,6 +65,16 @@ var appRemoveCommand = &cli.Command{ if err != nil { logrus.Fatal(err) } + if !internal.Force { + // get app status and check if it's deployed + statuses, err := config.GetAppStatuses(appFiles) + if err != nil { + logrus.Fatal(err) + } + if statuses[appName] == "deployed" { + logrus.Fatalf("'%s' is still deployed. Run \"abra app %s undeploy\" or pass --force", appName, appName) + } + } fs := filters.NewArgs() fs.Add("name", appName) @@ -74,14 +84,14 @@ var appRemoveCommand = &cli.Command{ } secrets := make(map[string]string) + var secretNames []string + + for _, cont := range secretList { + secrets[cont.Spec.Annotations.Name] = cont.ID // we have to map the names to ID's + secretNames = append(secretNames, cont.Spec.Annotations.Name) + } + if len(secrets) > 0 { - var secretNames []string - - for _, cont := range secretList { - secrets[cont.Spec.Annotations.Name] = cont.ID // we have to map the names to ID's - secretNames = append(secretNames, cont.Spec.Annotations.Name) - } - var secretNamesToRemove []string if !internal.Force { secretsPrompt := &survey.MultiSelect{ @@ -112,11 +122,11 @@ var appRemoveCommand = &cli.Command{ } var vols []string - if len(vols) > 0 { - for _, vol := range volumeList { - vols = append(vols, vol.Name) - } + for _, vol := range volumeList { + vols = append(vols, vol.Name) + } + if len(vols) > 0 { if Volumes { var removeVols []string if !internal.Force {