From 2c891a95c65b3e68e0afcbefda543b156f44ee68 Mon Sep 17 00:00:00 2001 From: Maruf Tuhin Date: Fri, 9 Mar 2018 16:46:19 +0600 Subject: [PATCH] Remove --force flag (#195) --- docs/reference/kubedb_delete.md | 1 - pkg/cmds/delete.go | 28 ++++------------------------ pkg/util/flags.go | 1 - 3 files changed, 4 insertions(+), 26 deletions(-) diff --git a/docs/reference/kubedb_delete.md b/docs/reference/kubedb_delete.md index 93de3a9de..781203d34 100644 --- a/docs/reference/kubedb_delete.md +++ b/docs/reference/kubedb_delete.md @@ -46,7 +46,6 @@ kubedb delete ([-f FILENAME] | TYPE [(NAME | -l label | --all)]) [flags] ``` --all Delete all resources, including uninitialized ones, in the namespace of the specified resource types. -f, --filename stringSlice Filename to use to delete the resource - --force Immediate deletion of some resources may result in inconsistency or data loss. -h, --help help for delete -n, --namespace string Delete object(s) from this namespace. (default "default") -o, --output string Output mode. Use "-o name" for shorter output (resource/name). diff --git a/pkg/cmds/delete.go b/pkg/cmds/delete.go index d1bab371c..fbabc023c 100644 --- a/pkg/cmds/delete.go +++ b/pkg/cmds/delete.go @@ -11,7 +11,6 @@ import ( "github.com/spf13/cobra" kerr "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/api/meta" - "k8s.io/apimachinery/pkg/types" "k8s.io/kubernetes/pkg/kubectl/cmd/templates" cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util" "k8s.io/kubernetes/pkg/kubectl/resource" @@ -99,7 +98,6 @@ func RunDelete(f cmdutil.Factory, cmd *cobra.Command, out io.Writer, args []stri } func deleteResult(f cmdutil.Factory, cmd *cobra.Command, r *resource.Result, out io.Writer, mapper meta.RESTMapper) error { - forceDeletion := cmdutil.GetFlagBool(cmd, "force") shortOutput := cmdutil.GetFlagString(cmd, "output") == "name" infoList := make([]*resource.Info, 0) @@ -112,10 +110,8 @@ func deleteResult(f cmdutil.Factory, cmd *cobra.Command, r *resource.Result, out return err } - if !forceDeletion { - if err := validator.ValidateDeletion(info); err != nil { - return cmdutil.AddSourceToErr("validating", info.Source, err) - } + if err := validator.ValidateDeletion(info); err != nil { + return cmdutil.AddSourceToErr("validating", info.Source, err) } infoList = append(infoList, info) @@ -132,7 +128,7 @@ func deleteResult(f cmdutil.Factory, cmd *cobra.Command, r *resource.Result, out } for _, info := range infoList { - if err := deleteResource(f, info, out, mapper, shortOutput, forceDeletion); err != nil { + if err := deleteResource(f, info, out, mapper, shortOutput); err != nil { return err } } @@ -140,23 +136,7 @@ func deleteResult(f cmdutil.Factory, cmd *cobra.Command, r *resource.Result, out return nil } -var forceDeletePatch = ` -{ - "metadata":{ - "finalizers":null - } -} -` - -func deleteResource(f cmdutil.Factory, info *resource.Info, out io.Writer, mapper meta.RESTMapper, shortOutput, forceDeletion bool) error { - if forceDeletion { - resource.NewHelper(info.Client, info.Mapping).Patch( - info.Namespace, - info.Name, - types.MergePatchType, - []byte(forceDeletePatch), - ) - } +func deleteResource(f cmdutil.Factory, info *resource.Info, out io.Writer, mapper meta.RESTMapper, shortOutput bool) error { if err := resource.NewHelper(info.Client, info.Mapping).Delete(info.Namespace, info.Name); err != nil && !kerr.IsNotFound(err) { return cmdutil.AddSourceToErr("deleting", info.Source, err) } diff --git a/pkg/util/flags.go b/pkg/util/flags.go index e3f49891c..69e9585e9 100644 --- a/pkg/util/flags.go +++ b/pkg/util/flags.go @@ -26,7 +26,6 @@ func AddCreateFlags(cmd *cobra.Command, options *resource.FilenameOptions) { func AddDeleteFlags(cmd *cobra.Command, options *resource.FilenameOptions) { cmd.Flags().StringP("namespace", "n", core.NamespaceDefault, "Delete object(s) from this namespace.") cmd.Flags().BoolP("all", "", false, "Delete all resources, including uninitialized ones, in the namespace of the specified resource types.") - cmd.Flags().BoolP("force", "", false, "Immediate deletion of some resources may result in inconsistency or data loss.") cmd.Flags().StringP("selector", "l", "", "Selector (label query) to filter on.") cmd.Flags().StringP("output", "o", "", "Output mode. Use \"-o name\" for shorter output (resource/name).") usage := "delete the resource"