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

feat: add --purge-namespace flags for karmadactl deinit, and default not delete namespace #3326

Merged
merged 1 commit into from
Apr 6, 2023
Merged
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
21 changes: 12 additions & 9 deletions pkg/karmadactl/deinit/deinit.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ type CommandDeInitOption struct {
Namespace string

// DryRun tells if run the command in dry-run mode, without making any server requests.
DryRun bool
Force bool
DryRun bool
Force bool
PurgeNamespace bool

KubeClientSet *kubernetes.Clientset
}
Expand Down Expand Up @@ -81,6 +82,7 @@ func NewCmdDeInit(parentCommand string) *cobra.Command {
flags.StringVar(&opts.Context, "context", "", "The name of the kubeconfig context to use")
flags.BoolVar(&opts.DryRun, "dry-run", false, "Run the command in dry-run mode, without making any server requests.")
flags.BoolVarP(&opts.Force, "force", "f", false, "Reset cluster without prompting for confirmation.")
flags.BoolVar(&opts.PurgeNamespace, "purge-namespace", false, "Run the command with purge-namespace, the namespace which Karmada components were installed will be deleted.")
return cmd
}

Expand Down Expand Up @@ -143,14 +145,15 @@ func (o *CommandDeInitOption) delete() error {
}

// Delete namespace where Karmada components are installed
fmt.Printf("delete Namespace %q\n", o.Namespace)
if o.DryRun {
return nil
}
if err = o.KubeClientSet.CoreV1().Namespaces().Delete(context.Background(), o.Namespace, metav1.DeleteOptions{}); err != nil {
return err
if o.PurgeNamespace {
fmt.Printf("delete Namespace %q\n", o.Namespace)
if o.DryRun {
return nil
}
if err = o.KubeClientSet.CoreV1().Namespaces().Delete(context.Background(), o.Namespace, metav1.DeleteOptions{}); err != nil {
return err
}
}

return nil
}

Expand Down