Merge pull request #3326 from my-git9/feat/ignorens

feat: add --purge-namespace flags for `karmadactl deinit`, and default not delete namespace
This commit is contained in:
karmada-bot 2023-04-06 20:07:55 +08:00 committed by GitHub
commit 31b5088baf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 9 deletions

View File

@ -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
}
@ -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
}
@ -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 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
}
}
if err = o.KubeClientSet.CoreV1().Namespaces().Delete(context.Background(), o.Namespace, metav1.DeleteOptions{}); err != nil {
return err
}
return nil
}