Skip to content

Commit

Permalink
add grace period for pod kill chaos (chaos-mesh#663)
Browse files Browse the repository at this point in the history
Signed-off-by: Gong Mengnan <[email protected]>
  • Loading branch information
namco1992 authored Jul 1, 2020
1 parent 153a2c4 commit fb6da39
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
6 changes: 6 additions & 0 deletions api/v1alpha1/podchaos_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 8 additions & 0 deletions config/crd/bases/pingcap.com_podchaos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion controllers/podchaos/podkill/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions manifests/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit fb6da39

Please sign in to comment.