mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-05 10:19:50 +00:00
Declare wait flag in way consistent with other deletion flags
This commit is contained in:
parent
0125edb460
commit
6f1b178ed7
@ -139,8 +139,6 @@ func NewCmdDelete(f cmdutil.Factory, streams genericclioptions.IOStreams) *cobra
|
|||||||
|
|
||||||
deleteFlags.AddFlags(cmd)
|
deleteFlags.AddFlags(cmd)
|
||||||
|
|
||||||
cmd.Flags().Bool("wait", true, `If true, wait for resources to be gone before returning. This waits for finalizers.`)
|
|
||||||
|
|
||||||
cmdutil.AddIncludeUninitializedFlag(cmd)
|
cmdutil.AddIncludeUninitializedFlag(cmd)
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
@ -165,14 +163,9 @@ func (o *DeleteOptions) Complete(f cmdutil.Factory, args []string, cmd *cobra.Co
|
|||||||
}
|
}
|
||||||
if o.GracePeriod == 0 && !o.ForceDeletion {
|
if o.GracePeriod == 0 && !o.ForceDeletion {
|
||||||
// To preserve backwards compatibility, but prevent accidental data loss, we convert --grace-period=0
|
// To preserve backwards compatibility, but prevent accidental data loss, we convert --grace-period=0
|
||||||
// into --grace-period=1 and wait until the object is successfully deleted. Users may provide --force
|
// into --grace-period=1. Users may provide --force to bypass this conversion.
|
||||||
// to bypass this wait.
|
|
||||||
o.WaitForDeletion = true
|
|
||||||
o.GracePeriod = 1
|
o.GracePeriod = 1
|
||||||
}
|
}
|
||||||
if b, err := cmd.Flags().GetBool("wait"); err == nil {
|
|
||||||
o.WaitForDeletion = b
|
|
||||||
}
|
|
||||||
|
|
||||||
includeUninitialized := cmdutil.ShouldIncludeUninitialized(cmd, false)
|
includeUninitialized := cmdutil.ShouldIncludeUninitialized(cmd, false)
|
||||||
r := f.NewBuilder().
|
r := f.NewBuilder().
|
||||||
@ -218,6 +211,11 @@ 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")
|
||||||
|
@ -39,6 +39,7 @@ type DeleteFlags struct {
|
|||||||
IgnoreNotFound *bool
|
IgnoreNotFound *bool
|
||||||
Now *bool
|
Now *bool
|
||||||
Timeout *time.Duration
|
Timeout *time.Duration
|
||||||
|
Wait *bool
|
||||||
Output *string
|
Output *string
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,6 +86,9 @@ func (f *DeleteFlags) ToOptions(dynamicClient dynamic.Interface, streams generic
|
|||||||
if f.Timeout != nil {
|
if f.Timeout != nil {
|
||||||
options.Timeout = *f.Timeout
|
options.Timeout = *f.Timeout
|
||||||
}
|
}
|
||||||
|
if f.Wait != nil {
|
||||||
|
options.WaitForDeletion = *f.Wait
|
||||||
|
}
|
||||||
|
|
||||||
return options
|
return options
|
||||||
}
|
}
|
||||||
@ -118,11 +122,12 @@ func (f *DeleteFlags) AddFlags(cmd *cobra.Command) {
|
|||||||
if f.IgnoreNotFound != nil {
|
if f.IgnoreNotFound != nil {
|
||||||
cmd.Flags().BoolVar(f.IgnoreNotFound, "ignore-not-found", *f.IgnoreNotFound, "Treat \"resource not found\" as a successful delete. Defaults to \"true\" when --all is specified.")
|
cmd.Flags().BoolVar(f.IgnoreNotFound, "ignore-not-found", *f.IgnoreNotFound, "Treat \"resource not found\" as a successful delete. Defaults to \"true\" when --all is specified.")
|
||||||
}
|
}
|
||||||
|
if f.Wait != nil {
|
||||||
|
cmd.Flags().BoolVar(f.Wait, "wait", *f.Wait, "If true, wait for resources to be gone before returning. This waits for finalizers.")
|
||||||
|
}
|
||||||
if f.Output != nil {
|
if f.Output != nil {
|
||||||
cmd.Flags().StringVarP(f.Output, "output", "o", *f.Output, "Output mode. Use \"-o name\" for shorter output (resource/name).")
|
cmd.Flags().StringVarP(f.Output, "output", "o", *f.Output, "Output mode. Use \"-o name\" for shorter output (resource/name).")
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewDeleteCommandFlags provides default flags and values for use with the "delete" command
|
// NewDeleteCommandFlags provides default flags and values for use with the "delete" command
|
||||||
@ -139,6 +144,7 @@ func NewDeleteCommandFlags(usage string) *DeleteFlags {
|
|||||||
labelSelector := ""
|
labelSelector := ""
|
||||||
fieldSelector := ""
|
fieldSelector := ""
|
||||||
timeout := time.Duration(0)
|
timeout := time.Duration(0)
|
||||||
|
wait := true
|
||||||
|
|
||||||
filenames := []string{}
|
filenames := []string{}
|
||||||
recursive := false
|
recursive := false
|
||||||
@ -156,6 +162,7 @@ func NewDeleteCommandFlags(usage string) *DeleteFlags {
|
|||||||
IgnoreNotFound: &ignoreNotFound,
|
IgnoreNotFound: &ignoreNotFound,
|
||||||
Now: &now,
|
Now: &now,
|
||||||
Timeout: &timeout,
|
Timeout: &timeout,
|
||||||
|
Wait: &wait,
|
||||||
Output: &output,
|
Output: &output,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -167,6 +174,7 @@ func NewDeleteFlags(usage string) *DeleteFlags {
|
|||||||
|
|
||||||
force := false
|
force := false
|
||||||
timeout := time.Duration(0)
|
timeout := time.Duration(0)
|
||||||
|
wait := false
|
||||||
|
|
||||||
filenames := []string{}
|
filenames := []string{}
|
||||||
recursive := false
|
recursive := false
|
||||||
@ -180,5 +188,6 @@ func NewDeleteFlags(usage string) *DeleteFlags {
|
|||||||
// add non-defaults
|
// add non-defaults
|
||||||
Force: &force,
|
Force: &force,
|
||||||
Timeout: &timeout,
|
Timeout: &timeout,
|
||||||
|
Wait: &wait,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user