mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 12:15:52 +00:00
default the ignorenotfound for delete when selecting objects
This commit is contained in:
parent
f4b2452654
commit
4ae3f882be
@ -151,6 +151,26 @@ func (o *DeleteOptions) Complete(f cmdutil.Factory, out, errOut io.Writer, args
|
||||
return err
|
||||
}
|
||||
|
||||
if o.DeleteAll || len(o.LabelSelector) > 0 || len(o.FieldSelector) > 0 {
|
||||
if f := cmd.Flags().Lookup("ignore-not-found"); f != nil && !f.Changed {
|
||||
// If the user didn't explicitly set the option, default to ignoring NotFound errors when used with --all, -l, or --field-selector
|
||||
o.IgnoreNotFound = true
|
||||
}
|
||||
}
|
||||
if o.DeleteNow {
|
||||
if o.GracePeriod != -1 {
|
||||
return fmt.Errorf("--now and --grace-period cannot be specified together")
|
||||
}
|
||||
o.GracePeriod = 1
|
||||
}
|
||||
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
|
||||
o.GracePeriod = 1
|
||||
}
|
||||
|
||||
o.Reaper = f.Reaper
|
||||
|
||||
includeUninitialized := cmdutil.ShouldIncludeUninitialized(cmd, false)
|
||||
@ -191,34 +211,11 @@ func (o *DeleteOptions) Validate(cmd *cobra.Command) error {
|
||||
if o.DeleteAll && len(o.FieldSelector) > 0 {
|
||||
return fmt.Errorf("cannot set --all and --field-selector at the same time")
|
||||
}
|
||||
if o.DeleteAll {
|
||||
f := cmd.Flags().Lookup("ignore-not-found")
|
||||
// The flag should never be missing
|
||||
if f == nil {
|
||||
return fmt.Errorf("missing --ignore-not-found flag")
|
||||
}
|
||||
// If the user didn't explicitly set the option, default to ignoring NotFound errors when used with --all
|
||||
if !f.Changed {
|
||||
o.IgnoreNotFound = true
|
||||
}
|
||||
}
|
||||
if o.DeleteNow {
|
||||
if o.GracePeriod != -1 {
|
||||
return fmt.Errorf("--now and --grace-period cannot be specified together")
|
||||
}
|
||||
o.GracePeriod = 1
|
||||
}
|
||||
if o.GracePeriod == 0 {
|
||||
if 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")
|
||||
} else {
|
||||
// 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
|
||||
o.GracePeriod = 1
|
||||
}
|
||||
} else if o.ForceDeletion {
|
||||
|
||||
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")
|
||||
case o.ForceDeletion:
|
||||
fmt.Fprintf(o.ErrOut, "warning: --force is ignored because --grace-period is not 0.\n")
|
||||
}
|
||||
return nil
|
||||
|
Loading…
Reference in New Issue
Block a user