Skip to content

Commit

Permalink
Allow to retain namespace while operator deletion (#1807)
Browse files Browse the repository at this point in the history
Using a command line flag `--retain-namespace` under command
`kubectl minio delete` it would retain the namespace and delete
all other resources.

Signed-off-by: Shubhendu Ram Tripathi <shubhendu@minio.io>
  • Loading branch information
shtripat authored Oct 16, 2023
1 parent 47106d6 commit 61bb830
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions kubectl-minio/cmd/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type deleteCmd struct {
operatorOpts resources.OperatorOptions
force bool
dangerous bool
retainNS bool
}

func newDeleteCmd(out io.Writer, errOut io.Writer) *cobra.Command {
Expand Down Expand Up @@ -82,6 +83,7 @@ func newDeleteCmd(out io.Writer, errOut io.Writer) *cobra.Command {
f.StringVarP(&o.operatorOpts.Namespace, "namespace", "n", helpers.DefaultNamespace, "namespace scope for this request")
f.BoolVarP(&o.force, "force", "f", false, "allow without confirmation")
f.BoolVarP(&o.dangerous, "dangerous", "d", false, "confirm deletion")
f.BoolVarP(&o.retainNS, "retain-namespace", "r", false, "retain operator namespace")
return cmd
}

Expand Down Expand Up @@ -133,6 +135,18 @@ func (o *deleteCmd) run(writer io.Writer) error {
return err
}

// Retain namespace if flag passed
if o.retainNS {
resources := m.Resources()
m.Clear()
for _, res := range resources {
if res.GetName() == o.operatorOpts.Namespace && res.GetKind() == "Namespace" {
continue
}
m.Append(res)
}
}

yml, err := m.AsYaml()
if err != nil {
return err
Expand Down

0 comments on commit 61bb830

Please sign in to comment.