Skip to content

Commit

Permalink
Fix #68 avoid deleting namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
guymguym committed Oct 3, 2019
1 parent 4d311d2 commit cc797f7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
8 changes: 4 additions & 4 deletions pkg/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func CmdUninstall() *cobra.Command {
Short: "Uninstall the operator and delete the system",
Run: RunUninstall,
}
cmd.Flags().Bool("crd", false, "Enable deletion of CRD's")
cmd.Flags().Bool("cleanup", false, "Enable deletion of Namespace and CRD's")
return cmd
}

Expand Down Expand Up @@ -79,12 +79,12 @@ func RunUninstall(cmd *cobra.Command, args []string) {
log.Printf("Operator Delete:")
operator.RunUninstall(cmd, args)
log.Printf("")
crdDelete, _ := cmd.Flags().GetBool("crd")
if crdDelete {
cleanup, _ := cmd.Flags().GetBool("cleanup")
if cleanup {
log.Printf("CRD Delete:")
crd.RunDelete(cmd, args)
} else {
log.Printf("CRD Delete: currently disabled (enable with \"--crd\")")
log.Printf("CRD Delete: currently disabled (enable with \"--cleanup\")")
log.Printf("CRD Status:")
crd.RunStatus(cmd, args)
}
Expand Down
21 changes: 20 additions & 1 deletion pkg/operator/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package operator

import (
"os"
"strings"

"github.com/noobaa/noobaa-operator/v2/build/_output/bundle"
"github.com/noobaa/noobaa-operator/v2/pkg/options"
Expand Down Expand Up @@ -48,6 +49,7 @@ func CmdUninstall() *cobra.Command {
Short: "Uninstall noobaa-operator",
Run: RunUninstall,
}
cmd.Flags().Bool("cleanup", false, "Enable deletion of the Namespace")
return cmd
}

Expand Down Expand Up @@ -108,7 +110,24 @@ func RunUninstall(cmd *cobra.Command, args []string) {
util.KubeDelete(c.RoleBinding)
util.KubeDelete(c.Role)
util.KubeDelete(c.SA)
util.KubeDelete(c.NS)

cleanup, _ := cmd.Flags().GetBool("cleanup")
reservedNS := c.NS.Name == "default" ||
strings.HasPrefix(c.NS.Name, "openshift-") ||
strings.HasPrefix(c.NS.Name, "kubernetes-") ||
strings.HasPrefix(c.NS.Name, "kube-")
if reservedNS {
log.Printf("Namespace Delete: disabled for reserved namespace")
log.Printf("Namespace Status:")
util.KubeCheck(c.NS)
} else if !cleanup {
log.Printf("Namespace Delete: currently disabled (enable with \"--cleanup\")")
log.Printf("Namespace Status:")
util.KubeCheck(c.NS)
} else {
log.Printf("Namespace Delete:")
util.KubeDelete(c.NS)
}
}

// RunStatus runs a CLI command
Expand Down

0 comments on commit cc797f7

Please sign in to comment.