Merge pull request 'fix: app rm quitting when there are no secrets/volumes to remove' (#56) from knoflook/go-abra:dev into main
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
Reviewed-on: coop-cloud/go-abra#56
This commit is contained in:
commit
97188b57d9
|
@ -65,12 +65,6 @@ var appRemoveCommand = &cli.Command{
|
||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = os.Remove(appPath)
|
|
||||||
if err != nil {
|
|
||||||
logrus.Fatal(err)
|
|
||||||
}
|
|
||||||
logrus.Info(fmt.Sprintf("File: %s removed", appPath))
|
|
||||||
|
|
||||||
fs := filters.NewArgs()
|
fs := filters.NewArgs()
|
||||||
fs.Add("name", appName)
|
fs.Add("name", appName)
|
||||||
secretList, err := cl.SecretList(ctx, types.SecretListOptions{Filters: fs})
|
secretList, err := cl.SecretList(ctx, types.SecretListOptions{Filters: fs})
|
||||||
|
@ -79,35 +73,35 @@ var appRemoveCommand = &cli.Command{
|
||||||
}
|
}
|
||||||
|
|
||||||
secrets := make(map[string]string)
|
secrets := make(map[string]string)
|
||||||
var secretNames []string
|
if len(secrets) > 0 {
|
||||||
|
var secretNames []string
|
||||||
|
|
||||||
for _, cont := range secretList {
|
for _, cont := range secretList {
|
||||||
secrets[cont.Spec.Annotations.Name] = cont.ID // we have to map the names to ID's
|
secrets[cont.Spec.Annotations.Name] = cont.ID // we have to map the names to ID's
|
||||||
secretNames = append(secretNames, cont.Spec.Annotations.Name)
|
secretNames = append(secretNames, cont.Spec.Annotations.Name)
|
||||||
}
|
|
||||||
|
|
||||||
var secretNamesToRemove []string
|
|
||||||
if !internal.Force {
|
|
||||||
secretsPrompt := &survey.MultiSelect{
|
|
||||||
Message: "Which secrets do you want to remove?",
|
|
||||||
Options: secretNames,
|
|
||||||
Default: secretNames,
|
|
||||||
}
|
}
|
||||||
if err := survey.AskOne(secretsPrompt, &secretNamesToRemove); err != nil {
|
|
||||||
logrus.Fatal(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, name := range secretNamesToRemove {
|
var secretNamesToRemove []string
|
||||||
err := cl.SecretRemove(ctx, secrets[name])
|
if !internal.Force {
|
||||||
if err != nil {
|
secretsPrompt := &survey.MultiSelect{
|
||||||
logrus.Fatal(err)
|
Message: "Which secrets do you want to remove?",
|
||||||
|
Options: secretNames,
|
||||||
|
Default: secretNames,
|
||||||
|
}
|
||||||
|
if err := survey.AskOne(secretsPrompt, &secretNamesToRemove); err != nil {
|
||||||
|
logrus.Fatal(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
logrus.Info(fmt.Sprintf("Secret: %s removed", name))
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(secretNamesToRemove) == 0 {
|
for _, name := range secretNamesToRemove {
|
||||||
logrus.Info("No secrets were removed")
|
err := cl.SecretRemove(ctx, secrets[name])
|
||||||
|
if err != nil {
|
||||||
|
logrus.Fatal(err)
|
||||||
|
}
|
||||||
|
logrus.Info(fmt.Sprintf("Secret: %s removed", name))
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
logrus.Info("No secrets to remove")
|
||||||
}
|
}
|
||||||
|
|
||||||
volumeListOKBody, err := cl.VolumeList(ctx, fs)
|
volumeListOKBody, err := cl.VolumeList(ctx, fs)
|
||||||
|
@ -117,33 +111,43 @@ var appRemoveCommand = &cli.Command{
|
||||||
}
|
}
|
||||||
|
|
||||||
var vols []string
|
var vols []string
|
||||||
for _, vol := range volumeList {
|
if len(vols) > 0 {
|
||||||
vols = append(vols, vol.Name)
|
for _, vol := range volumeList {
|
||||||
}
|
vols = append(vols, vol.Name)
|
||||||
|
|
||||||
if Volumes {
|
|
||||||
var removeVols []string
|
|
||||||
if !internal.Force {
|
|
||||||
volumesPrompt := &survey.MultiSelect{
|
|
||||||
Message: "Which volumes do you want to remove?",
|
|
||||||
Options: vols,
|
|
||||||
Default: vols,
|
|
||||||
}
|
|
||||||
if err := survey.AskOne(volumesPrompt, &removeVols); err != nil {
|
|
||||||
logrus.Fatal(err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
for _, vol := range removeVols {
|
|
||||||
err := cl.VolumeRemove(ctx, vol, internal.Force) // last argument is for force removing
|
if Volumes {
|
||||||
if err != nil {
|
var removeVols []string
|
||||||
logrus.Fatal(err)
|
if !internal.Force {
|
||||||
|
volumesPrompt := &survey.MultiSelect{
|
||||||
|
Message: "Which volumes do you want to remove?",
|
||||||
|
Options: vols,
|
||||||
|
Default: vols,
|
||||||
|
}
|
||||||
|
if err := survey.AskOne(volumesPrompt, &removeVols); err != nil {
|
||||||
|
logrus.Fatal(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
logrus.Info(fmt.Sprintf("Volume %s removed", vol))
|
for _, vol := range removeVols {
|
||||||
|
err := cl.VolumeRemove(ctx, vol, internal.Force) // last argument is for force removing
|
||||||
|
if err != nil {
|
||||||
|
logrus.Fatal(err)
|
||||||
|
}
|
||||||
|
logrus.Info(fmt.Sprintf("Volume %s removed", vol))
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
logrus.Info("No volumes were removed")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
logrus.Info("No volumes were removed")
|
logrus.Info("No volumes to remove")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err = os.Remove(appPath)
|
||||||
|
if err != nil {
|
||||||
|
logrus.Fatal(err)
|
||||||
|
}
|
||||||
|
logrus.Info(fmt.Sprintf("File: %s removed", appPath))
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue