Add abra app remove command #43

Closed
knoflook wants to merge 7 commits from knoflook:dev into main
Showing only changes of commit f528cf4cfa - Show all commits

View File

@ -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{
knoflook marked this conversation as resolved Outdated

This is a general flag we'll add to other sub-commands, it can live in cli/internal/common.go?

This is a general flag we'll add to other sub-commands, it can live in [cli/internal/common.go](https://git.coopcloud.tech/coop-cloud/go-abra/src/branch/main/cli/internal/common.go)?
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)
decentral1se marked this conversation as resolved Outdated

appFiles, err := config.LoadAppFiles()

`appFiles, err := config.LoadAppFiles()`

Can't do it that way, if you remove "" LoadAppFiles returns an empty map[]

Can't do it that way, if you remove "" LoadAppFiles returns an empty map[]
if err != nil {
return err
knoflook marked this conversation as resolved Outdated

logrus.Fatal(err)

`logrus.Fatal(err)`
}
knoflook marked this conversation as resolved Outdated

appPath := AppFiles[appName].Path

`appPath := AppFiles[appName].Path`
// 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{}
knoflook marked this conversation as resolved
Review
if err != nil {
	logrus.Fatal(err)
}
logrus.Info(fmt.Sprintf("File: %s removed", appPath))
```golang if err != nil { logrus.Fatal(err) } logrus.Info(fmt.Sprintf("File: %s removed", appPath)) ```
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,
}
knoflook marked this conversation as resolved Outdated

logrus.Fatal(err)

`logrus.Fatal(err)`
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,
knoflook marked this conversation as resolved Outdated

Let's remove that 🙃

Let's remove that 🙃
Default: Vols,
}
knoflook marked this conversation as resolved Outdated
if err != nil {
	logrus.Fatal(err)
}
logrus.Info(fmt.Sprintf("Secret: %s removed", name))
```golang if err != nil { logrus.Fatal(err) } logrus.Info(fmt.Sprintf("Secret: %s removed", name)) ```
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")
}
knoflook marked this conversation as resolved
Review

logrus.Fatal(err)

`logrus.Fatal(err)`
return nil
},