mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +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:
commit
a42d7fa31c
@ -1179,6 +1179,7 @@ _kubectl_delete()
|
|||||||
flags+=("--grace-period=")
|
flags+=("--grace-period=")
|
||||||
flags+=("--ignore-not-found")
|
flags+=("--ignore-not-found")
|
||||||
flags+=("--include-extended-apis")
|
flags+=("--include-extended-apis")
|
||||||
|
flags+=("--now")
|
||||||
flags+=("--output=")
|
flags+=("--output=")
|
||||||
two_word_flags+=("-o")
|
two_word_flags+=("-o")
|
||||||
flags+=("--recursive")
|
flags+=("--recursive")
|
||||||
|
@ -52,6 +52,10 @@ will be lost along with the rest of the resource.
|
|||||||
\fB\-\-include\-extended\-apis\fP=true
|
\fB\-\-include\-extended\-apis\fP=true
|
||||||
If true, include definitions of new APIs via calls to the API server. [default true]
|
If true, include definitions of new APIs via calls to the API server. [default true]
|
||||||
|
|
||||||
|
.PP
|
||||||
|
\fB\-\-now\fP=false
|
||||||
|
If true, resources are force terminated without graceful deletion (same as \-\-grace\-period=0).
|
||||||
|
|
||||||
.PP
|
.PP
|
||||||
\fB\-o\fP, \fB\-\-output\fP=""
|
\fB\-o\fP, \fB\-\-output\fP=""
|
||||||
Output mode. Use "\-o name" for shorter output (resource/name).
|
Output mode. Use "\-o name" for shorter output (resource/name).
|
||||||
@ -184,6 +188,9 @@ kubectl delete pod,service baz foo
|
|||||||
# Delete pods and services with label name=myLabel.
|
# Delete pods and services with label name=myLabel.
|
||||||
kubectl delete pods,services \-l 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.
|
# Delete a pod with UID 1234\-56\-7890\-234234\-456456.
|
||||||
kubectl delete pod 1234\-56\-7890\-234234\-456456
|
kubectl delete pod 1234\-56\-7890\-234234\-456456
|
||||||
|
|
||||||
|
@ -68,6 +68,9 @@ kubectl delete pod,service baz foo
|
|||||||
# Delete pods and services with label name=myLabel.
|
# Delete pods and services with label name=myLabel.
|
||||||
kubectl delete pods,services -l 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.
|
# Delete a pod with UID 1234-56-7890-234234-456456.
|
||||||
kubectl delete pod 1234-56-7890-234234-456456
|
kubectl delete pod 1234-56-7890-234234-456456
|
||||||
|
|
||||||
@ -84,6 +87,7 @@ kubectl delete pods --all
|
|||||||
--grace-period=-1: Period of time in seconds given to the resource to terminate gracefully. Ignored if negative.
|
--grace-period=-1: Period of time in seconds given to the resource to terminate gracefully. Ignored if negative.
|
||||||
--ignore-not-found[=false]: Treat "resource not found" as a successful delete. Defaults to "true" when --all is specified.
|
--ignore-not-found[=false]: Treat "resource not found" as a successful delete. Defaults to "true" when --all is specified.
|
||||||
--include-extended-apis[=true]: If true, include definitions of new APIs via calls to the API server. [default true]
|
--include-extended-apis[=true]: If true, include definitions of new APIs via calls to the API server. [default true]
|
||||||
|
--now[=false]: If true, resources are force terminated without graceful deletion (same as --grace-period=0).
|
||||||
-o, --output="": Output mode. Use "-o name" for shorter output (resource/name).
|
-o, --output="": Output mode. Use "-o name" for shorter output (resource/name).
|
||||||
-R, --recursive[=false]: If true, process directory recursively.
|
-R, --recursive[=false]: If true, process directory recursively.
|
||||||
-l, --selector="": Selector (label query) to filter on.
|
-l, --selector="": Selector (label query) to filter on.
|
||||||
@ -122,7 +126,7 @@ kubectl delete pods --all
|
|||||||
|
|
||||||
* [kubectl](kubectl.md) - kubectl controls the Kubernetes cluster manager
|
* [kubectl](kubectl.md) - kubectl controls the Kubernetes cluster manager
|
||||||
|
|
||||||
###### Auto generated by spf13/cobra on 30-Mar-2016
|
###### Auto generated by spf13/cobra on 6-Apr-2016
|
||||||
|
|
||||||
<!-- BEGIN MUNGE: GENERATED_ANALYTICS -->
|
<!-- BEGIN MUNGE: GENERATED_ANALYTICS -->
|
||||||
[]()
|
[]()
|
||||||
|
@ -364,6 +364,15 @@ runTests() {
|
|||||||
# Post-condition: valid-pod POD doesn't exist
|
# Post-condition: valid-pod POD doesn't exist
|
||||||
kube::test::get_object_assert pods "{{range.items}}{{$id_field}}:{{end}}" ''
|
kube::test::get_object_assert pods "{{range.items}}{{$id_field}}:{{end}}" ''
|
||||||
|
|
||||||
|
### Delete POD valid-pod by id with --now
|
||||||
|
# Pre-condition: valid-pod POD exists
|
||||||
|
kubectl create "${kube_flags[@]}" -f docs/admin/limitrange/valid-pod.yaml
|
||||||
|
kube::test::get_object_assert pods "{{range.items}}{{$id_field}}:{{end}}" 'valid-pod:'
|
||||||
|
# Command
|
||||||
|
kubectl delete pod valid-pod "${kube_flags[@]}" --now
|
||||||
|
# Post-condition: valid-pod POD doesn't exist
|
||||||
|
kube::test::get_object_assert pods "{{range.items}}{{$id_field}}:{{end}}" ''
|
||||||
|
|
||||||
### Create POD valid-pod from dumped YAML
|
### Create POD valid-pod from dumped YAML
|
||||||
# Pre-condition: no POD exists
|
# Pre-condition: no POD exists
|
||||||
create_and_use_new_namespace
|
create_and_use_new_namespace
|
||||||
@ -758,7 +767,7 @@ __EOF__
|
|||||||
kubectl autoscale -f hack/testdata/frontend-controller.yaml --save-config "${kube_flags[@]}" --max=2
|
kubectl autoscale -f hack/testdata/frontend-controller.yaml --save-config "${kube_flags[@]}" --max=2
|
||||||
# Post-Condition: hpa "frontend" has configuration annotation
|
# Post-Condition: hpa "frontend" has configuration annotation
|
||||||
[[ "$(kubectl get hpa.v1beta1.extensions frontend -o yaml "${kube_flags[@]}" | grep kubectl.kubernetes.io/last-applied-configuration)" ]]
|
[[ "$(kubectl get hpa.v1beta1.extensions frontend -o yaml "${kube_flags[@]}" | grep kubectl.kubernetes.io/last-applied-configuration)" ]]
|
||||||
# Ensure we can interact with HPA objects in lists through both the extensions/v1beta1 and autoscaling/v1 APIs
|
# Ensure we can interact with HPA objects in lists through both the extensions/v1beta1 and autoscaling/v1 APIs
|
||||||
output_message=$(kubectl get hpa -o=jsonpath='{.items[0].apiVersion}' 2>&1 "${kube_flags[@]}")
|
output_message=$(kubectl get hpa -o=jsonpath='{.items[0].apiVersion}' 2>&1 "${kube_flags[@]}")
|
||||||
kube::test::if_has_string "${output_message}" 'extensions/v1beta1'
|
kube::test::if_has_string "${output_message}" 'extensions/v1beta1'
|
||||||
output_message=$(kubectl get hpa.extensions -o=jsonpath='{.items[0].apiVersion}' 2>&1 "${kube_flags[@]}")
|
output_message=$(kubectl get hpa.extensions -o=jsonpath='{.items[0].apiVersion}' 2>&1 "${kube_flags[@]}")
|
||||||
|
@ -60,6 +60,9 @@ kubectl delete pod,service baz foo
|
|||||||
# Delete pods and services with label name=myLabel.
|
# Delete pods and services with label name=myLabel.
|
||||||
kubectl delete pods,services -l 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.
|
# Delete a pod with UID 1234-56-7890-234234-456456.
|
||||||
kubectl delete pod 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("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().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().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")
|
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.AddOutputFlagsForMutation(cmd)
|
||||||
cmdutil.AddInclude3rdPartyFlags(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"
|
shortOutput := cmdutil.GetFlagString(cmd, "output") == "name"
|
||||||
// By default use a reaper to delete all related resources.
|
// By default use a reaper to delete all related resources.
|
||||||
if cmdutil.GetFlagBool(cmd, "cascade") {
|
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)
|
return DeleteResult(r, out, ignoreNotFound, shortOutput, mapper)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user