Skip to content
This repository has been archived by the owner on Mar 16, 2024. It is now read-only.

Commit

Permalink
Refactor rm
Browse files Browse the repository at this point in the history
Signed-off-by: Darren Shepherd <[email protected]>
  • Loading branch information
ibuildthecloud committed Jul 21, 2023
1 parent 95a93bc commit 42df272
Show file tree
Hide file tree
Showing 32 changed files with 122 additions and 655 deletions.
2 changes: 1 addition & 1 deletion docs/docs/100-reference/01-command-line/acorn.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ acorn [flags]
* [acorn pull](acorn_pull.md) - Pull an image from a remote registry
* [acorn push](acorn_push.md) - Push an image to a remote registry
* [acorn render](acorn_render.md) - Evaluate and display an Acornfile with args
* [acorn rm](acorn_rm.md) - Delete an app, container, secret or volume
* [acorn rm](acorn_rm.md) - Delete an acorn, optionally with it's associated secrets and volumes
* [acorn run](acorn_run.md) - Run an app from an image or Acornfile
* [acorn secret](acorn_secret.md) - Manage secrets
* [acorn start](acorn_start.md) - Start an app
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/100-reference/01-command-line/acorn_container.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ title: "acorn container"
Manage containers

```
acorn container [flags] [APP_NAME|CONTAINER_NAME...]
acorn container [flags] [ACORN_NAME|CONTAINER_NAME...]
```

### Examples
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/100-reference/01-command-line/acorn_exec.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Run a command in a container
Run a command in a container

```
acorn exec [flags] APP_NAME|CONTAINER_NAME CMD
acorn exec [flags] ACORN_NAME|CONTAINER_NAME CMD
```

### Options
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/100-reference/01-command-line/acorn_logs.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ title: "acorn logs"
Log all workloads from an app

```
acorn logs [flags] [APP_NAME|CONTAINER_REPLICA_NAME]
acorn logs [flags] [ACORN_NAME|CONTAINER_REPLICA_NAME]
```

### Options
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Forward a container port locally
Forward a container port locally

```
acorn port-forward [flags] APP_NAME|CONTAINER_NAME PORT
acorn port-forward [flags] ACORN_NAME|CONTAINER_NAME PORT
```

### Options
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/100-reference/01-command-line/acorn_ps.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ title: "acorn ps"
List or get apps

```
acorn ps [flags] [APP_NAME...]
acorn ps [flags] [ACORN_NAME...]
```

### Examples
Expand Down
17 changes: 9 additions & 8 deletions docs/docs/100-reference/01-command-line/acorn_rm.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,29 @@ title: "acorn rm"
---
## acorn rm

Delete an app, container, secret or volume
Delete an acorn, optionally with it's associated secrets and volumes

```
acorn rm [flags] APP_NAME [APP_NAME...]
acorn rm [flags] ACORN_NAME [ACORN_NAME...]
```

### Examples

```
acorn rm APP_NAME
acorn rm -t volume,container APP_NAME
acorn rm ACORN_NAME
acorn rm --volumes --secrets ACORN_NAME
```

### Options

```
-a, --all Delete all types
-f, --force Force Delete
-a, --all Delete all associated resources (volumes, secrets)
-f, --force Do not prompt for delete
-h, --help help for rm
--ignore-cleanup Ignore delete jobs
-t, --type strings Delete by type (container,app,volume,secret or c,a,v,s)
--ignore-cleanup Delete acorns without running delete jobs
-s, --secrets Delete acorn and associated secrets
-v, --volumes Delete acorn and associated volumes
```

### Options inherited from parent commands
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/100-reference/01-command-line/acorn_start.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ title: "acorn start"
Start an app

```
acorn start [flags] [APP_NAME...]
acorn start [flags] [ACORN_NAME...]
```

### Examples
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/100-reference/01-command-line/acorn_stop.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ title: "acorn stop"
Stop an app

```
acorn stop [flags] [APP_NAME...]
acorn stop [flags] [ACORN_NAME...]
```

### Examples
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/100-reference/01-command-line/acorn_update.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ title: "acorn update"
Update a deployed Acorn

```
acorn update [flags] APP_NAME [deploy flags]
acorn update [flags] ACORN_NAME [deploy flags]
```

### Examples
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/100-reference/01-command-line/acorn_wait.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ title: "acorn wait"
Wait an app to be ready then exit with status code 0

```
acorn wait [flags] APP_NAME
acorn wait [flags] ACORN_NAME
```

### Options
Expand Down
2 changes: 1 addition & 1 deletion pkg/cli/all.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type All struct {
func (a *All) Run(cmd *cobra.Command, args []string) error {
if !a.Quiet {
fmt.Println("")
fmt.Println("APPS:")
fmt.Println("ACORNS:")
}
ps := &Ps{
Quiet: a.Quiet,
Expand Down
2 changes: 1 addition & 1 deletion pkg/cli/apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var (
func NewApiServer(c CommandContext) *cobra.Command {
api := &APIServer{client: c.ClientFactory}
cmd := cli.Command(api, cobra.Command{
Use: "api-server [flags] [APP_NAME...]",
Use: "api-server [flags] [ACORN_NAME...]",
SilenceUsage: true,
Short: "Run api-server",
Hidden: true,
Expand Down
2 changes: 1 addition & 1 deletion pkg/cli/containers.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

func NewContainer(c CommandContext) *cobra.Command {
cmd := cli.Command(&Container{client: c.ClientFactory}, cobra.Command{
Use: "container [flags] [APP_NAME|CONTAINER_NAME...]",
Use: "container [flags] [ACORN_NAME|CONTAINER_NAME...]",
Aliases: []string{"containers", "c"},
Example: `
acorn containers`,
Expand Down
10 changes: 5 additions & 5 deletions pkg/cli/containers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func TestContainer(t *testing.T) {
client: mClient,
},
wantErr: false,
wantOut: "NAME APP IMAGE STATE RESTARTCOUNT CREATED MESSAGE\nfound.container1 0 10y ago \n",
wantOut: "NAME ACORN IMAGE STATE RESTARTCOUNT CREATED MESSAGE\nfound.container1 0 10y ago \n",
},
{
name: "acorn container -a", fields: fields{
Expand All @@ -138,7 +138,7 @@ func TestContainer(t *testing.T) {
client: mClient,
},
wantErr: false,
wantOut: "NAME APP IMAGE STATE RESTARTCOUNT CREATED MESSAGE\nfound.container1 0 10y ago \nfound.container2 stopped 0 10y ago \n",
wantOut: "NAME ACORN IMAGE STATE RESTARTCOUNT CREATED MESSAGE\nfound.container1 0 10y ago \nfound.container2 stopped 0 10y ago \n",
},
{
name: "acorn container found.container1", fields: fields{
Expand All @@ -159,7 +159,7 @@ func TestContainer(t *testing.T) {
client: mClient,
},
wantErr: false,
wantOut: "NAME APP IMAGE STATE RESTARTCOUNT CREATED MESSAGE\nfound.container1 0 10y ago \n",
wantOut: "NAME ACORN IMAGE STATE RESTARTCOUNT CREATED MESSAGE\nfound.container1 0 10y ago \n",
},
{
name: "acorn container found", fields: fields{
Expand All @@ -180,7 +180,7 @@ func TestContainer(t *testing.T) {
client: mClient,
},
wantErr: false,
wantOut: "NAME APP IMAGE STATE RESTARTCOUNT CREATED MESSAGE\nfound.container1 0 10y ago \n",
wantOut: "NAME ACORN IMAGE STATE RESTARTCOUNT CREATED MESSAGE\nfound.container1 0 10y ago \n",
},
{
name: "acorn container found -a", fields: fields{
Expand All @@ -201,7 +201,7 @@ func TestContainer(t *testing.T) {
client: mClient,
},
wantErr: false,
wantOut: "NAME APP IMAGE STATE RESTARTCOUNT CREATED MESSAGE\nfound.container1 0 10y ago \nfound.container2 stopped 0 10y ago \n",
wantOut: "NAME ACORN IMAGE STATE RESTARTCOUNT CREATED MESSAGE\nfound.container1 0 10y ago \nfound.container2 stopped 0 10y ago \n",
},
{
name: "acorn container kill found.container1", fields: fields{
Expand Down
2 changes: 1 addition & 1 deletion pkg/cli/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
func NewExec(c CommandContext) *cobra.Command {
exec := &Exec{client: c.ClientFactory}
cmd := cli.Command(exec, cobra.Command{
Use: "exec [flags] APP_NAME|CONTAINER_NAME CMD",
Use: "exec [flags] ACORN_NAME|CONTAINER_NAME CMD",
SilenceUsage: true,
Short: "Run a command in a container",
Long: "Run a command in a container",
Expand Down
2 changes: 1 addition & 1 deletion pkg/cli/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
func NewLogs(c CommandContext) *cobra.Command {
logs := &Logs{client: c.ClientFactory}
return cli.Command(logs, cobra.Command{
Use: "logs [flags] [APP_NAME|CONTAINER_REPLICA_NAME]",
Use: "logs [flags] [ACORN_NAME|CONTAINER_REPLICA_NAME]",
SilenceUsage: true,
Short: "Log all workloads from an app",
Args: cobra.MaximumNArgs(1),
Expand Down
2 changes: 1 addition & 1 deletion pkg/cli/port_forward.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
func NewPortForward(c CommandContext) *cobra.Command {
exec := &PortForward{client: c.ClientFactory}
cmd := cli.Command(exec, cobra.Command{
Use: "port-forward [flags] APP_NAME|CONTAINER_NAME PORT",
Use: "port-forward [flags] ACORN_NAME|CONTAINER_NAME PORT",
SilenceUsage: true,
Short: "Forward a container port locally",
Long: "Forward a container port locally",
Expand Down
2 changes: 1 addition & 1 deletion pkg/cli/ps.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

func NewPs(c CommandContext) *cobra.Command {
return cli.Command(&Ps{client: c.ClientFactory}, cobra.Command{
Use: "ps [flags] [APP_NAME...]",
Use: "ps [flags] [ACORN_NAME...]",
Aliases: []string{"app", "apps", "a"},
Example: `
acorn ps`,
Expand Down
60 changes: 16 additions & 44 deletions pkg/cli/rm.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,77 +7,49 @@ import (

func NewRm(c CommandContext) *cobra.Command {
return cli.Command(&Rm{client: c.ClientFactory}, cobra.Command{
Use: "rm [flags] APP_NAME [APP_NAME...]",
Use: "rm [flags] ACORN_NAME [ACORN_NAME...]",
Example: `
acorn rm APP_NAME
acorn rm -t volume,container APP_NAME`,
acorn rm ACORN_NAME
acorn rm --volumes --secrets ACORN_NAME`,
SilenceUsage: true,
Short: "Delete an app, container, secret or volume",
Short: "Delete an acorn, optionally with it's associated secrets and volumes",
ValidArgsFunction: newCompletion(c.ClientFactory, appsCompletion).complete,
Args: cobra.MinimumNArgs(1),
})
}

type Rm struct {
All bool `usage:"Delete all types" short:"a"`
Type []string `usage:"Delete by type (container,app,volume,secret or c,a,v,s)" short:"t"`
Force bool `usage:"Force Delete" short:"f"`
IgnoreCleanup bool `usage:"Ignore delete jobs"`
All bool `usage:"Delete all associated resources (volumes, secrets)" short:"a"`
Volumes bool `usage:"Delete acorn and associated volumes" short:"v"`
Secrets bool `usage:"Delete acorn and associated secrets" short:"s"`
Force bool `usage:"Do not prompt for delete" short:"f"`
IgnoreCleanup bool `usage:"Delete acorns without running delete jobs"`
client ClientFactory
}
type RmObjects struct {
App bool
Container bool
Secret bool
Volume bool
}

func (a *Rm) Run(cmd *cobra.Command, args []string) error {
var rmObjects RmObjects

c, err := a.client.CreateDefault()
if err != nil {
return err
}

if a.All {
rmObjects = RmObjects{
App: true,
Secret: true,
Volume: true,
}
} else if len(a.Type) > 0 {
for _, obj := range a.Type {
addRmObject(&rmObjects, obj)
}
} else { // If nothing is set default to App
rmObjects = RmObjects{
App: true,
}
a.Volumes = true
a.Secrets = true
}
// Do not prompt when deleting non-nested resource
a.Force = a.Force || rmObjects.App && !rmObjects.Secret && !rmObjects.Volume

for _, arg := range args {
if rmObjects.App {
err := removeApp(arg, c, cmd, a.Force, a.IgnoreCleanup, rmObjects.Container || rmObjects.Volume || rmObjects.Secret)
if err != nil {
return err
}
}
if rmObjects.Container {
err := removeContainer(arg, c, cmd, a.Force)
if err != nil {
return err
}
err := removeAcorn(cmd.Context(), c, arg, a.IgnoreCleanup, a.Volumes || a.Secrets)
if err != nil {
return err
}
if rmObjects.Volume {
if a.Volumes {
err := removeVolume(arg, c, cmd, a.Force)
if err != nil {
return err
}
}
if rmObjects.Secret {
if a.Secrets {
err := removeSecret(arg, c, cmd, a.Force)
if err != nil {
return err
Expand Down
Loading

0 comments on commit 42df272

Please sign in to comment.