remove unneed if block for kubectl delete command

This commit is contained in:
Pingan2017 2018-10-18 11:33:45 +08:00
parent aad6437aa9
commit 797f0ac660

View File

@ -126,7 +126,7 @@ func NewCmdDelete(f cmdutil.Factory, streams genericclioptions.IOStreams) *cobra
Run: func(cmd *cobra.Command, args []string) {
o := deleteFlags.ToOptions(nil, streams)
cmdutil.CheckErr(o.Complete(f, args, cmd))
cmdutil.CheckErr(o.Validate(cmd))
cmdutil.CheckErr(o.Validate())
cmdutil.CheckErr(o.RunDelete())
},
SuggestFor: []string{"rm"},
@ -194,9 +194,9 @@ func (o *DeleteOptions) Complete(f cmdutil.Factory, args []string, cmd *cobra.Co
return nil
}
func (o *DeleteOptions) Validate(cmd *cobra.Command) error {
func (o *DeleteOptions) Validate() error {
if o.Output != "" && o.Output != "name" {
return cmdutil.UsageErrorf(cmd, "Unexpected -o output mode: %v. We only support '-o name'.", o.Output)
return fmt.Errorf("unexpected -o output mode: %v. We only support '-o name'.", o.Output)
}
if o.DeleteAll && len(o.LabelSelector) > 0 {
@ -206,11 +206,6 @@ func (o *DeleteOptions) Validate(cmd *cobra.Command) error {
return fmt.Errorf("cannot set --all and --field-selector at the same time")
}
if o.GracePeriod == 0 && !o.ForceDeletion && !o.WaitForDeletion {
// With the explicit --wait flag we need extra validation for backward compatibility
return fmt.Errorf("--grace-period=0 must have either --force specified, or --wait to be set to true")
}
switch {
case o.GracePeriod == 0 && o.ForceDeletion:
fmt.Fprintf(o.ErrOut, "warning: Immediate deletion does not wait for confirmation that the running resource has been terminated. The resource may continue to run on the cluster indefinitely.\n")