mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-04 15:05:20 +00:00
Merge pull request #23756 from smarterclayton/force_delete
Add a client flag to delete "--now" for grace period 0
This commit is contained in:
@@ -60,6 +60,9 @@ kubectl delete pod,service baz foo
|
||||
# Delete pods and services with label name=myLabel.
|
||||
kubectl delete pods,services -l name=myLabel
|
||||
|
||||
# Delete a pod immediately (no graceful shutdown)
|
||||
kubectl delete pod foo --now
|
||||
|
||||
# Delete a pod with UID 1234-56-7890-234234-456456.
|
||||
kubectl delete pod 1234-56-7890-234234-456456
|
||||
|
||||
@@ -100,6 +103,7 @@ func NewCmdDelete(f *cmdutil.Factory, out io.Writer) *cobra.Command {
|
||||
cmd.Flags().Bool("ignore-not-found", false, "Treat \"resource not found\" as a successful delete. Defaults to \"true\" when --all is specified.")
|
||||
cmd.Flags().Bool("cascade", true, "If true, cascade the deletion of the resources managed by this resource (e.g. Pods created by a ReplicationController). Default true.")
|
||||
cmd.Flags().Int("grace-period", -1, "Period of time in seconds given to the resource to terminate gracefully. Ignored if negative.")
|
||||
cmd.Flags().Bool("now", false, "If true, resources are force terminated without graceful deletion (same as --grace-period=0).")
|
||||
cmd.Flags().Duration("timeout", 0, "The length of time to wait before giving up on a delete, zero means determine a timeout from the size of the object")
|
||||
cmdutil.AddOutputFlagsForMutation(cmd)
|
||||
cmdutil.AddInclude3rdPartyFlags(cmd)
|
||||
@@ -140,10 +144,18 @@ func RunDelete(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []str
|
||||
}
|
||||
}
|
||||
|
||||
gracePeriod := cmdutil.GetFlagInt(cmd, "grace-period")
|
||||
if cmdutil.GetFlagBool(cmd, "now") {
|
||||
if gracePeriod != -1 {
|
||||
return fmt.Errorf("--now and --grace-period cannot be specified together")
|
||||
}
|
||||
gracePeriod = 0
|
||||
}
|
||||
|
||||
shortOutput := cmdutil.GetFlagString(cmd, "output") == "name"
|
||||
// By default use a reaper to delete all related resources.
|
||||
if cmdutil.GetFlagBool(cmd, "cascade") {
|
||||
return ReapResult(r, f, out, cmdutil.GetFlagBool(cmd, "cascade"), ignoreNotFound, cmdutil.GetFlagDuration(cmd, "timeout"), cmdutil.GetFlagInt(cmd, "grace-period"), shortOutput, mapper)
|
||||
return ReapResult(r, f, out, cmdutil.GetFlagBool(cmd, "cascade"), ignoreNotFound, cmdutil.GetFlagDuration(cmd, "timeout"), gracePeriod, shortOutput, mapper)
|
||||
}
|
||||
return DeleteResult(r, out, ignoreNotFound, shortOutput, mapper)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user