Skip to content
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
5 changes: 5 additions & 0 deletions changelog/fragments/optional-flags-cleanup.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
entries:
- description: >
Added new optional flags `--delete-all`, `--delete-crds` and `--delete-operator-groups` to the cleanup command
kind: "addition"
breaking: false
4 changes: 2 additions & 2 deletions internal/cmd/operator-sdk/cleanup/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
func NewCmd() *cobra.Command {
var timeout time.Duration
cfg := &operator.Configuration{}
u := operator.NewUninstall(cfg)
cmd := &cobra.Command{
Use: "cleanup <operatorPackageName>",
Short: "Clean up an Operator deployed with the 'run' subcommand",
Expand All @@ -37,9 +38,7 @@ func NewCmd() *cobra.Command {
return cfg.Load()
},
Run: func(cmd *cobra.Command, args []string) {
u := operator.NewUninstall(cfg)
u.Package = args[0]
u.DeleteAll = true
u.DeleteOperatorGroupNames = []string{operator.SDKOperatorGroupName}
u.Logf = log.Infof

Expand All @@ -60,6 +59,7 @@ func NewCmd() *cobra.Command {
}
cmd.Flags().DurationVar(&timeout, "timeout", 2*time.Minute, "Time to wait for the command to complete before failing")
cfg.BindFlags(cmd.PersistentFlags())
u.BindFlags(cmd.Flags())

return cmd
}
15 changes: 15 additions & 0 deletions internal/olm/operator/uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (

v1 "github.com/operator-framework/api/pkg/operators/v1"
"github.com/operator-framework/api/pkg/operators/v1alpha1"
log "github.com/sirupsen/logrus"
"github.com/spf13/pflag"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime/schema"
Expand Down Expand Up @@ -53,6 +55,12 @@ func NewUninstall(cfg *Configuration) *Uninstall {
}
}

func (u *Uninstall) BindFlags(fs *pflag.FlagSet) {
fs.BoolVar(&u.DeleteCRDs, "delete-crds", false, "If set to true, owned CRDs and CRs will be deleted")
fs.BoolVar(&u.DeleteAll, "delete-all", true, "If set to true, all other delete options will be enabled")
fs.BoolVar(&u.DeleteOperatorGroups, "delete-operator-groups", false, "If set to true, operator groups will be deleted")
}

type ErrPackageNotFound struct {
PackageName string
}
Expand Down Expand Up @@ -143,9 +151,14 @@ func (u *Uninstall) Run(ctx context.Context) error {
return err
}
var objs []client.Object

if u.DeleteCRDs {
objs = append(objs, crds...)
} else {
log.Info("Skipping CRD deletion")

}

objs = append(objs, csvObj, csObj)
// These objects may have owned resources/finalizers, so block on deletion.
if err := u.deleteObjects(ctx, true, objs...); err != nil {
Expand All @@ -158,6 +171,8 @@ func (u *Uninstall) Run(ctx context.Context) error {
if err := u.deleteOperatorGroup(ctx); err != nil {
return err
}
} else {
log.Info("Skipping Operator Groups deletion")
}

// If no objects were cleaned up, the package was not found.
Expand Down
11 changes: 7 additions & 4 deletions website/content/en/docs/cli/operator-sdk_cleanup.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@ operator-sdk cleanup <operatorPackageName> [flags]
### Options

```
-h, --help help for cleanup
--kubeconfig string Path to the kubeconfig file to use for CLI requests.
-n, --namespace string If present, namespace scope for this CLI request
--timeout duration Time to wait for the command to complete before failing (default 2m0s)
--delete-all If set to true, all other delete options will be enabled (default true)
--delete-crds If set to true, owned CRDs and CRs will be deleted
--delete-operator-groups If set to true, operator groups will be deleted
-h, --help help for cleanup
--kubeconfig string Path to the kubeconfig file to use for CLI requests.
-n, --namespace string If present, namespace scope for this CLI request
--timeout duration Time to wait for the command to complete before failing (default 2m0s)
```

### Options inherited from parent commands
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ Let's look at the anatomy of the `run bundle-upgrade` configuration model:
`run packagemanifests`.

```
operator-sdk cleanup <operatorPackageName> [--kubeconfig=] [--namespace=] [--timeout=]
operator-sdk cleanup <operatorPackageName> [--delete-all=] [--delete-crds=] [--delete-operator-groups=] [--kubeconfig=] [--namespace=] [--timeout=]
```

Let's look at the configuration shared between `run bundle`, `run
Expand All @@ -141,6 +141,13 @@ Let's look at the anatomy of the `cleanup` configuration model:

- **operatorPackageName**: the Operator's package name which you want to remove
from the cluster, e.g. memcached-operator. This is a required parameter.
- **delete-all**: a boolean indicating to enable all the delete flags that are present. This is an optional
field which will default to true if not provided. If set to true, it will enable all the delete flags to be true. If set to false, it will enable specific delete flags.
- **delete-crds**: a boolean indicating to delete all owned CRDs and CRs. This is an optional field
which will default to false if not provided. If set to true, owned CRDs and CRs
will be deleted.
- **delete-operator-groups**: a boolean indicating to delete all operator groups. This is an optional field
which will default to false if not provided. If set to true, operator groups will be deleted.

### Caveats

Expand Down