Skip to content

Commit

Permalink
Remove --force flag (#195)
Browse files Browse the repository at this point in the history
  • Loading branch information
the-redback authored and tamalsaha committed Mar 9, 2018
1 parent 62b20a8 commit 2c891a9
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 26 deletions.
1 change: 0 additions & 1 deletion docs/reference/kubedb_delete.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
28 changes: 4 additions & 24 deletions pkg/cmds/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -132,31 +128,15 @@ 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
}
}

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)
}
Expand Down
1 change: 0 additions & 1 deletion pkg/util/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 2c891a9

Please sign in to comment.