Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add delete backup cmd using finalizer and simplify GC process #252

Merged
merged 3 commits into from
Jan 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions docs/cli-reference/ark.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ operations can also be performed as 'ark backup get' and 'ark schedule create'.
### SEE ALSO
* [ark backup](ark_backup.md) - Work with backups
* [ark create](ark_create.md) - Create ark resources
* [ark delete](ark_delete.md) - Delete ark resources
* [ark describe](ark_describe.md) - Describe ark resources
* [ark get](ark_get.md) - Get ark resources
* [ark plugin](ark_plugin.md) - Work with plugins
Expand Down
1 change: 1 addition & 0 deletions docs/cli-reference/ark_backup.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Work with backups
### SEE ALSO
* [ark](ark.md) - Back up and restore Kubernetes cluster resources.
* [ark backup create](ark_backup_create.md) - Create a backup
* [ark backup delete](ark_backup_delete.md) - Delete a backup
* [ark backup describe](ark_backup_describe.md) - Describe backups
* [ark backup download](ark_backup_download.md) - Download a backup
* [ark backup get](ark_backup_get.md) - Get backups
Expand Down
35 changes: 35 additions & 0 deletions docs/cli-reference/ark_backup_delete.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
## ark backup delete

Delete a backup

### Synopsis


Delete a backup

```
ark backup delete NAME [flags]
```

### Options

```
-h, --help help for delete
```

### Options inherited from parent commands

```
--alsologtostderr log to standard error as well as files
--kubeconfig string Path to the kubeconfig file to use to talk to the Kubernetes apiserver. If unset, try the environment variable KUBECONFIG, as well as in-cluster configuration
--log_backtrace_at traceLocation when logging hits line file:N, emit a stack trace (default :0)
--log_dir string If non-empty, write log files in this directory
--logtostderr log to standard error instead of files
--stderrthreshold severity logs at or above this threshold go to stderr (default 2)
-v, --v Level log level for V logs
--vmodule moduleSpec comma-separated list of pattern=N settings for file-filtered logging
```

### SEE ALSO
* [ark backup](ark_backup.md) - Work with backups

34 changes: 34 additions & 0 deletions docs/cli-reference/ark_delete.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
## ark delete

Delete ark resources

### Synopsis


Delete ark resources

### Options

```
-h, --help help for delete
```

### Options inherited from parent commands

```
--alsologtostderr log to standard error as well as files
--kubeconfig string Path to the kubeconfig file to use to talk to the Kubernetes apiserver. If unset, try the environment variable KUBECONFIG, as well as in-cluster configuration
--log_backtrace_at traceLocation when logging hits line file:N, emit a stack trace (default :0)
--log_dir string If non-empty, write log files in this directory
--logtostderr log to standard error instead of files
--stderrthreshold severity logs at or above this threshold go to stderr (default 2)
-v, --v Level log level for V logs
--vmodule moduleSpec comma-separated list of pattern=N settings for file-filtered logging
```

### SEE ALSO
* [ark](ark.md) - Back up and restore Kubernetes cluster resources.
* [ark delete backup](ark_delete_backup.md) - Delete a backup
* [ark delete restore](ark_delete_restore.md) - Delete a restore
* [ark delete schedule](ark_delete_schedule.md) - Delete a schedule

35 changes: 35 additions & 0 deletions docs/cli-reference/ark_delete_backup.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
## ark delete backup

Delete a backup

### Synopsis


Delete a backup

```
ark delete backup NAME [flags]
```

### Options

```
-h, --help help for backup
```

### Options inherited from parent commands

```
--alsologtostderr log to standard error as well as files
--kubeconfig string Path to the kubeconfig file to use to talk to the Kubernetes apiserver. If unset, try the environment variable KUBECONFIG, as well as in-cluster configuration
--log_backtrace_at traceLocation when logging hits line file:N, emit a stack trace (default :0)
--log_dir string If non-empty, write log files in this directory
--logtostderr log to standard error instead of files
--stderrthreshold severity logs at or above this threshold go to stderr (default 2)
-v, --v Level log level for V logs
--vmodule moduleSpec comma-separated list of pattern=N settings for file-filtered logging
```

### SEE ALSO
* [ark delete](ark_delete.md) - Delete ark resources

35 changes: 35 additions & 0 deletions docs/cli-reference/ark_delete_restore.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
## ark delete restore

Delete a restore

### Synopsis


Delete a restore

```
ark delete restore NAME [flags]
```

### Options

```
-h, --help help for restore
```

### Options inherited from parent commands

```
--alsologtostderr log to standard error as well as files
--kubeconfig string Path to the kubeconfig file to use to talk to the Kubernetes apiserver. If unset, try the environment variable KUBECONFIG, as well as in-cluster configuration
--log_backtrace_at traceLocation when logging hits line file:N, emit a stack trace (default :0)
--log_dir string If non-empty, write log files in this directory
--logtostderr log to standard error instead of files
--stderrthreshold severity logs at or above this threshold go to stderr (default 2)
-v, --v Level log level for V logs
--vmodule moduleSpec comma-separated list of pattern=N settings for file-filtered logging
```

### SEE ALSO
* [ark delete](ark_delete.md) - Delete ark resources

35 changes: 35 additions & 0 deletions docs/cli-reference/ark_delete_schedule.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
## ark delete schedule

Delete a schedule

### Synopsis


Delete a schedule

```
ark delete schedule NAME [flags]
```

### Options

```
-h, --help help for schedule
```

### Options inherited from parent commands

```
--alsologtostderr log to standard error as well as files
--kubeconfig string Path to the kubeconfig file to use to talk to the Kubernetes apiserver. If unset, try the environment variable KUBECONFIG, as well as in-cluster configuration
--log_backtrace_at traceLocation when logging hits line file:N, emit a stack trace (default :0)
--log_dir string If non-empty, write log files in this directory
--logtostderr log to standard error instead of files
--stderrthreshold severity logs at or above this threshold go to stderr (default 2)
-v, --v Level log level for V logs
--vmodule moduleSpec comma-separated list of pattern=N settings for file-filtered logging
```

### SEE ALSO
* [ark delete](ark_delete.md) - Delete ark resources

2 changes: 2 additions & 0 deletions pkg/cmd/ark/ark.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/heptio/ark/pkg/client"
"github.com/heptio/ark/pkg/cmd/cli/backup"
"github.com/heptio/ark/pkg/cmd/cli/create"
"github.com/heptio/ark/pkg/cmd/cli/delete"
"github.com/heptio/ark/pkg/cmd/cli/describe"
"github.com/heptio/ark/pkg/cmd/cli/get"
"github.com/heptio/ark/pkg/cmd/cli/plugin"
Expand Down Expand Up @@ -61,6 +62,7 @@ operations can also be performed as 'ark backup get' and 'ark schedule create'.`
create.NewCommand(f),
runplugin.NewCommand(),
plugin.NewCommand(f),
delete.NewCommand(f),
)

// add the glog flags
Expand Down
5 changes: 1 addition & 4 deletions pkg/cmd/cli/backup/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,7 @@ func NewCommand(f client.Factory) *cobra.Command {
NewLogsCommand(f),
NewDescribeCommand(f, "describe"),
NewDownloadCommand(f),

// If you delete a backup and it still exists in object storage, the backup sync controller will
// recreate it. Until we have a good UX around this, we're disabling the delete command.
// NewDeleteCommand(f),
NewDeleteCommand(f, "delete"),
)

return c
Expand Down
17 changes: 15 additions & 2 deletions pkg/cmd/cli/backup/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,36 @@ import (
"fmt"
"os"

"github.com/pkg/errors"
"github.com/spf13/cobra"

api "github.com/heptio/ark/pkg/apis/ark/v1"
"github.com/heptio/ark/pkg/client"
"github.com/heptio/ark/pkg/cmd"
"github.com/heptio/ark/pkg/controller"
kubeutil "github.com/heptio/ark/pkg/util/kube"
)

func NewDeleteCommand(f client.Factory) *cobra.Command {
func NewDeleteCommand(f client.Factory, use string) *cobra.Command {
c := &cobra.Command{
Use: "delete NAME",
Use: fmt.Sprintf("%s NAME", use),
Short: "Delete a backup",
Run: func(c *cobra.Command, args []string) {
if len(args) != 1 {
c.Usage()
os.Exit(1)
}

kubeClient, err := f.KubeClient()
cmd.CheckError(err)

serverVersion, err := kubeutil.ServerVersion(kubeClient.Discovery())
cmd.CheckError(err)

if !serverVersion.AtLeast(controller.MinVersionForDelete) {
cmd.CheckError(errors.Errorf("this command requires the Kubernetes server version to be at least %s", controller.MinVersionForDelete))
}

arkClient, err := f.Client()
cmd.CheckError(err)

Expand Down
51 changes: 51 additions & 0 deletions pkg/cmd/cli/delete/delete.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
Copyright 2017 the Heptio Ark contributors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package delete

import (
"github.com/spf13/cobra"

"github.com/heptio/ark/pkg/client"
"github.com/heptio/ark/pkg/cmd/cli/backup"
"github.com/heptio/ark/pkg/cmd/cli/restore"
"github.com/heptio/ark/pkg/cmd/cli/schedule"
)

func NewCommand(f client.Factory) *cobra.Command {
c := &cobra.Command{
Use: "delete",
Short: "Delete ark resources",
Long: "Delete ark resources",
}

backupCommand := backup.NewDeleteCommand(f, "backup")
backupCommand.Aliases = []string{"backups"}

restoreCommand := restore.NewDeleteCommand(f, "restore")
restoreCommand.Aliases = []string{"restores"}

scheduleCommand := schedule.NewDeleteCommand(f, "schedule")
scheduleCommand.Aliases = []string{"schedules"}

c.AddCommand(
backupCommand,
restoreCommand,
scheduleCommand,
)

return c
}
4 changes: 2 additions & 2 deletions pkg/cmd/cli/restore/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ import (
"github.com/heptio/ark/pkg/cmd"
)

func NewDeleteCommand(f client.Factory) *cobra.Command {
func NewDeleteCommand(f client.Factory, use string) *cobra.Command {
c := &cobra.Command{
Use: "delete NAME",
Use: fmt.Sprintf("%s NAME", use),
Short: "Delete a restore",
Run: func(c *cobra.Command, args []string) {
if len(args) != 1 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/cli/restore/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func NewCommand(f client.Factory) *cobra.Command {
NewGetCommand(f, "get"),
NewLogsCommand(f),
NewDescribeCommand(f, "describe"),
NewDeleteCommand(f),
NewDeleteCommand(f, "delete"),
)

return c
Expand Down
4 changes: 2 additions & 2 deletions pkg/cmd/cli/schedule/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ import (
"github.com/heptio/ark/pkg/cmd"
)

func NewDeleteCommand(f client.Factory) *cobra.Command {
func NewDeleteCommand(f client.Factory, use string) *cobra.Command {
c := &cobra.Command{
Use: "delete NAME",
Use: fmt.Sprintf("%s NAME", use),
Short: "Delete a schedule",
Run: func(c *cobra.Command, args []string) {
if len(args) != 1 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/cli/schedule/schedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func NewCommand(f client.Factory) *cobra.Command {
NewCreateCommand(f, "create"),
NewGetCommand(f, "get"),
NewDescribeCommand(f, "describe"),
NewDeleteCommand(f),
NewDeleteCommand(f, "delete"),
)

return c
Expand Down
Loading