mirror of https://github.com/k3s-io/k3s
Merge pull request #64375 from nilebox/delete-wait-cleanup
Automatic merge from submit-queue (batch tested with PRs 64300, 64375). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. Declare kubectl wait flag in a way consistent with other deletion flags **What this PR does / why we need it**: A follow up PR for #64034 and #63979 that makes declaring wait flag consistent with the other flags. **Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*: Fixes #64401 **Special notes for your reviewer**: **Release note**: ```release-note ```pull/8/head
commit
07e6410cf7
|
@ -139,8 +139,6 @@ func NewCmdDelete(f cmdutil.Factory, streams genericclioptions.IOStreams) *cobra
|
|||
|
||||
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)
|
||||
return cmd
|
||||
}
|
||||
|
@ -165,14 +163,9 @@ func (o *DeleteOptions) Complete(f cmdutil.Factory, args []string, cmd *cobra.Co
|
|||
}
|
||||
if o.GracePeriod == 0 && !o.ForceDeletion {
|
||||
// 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
|
||||
// to bypass this wait.
|
||||
o.WaitForDeletion = true
|
||||
// into --grace-period=1. Users may provide --force to bypass this conversion.
|
||||
o.GracePeriod = 1
|
||||
}
|
||||
if b, err := cmd.Flags().GetBool("wait"); err == nil {
|
||||
o.WaitForDeletion = b
|
||||
}
|
||||
|
||||
includeUninitialized := cmdutil.ShouldIncludeUninitialized(cmd, false)
|
||||
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")
|
||||
}
|
||||
|
||||
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")
|
||||
|
|
|
@ -39,6 +39,7 @@ type DeleteFlags struct {
|
|||
IgnoreNotFound *bool
|
||||
Now *bool
|
||||
Timeout *time.Duration
|
||||
Wait *bool
|
||||
Output *string
|
||||
}
|
||||
|
||||
|
@ -85,6 +86,9 @@ func (f *DeleteFlags) ToOptions(dynamicClient dynamic.Interface, streams generic
|
|||
if f.Timeout != nil {
|
||||
options.Timeout = *f.Timeout
|
||||
}
|
||||
if f.Wait != nil {
|
||||
options.WaitForDeletion = *f.Wait
|
||||
}
|
||||
|
||||
return options
|
||||
}
|
||||
|
@ -118,11 +122,12 @@ func (f *DeleteFlags) AddFlags(cmd *cobra.Command) {
|
|||
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.")
|
||||
}
|
||||
|
||||
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 {
|
||||
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
|
||||
|
@ -139,6 +144,7 @@ func NewDeleteCommandFlags(usage string) *DeleteFlags {
|
|||
labelSelector := ""
|
||||
fieldSelector := ""
|
||||
timeout := time.Duration(0)
|
||||
wait := true
|
||||
|
||||
filenames := []string{}
|
||||
recursive := false
|
||||
|
@ -156,6 +162,7 @@ func NewDeleteCommandFlags(usage string) *DeleteFlags {
|
|||
IgnoreNotFound: &ignoreNotFound,
|
||||
Now: &now,
|
||||
Timeout: &timeout,
|
||||
Wait: &wait,
|
||||
Output: &output,
|
||||
}
|
||||
}
|
||||
|
@ -167,6 +174,7 @@ func NewDeleteFlags(usage string) *DeleteFlags {
|
|||
|
||||
force := false
|
||||
timeout := time.Duration(0)
|
||||
wait := false
|
||||
|
||||
filenames := []string{}
|
||||
recursive := false
|
||||
|
@ -180,5 +188,6 @@ func NewDeleteFlags(usage string) *DeleteFlags {
|
|||
// add non-defaults
|
||||
Force: &force,
|
||||
Timeout: &timeout,
|
||||
Wait: &wait,
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue