Initial commit for abra app rm
This commit is contained in:
parent
edaedeac3a
commit
f528cf4cfa
|
@ -4,6 +4,7 @@ import (
|
|||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"coopcloud.tech/abra/cli/internal"
|
||||
"coopcloud.tech/abra/client"
|
||||
|
@ -29,7 +30,6 @@ var appRemoveCommand = &cli.Command{
|
|||
Aliases: []string{"rm", "delete"},
|
||||
Flags: []cli.Flag{
|
||||
VolumesFlag,
|
||||
internal.SecretsFlag,
|
||||
},
|
||||
Action: func(c *cli.Context) error {
|
||||
// Check if app name was provided by user
|
||||
|
@ -59,21 +59,69 @@ var appRemoveCommand = &cli.Command{
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Println(AppPath) //to be replaced by a remove method
|
||||
err = os.Remove(AppPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Check if the app has secrets and remove them too
|
||||
if internal.Secrets {
|
||||
fs := filters.NewArgs()
|
||||
fs.Add("name", AppName)
|
||||
SecretList, err := cl.SecretList(ctx, types.SecretListOptions{Filters: fs})
|
||||
fs := filters.NewArgs()
|
||||
fs.Add("name", AppName)
|
||||
SecretList, err := cl.SecretList(ctx, types.SecretListOptions{Filters: fs})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// TODO: Actually remove secrets
|
||||
Secrets := make(map[string]string)
|
||||
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)
|
||||
//cl.SecretRemove(ctx, cont.ID)
|
||||
}
|
||||
SecretNamesToRemove := []string{}
|
||||
SecretsPrompt := &survey.MultiSelect{
|
||||
Message: "Which secrets do you want to remove?",
|
||||
Options: SecretNames,
|
||||
Default: SecretNames,
|
||||
}
|
||||
survey.AskOne(SecretsPrompt, &SecretNamesToRemove)
|
||||
for _, name := range SecretNamesToRemove {
|
||||
err := cl.SecretRemove(ctx, Secrets[name])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Println(SecretList)
|
||||
// SecretIDsToRemove = append(SecretIDsToRemove, Secrets[name])
|
||||
}
|
||||
|
||||
// Remove the volumes if desired
|
||||
if Volumes == true {
|
||||
VolumeListOKBody, err := cl.VolumeList(ctx, fs)
|
||||
VolumeList := VolumeListOKBody.Volumes
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
Vols := []string{}
|
||||
for _, vol := range VolumeList {
|
||||
Vols = append(Vols, vol.Name)
|
||||
}
|
||||
RemoveVols := []string{}
|
||||
VolumesPrompt := &survey.MultiSelect{
|
||||
Message: "Which volumes do you want to remove?",
|
||||
Options: Vols,
|
||||
Default: Vols,
|
||||
}
|
||||
survey.AskOne(VolumesPrompt, &RemoveVols)
|
||||
fmt.Println("Volumes to remove: ", RemoveVols) //TODO: Replace with a remove method
|
||||
for _, vol := range RemoveVols {
|
||||
err := cl.VolumeRemove(ctx, vol, false) // false is for force removing
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
} else {
|
||||
fmt.Println("Volumes will not be removed")
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue