Merge pull request #69958 from Pingan2017/cleanup-kubectl-delete

remove unneed if block for kubectl delete command
pull/58/head
k8s-ci-robot 2018-10-18 19:50:53 -07:00 committed by GitHub
commit d8f9b5b668
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 8 deletions

View File

@ -126,7 +126,7 @@ func NewCmdDelete(f cmdutil.Factory, streams genericclioptions.IOStreams) *cobra
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
o := deleteFlags.ToOptions(nil, streams) o := deleteFlags.ToOptions(nil, streams)
cmdutil.CheckErr(o.Complete(f, args, cmd)) cmdutil.CheckErr(o.Complete(f, args, cmd))
cmdutil.CheckErr(o.Validate(cmd)) cmdutil.CheckErr(o.Validate())
cmdutil.CheckErr(o.RunDelete()) cmdutil.CheckErr(o.RunDelete())
}, },
SuggestFor: []string{"rm"}, SuggestFor: []string{"rm"},
@ -194,9 +194,9 @@ func (o *DeleteOptions) Complete(f cmdutil.Factory, args []string, cmd *cobra.Co
return nil return nil
} }
func (o *DeleteOptions) Validate(cmd *cobra.Command) error { func (o *DeleteOptions) Validate() error {
if o.Output != "" && o.Output != "name" { 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 { 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") 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 { switch {
case o.GracePeriod == 0 && o.ForceDeletion: 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") 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")