From fb6da39a134950aae2efd4808ddb807fea0ccc3f Mon Sep 17 00:00:00 2001 From: Namco Date: Wed, 1 Jul 2020 13:36:05 +0800 Subject: [PATCH] add grace period for pod kill chaos (#663) Signed-off-by: Gong Mengnan --- api/v1alpha1/podchaos_types.go | 6 ++++++ config/crd/bases/pingcap.com_podchaos.yaml | 8 ++++++++ controllers/podchaos/podkill/types.go | 2 +- manifests/crd.yaml | 8 ++++++++ 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/api/v1alpha1/podchaos_types.go b/api/v1alpha1/podchaos_types.go index c633743606..0225a6b538 100644 --- a/api/v1alpha1/podchaos_types.go +++ b/api/v1alpha1/podchaos_types.go @@ -188,6 +188,12 @@ type PodChaosSpec struct { // Needed in container-kill. // +optional ContainerName string `json:"containerName"` + + // GracePeriod is used in pod-kill action. It represents the duration in seconds before the pod should be deleted. + // Value must be non-negative integer. The default value is zero that indicates delete immediately. + // +optional + // +kubebuilder:validation:Minimum=0 + GracePeriod int64 `json:"gracePeriod"` } func (in *PodChaosSpec) GetSelector() SelectorSpec { diff --git a/config/crd/bases/pingcap.com_podchaos.yaml b/config/crd/bases/pingcap.com_podchaos.yaml index 8f0646de1d..62792149ca 100644 --- a/config/crd/bases/pingcap.com_podchaos.yaml +++ b/config/crd/bases/pingcap.com_podchaos.yaml @@ -53,6 +53,14 @@ spec: fraction and a unit suffix, such as "300ms", "-1.5h" or "2h45m". Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h". type: string + gracePeriod: + description: GracePeriod is used in pod-kill action. It represents the + duration in seconds before the pod should be deleted. Value must be + non-negative integer. The default value is zero that indicates delete + immediately. + format: int64 + minimum: 0 + type: integer mode: description: 'Mode defines the mode to run chaos action. Supported mode: one / all / fixed / fixed-percent / random-max-percent' diff --git a/controllers/podchaos/podkill/types.go b/controllers/podchaos/podkill/types.go index 9aa0c6c32e..1db38e9b76 100644 --- a/controllers/podchaos/podkill/types.go +++ b/controllers/podchaos/podkill/types.go @@ -74,7 +74,7 @@ func (r *Reconciler) Apply(ctx context.Context, req ctrl.Request, chaos v1alpha1 r.Log.Info("Deleting", "namespace", pod.Namespace, "name", pod.Name) if err := r.Delete(ctx, pod, &client.DeleteOptions{ - GracePeriodSeconds: new(int64), // PeriodSeconds has to be set specifically + GracePeriodSeconds: &podchaos.Spec.GracePeriod, // PeriodSeconds has to be set specifically }); err != nil { r.Log.Error(err, "unable to delete pod") return err diff --git a/manifests/crd.yaml b/manifests/crd.yaml index bf7b65301c..179acdbf10 100644 --- a/manifests/crd.yaml +++ b/manifests/crd.yaml @@ -1016,6 +1016,14 @@ spec: fraction and a unit suffix, such as "300ms", "-1.5h" or "2h45m". Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h". type: string + gracePeriod: + description: GracePeriod is used in pod-kill action. It represents the + duration in seconds before the pod should be deleted. Value must be + non-negative integer. The default value is zero that indicates delete + immediately. + format: int64 + minimum: 0 + type: integer mode: description: 'Mode defines the mode to run chaos action. Supported mode: one / all / fixed / fixed-percent / random-max-percent'