Skip to content

Commit

Permalink
chore(terminationGracePeriodSeconds): Add support for termination gra…
Browse files Browse the repository at this point in the history
…ce period seconds (#138) (#139)

Signed-off-by: shubhamchaudhary <[email protected]>

Co-authored-by: Shubham Chaudhary <[email protected]>
  • Loading branch information
Karthik Satchitanand and ispeakc0de authored Apr 15, 2021
1 parent 9eb3d5e commit dde37bd
Show file tree
Hide file tree
Showing 12 changed files with 67 additions and 46 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ go 1.13

require (
github.com/jpillora/go-ogle-analytics v0.0.0-20161213085824-14b04e0594ef
github.com/litmuschaos/chaos-operator v0.0.0-20210312154932-c2d4b2ff7b19
github.com/litmuschaos/elves v0.0.0-20201107015738-552d74669e3c
github.com/litmuschaos/chaos-operator v0.0.0-20210325093226-50a357ad2256
github.com/litmuschaos/elves v0.0.0-20210325101625-5620f93aed51
github.com/litmuschaos/litmus-go v0.0.0-20201015093552-b88e93ffc452
github.com/onsi/ginkgo v1.11.0
github.com/onsi/gomega v1.8.1
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -452,12 +452,14 @@ github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de/go.mod h1:zAbeS9
github.com/lithammer/dedent v1.1.0/go.mod h1:jrXYCQtgg0nJiN+StA2KgR7w6CiQNv9Fd/Z9BP0jIOc=
github.com/litmuschaos/chaos-operator v0.0.0-20201005102541-be0f9bb115ce h1:pB9ba9swCB3tUYngzP3RMlLPuEAGYxmfTL/G0e3zs04=
github.com/litmuschaos/chaos-operator v0.0.0-20201005102541-be0f9bb115ce/go.mod h1:J4NuADZBn6nUkhKNux3p3ghSUfxoB+itsO+rD8tOCNk=
github.com/litmuschaos/chaos-operator v0.0.0-20210312154932-c2d4b2ff7b19 h1:k3qTu0NiBd5PMwA9O0EZ6J0vZjeFS6UqP4IZ1ISd0vQ=
github.com/litmuschaos/chaos-operator v0.0.0-20210312154932-c2d4b2ff7b19/go.mod h1:Z2GpYjqXwFd8bx+kv58YEQFxynx1v9PMGCGTQFRVnFQ=
github.com/litmuschaos/chaos-operator v0.0.0-20210325093226-50a357ad2256 h1:Za6YLg56j3QRNTv7gtReZxGN7Vp09zCbZttOL2DY4Ik=
github.com/litmuschaos/chaos-operator v0.0.0-20210325093226-50a357ad2256/go.mod h1:Z2GpYjqXwFd8bx+kv58YEQFxynx1v9PMGCGTQFRVnFQ=
github.com/litmuschaos/elves v0.0.0-20200930100735-5efe29d0ad5b h1:eYT2CfSf7FZu01DAgxgjrlSc7dX5IlwPRqD44RH47Kk=
github.com/litmuschaos/elves v0.0.0-20200930100735-5efe29d0ad5b/go.mod h1:DsbHGNUq/78NZozWVVI9Q6eBei4I+JjlkkD5aibJ3MQ=
github.com/litmuschaos/elves v0.0.0-20201107015738-552d74669e3c h1:+hlppERdpCxMRW0QC+ckbz/mS6wH+fNVMlDMFGClk7U=
github.com/litmuschaos/elves v0.0.0-20201107015738-552d74669e3c/go.mod h1:DsbHGNUq/78NZozWVVI9Q6eBei4I+JjlkkD5aibJ3MQ=
github.com/litmuschaos/elves v0.0.0-20210325101625-5620f93aed51 h1:6CpcGjZsVHMRSB/Z8z9+ectmb1KuQUiy+244jISNhBA=
github.com/litmuschaos/elves v0.0.0-20210325101625-5620f93aed51/go.mod h1:DsbHGNUq/78NZozWVVI9Q6eBei4I+JjlkkD5aibJ3MQ=
github.com/litmuschaos/litmus-go v0.0.0-20201015093552-b88e93ffc452 h1:ZC/dhFHbzpibZAxLT9Pp2IPcAnEusIN6W6IMepkT9ck=
github.com/litmuschaos/litmus-go v0.0.0-20201015093552-b88e93ffc452/go.mod h1:vS08ynv8o7+AjLwP6vhUjgcB5JM0zVq2AFWWW8P6q48=
github.com/lpabon/godbc v0.1.1/go.mod h1:Jo9QV0cf3U6jZABgiJ2skINAXb9j8m51r07g4KI92ZA=
Expand Down
4 changes: 4 additions & 0 deletions pkg/utils/builders.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ func buildPodTemplateSpec(experiment *ExperimentDetails, containerForPod *contai
WithAnnotations(experiment.Annotations).
WithContainerBuildersNew(containerForPod)

if experiment.TerminationGracePeriodSeconds != 0 {
podtemplate.WithTerminationGracePeriodSeconds(experiment.TerminationGracePeriodSeconds)
}

if !reflect.DeepEqual(experiment.SecurityContext.PodSecurityContext, corev1.PodSecurityContext{}) {

podtemplate.WithSecurityContext(experiment.SecurityContext.PodSecurityContext)
Expand Down
9 changes: 8 additions & 1 deletion pkg/utils/engineHelper.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ func (expDetails *ExperimentDetails) SetInstanceAttributeValuesFromChaosEngine(e
SetResourceRequirementsFromEngine(chaosEngine).
SetImagePullSecretsFromEngine(chaosEngine).
SetTolerationsFromEngine(chaosEngine).
SetExpImageFromEngine(chaosEngine)
SetExpImageFromEngine(chaosEngine).
SetTerminationGracePeriodSecondsFromEngine(chaosEngine)

return nil
}
Expand Down Expand Up @@ -88,6 +89,12 @@ func (expDetails *ExperimentDetails) SetExpNodeSelectorFromEngine(engine *litmus
return expDetails
}

// SetTerminationGracePeriodSecondsFromEngine set the terminationGracePeriodSeconds for experiment pod provided in the chaosEngine
func (expDetails *ExperimentDetails) SetTerminationGracePeriodSecondsFromEngine(engine *litmuschaosv1alpha1.ChaosEngine) *ExperimentDetails {
expDetails.TerminationGracePeriodSeconds = engine.Spec.TerminationGracePeriodSeconds
return expDetails
}

// SetTolerationsFromEngine add the tolerations based on the key/operator/effect provided in the chaosEngine
func (expDetails *ExperimentDetails) SetTolerationsFromEngine(engine *litmuschaosv1alpha1.ChaosEngine) *ExperimentDetails {
expRefList := engine.Spec.Experiments
Expand Down
24 changes: 13 additions & 11 deletions pkg/utils/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package utils

import (
"os"
"strconv"
"strings"

v1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -49,17 +50,18 @@ func (expDetails *ExperimentDetails) SetENV(engineDetails EngineDetails, clients
}
// Store ENV in a map
ENVList := map[string]string{
"CHAOSENGINE": engineDetails.Name,
"APP_LABEL": engineDetails.AppLabel,
"CHAOS_NAMESPACE": engineDetails.EngineNamespace,
"APP_NAMESPACE": engineDetails.AppNs,
"APP_KIND": engineDetails.AppKind,
"AUXILIARY_APPINFO": engineDetails.AuxiliaryAppInfo,
"CHAOS_UID": engineDetails.UID,
"EXPERIMENT_NAME": expDetails.Name,
"ANNOTATION_KEY": engineDetails.AnnotationKey,
"ANNOTATION_CHECK": engineDetails.AnnotationCheck,
"LIB_IMAGE_PULL_POLICY": string(expDetails.ExpImagePullPolicy),
"CHAOSENGINE": engineDetails.Name,
"APP_LABEL": engineDetails.AppLabel,
"CHAOS_NAMESPACE": engineDetails.EngineNamespace,
"APP_NAMESPACE": engineDetails.AppNs,
"APP_KIND": engineDetails.AppKind,
"AUXILIARY_APPINFO": engineDetails.AuxiliaryAppInfo,
"CHAOS_UID": engineDetails.UID,
"EXPERIMENT_NAME": expDetails.Name,
"ANNOTATION_KEY": engineDetails.AnnotationKey,
"ANNOTATION_CHECK": engineDetails.AnnotationCheck,
"LIB_IMAGE_PULL_POLICY": string(expDetails.ExpImagePullPolicy),
"TERMINATION_GRACE_PERIOD_SECONDS": strconv.Itoa(int(expDetails.TerminationGracePeriodSeconds)),
}
// Adding some additional ENV's from spec.AppInfo of ChaosEngine// Adding some additional ENV's from spec.AppInfo of ChaosEngine
for key, value := range ENVList {
Expand Down
9 changes: 5 additions & 4 deletions pkg/utils/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,11 @@ type ExperimentDetails struct {
HostPID bool
// InstanceID is passed as env inside chaosengine
// It is separately specified here because this attribute is common for all experiment.
InstanceID string
ResourceRequirements v1.ResourceRequirements
ImagePullSecrets []corev1.LocalObjectReference
StatusCheckTimeout int
InstanceID string
ResourceRequirements v1.ResourceRequirements
ImagePullSecrets []corev1.LocalObjectReference
StatusCheckTimeout int
TerminationGracePeriodSeconds int64
}

//VolumeOpts is a strcuture for all volume related operations
Expand Down
1 change: 0 additions & 1 deletion tests/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ var _ = Describe("BDD on chaos-runner", func() {
Type: "go",
},
},
Monitoring: true,
Experiments: []v1alpha1.ExperimentList{
{
Name: "pod-delete",
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ github.com/jpillora/go-ogle-analytics
github.com/json-iterator/go
# github.com/konsorten/go-windows-terminal-sequences v1.0.3
github.com/konsorten/go-windows-terminal-sequences
# github.com/litmuschaos/chaos-operator v0.0.0-20210312154932-c2d4b2ff7b19
# github.com/litmuschaos/chaos-operator v0.0.0-20210325093226-50a357ad2256
github.com/litmuschaos/chaos-operator/pkg/apis/litmuschaos/v1alpha1
github.com/litmuschaos/chaos-operator/pkg/client/clientset/versioned
github.com/litmuschaos/chaos-operator/pkg/client/clientset/versioned/fake
github.com/litmuschaos/chaos-operator/pkg/client/clientset/versioned/scheme
github.com/litmuschaos/chaos-operator/pkg/client/clientset/versioned/typed/litmuschaos/v1alpha1
github.com/litmuschaos/chaos-operator/pkg/client/clientset/versioned/typed/litmuschaos/v1alpha1/fake
# github.com/litmuschaos/elves v0.0.0-20201107015738-552d74669e3c
# github.com/litmuschaos/elves v0.0.0-20210325101625-5620f93aed51
github.com/litmuschaos/elves/kubernetes/container
github.com/litmuschaos/elves/kubernetes/job
github.com/litmuschaos/elves/kubernetes/jobspec
Expand Down

0 comments on commit dde37bd

Please sign in to comment.