diff --git a/README.md b/README.md index 6fc2af9..a1dcb8c 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,7 @@ Here's a summary of the available configuration options: | pod.annotations | object | `{}` | Pod annotations | | pod.labels | object | `{}` | Pod labels | | pod.securityContext | object | `{}` | Pod security context | +| terminationGracePeriodSeconds | string | `null` | Pod terminationGracePeriodSeconds | | securityContext | object | `{}` | Container security context | | service.type | string | `ClusterIP` | Kubernetes service type | | service.annotations | object | `{}` | Annotations to add to the service | diff --git a/templates/deployment.yaml b/templates/deployment.yaml index f841227..5102cbd 100644 --- a/templates/deployment.yaml +++ b/templates/deployment.yaml @@ -68,6 +68,9 @@ spec: securityContext: {{- toYaml . | nindent 8 }} {{- end }} + {{- if .Values.terminationGracePeriodSeconds }} + terminationGracePeriodSeconds: {{ .Values.terminationGracePeriodSeconds }} + {{- end}} containers: - name: {{ .Chart.Name }} {{- if $has_volumes }} diff --git a/test/deployment_test.go b/test/deployment_test.go index ea93ebf..7e51c75 100644 --- a/test/deployment_test.go +++ b/test/deployment_test.go @@ -424,3 +424,30 @@ func (s *TemplateTest) TestCanSetLifecycleHooks() { s.Require().Equal("-c", deployment.Spec.Template.Spec.Containers[0].Lifecycle.PreStop.Exec.Command[1]) s.Require().Equal("sleep 60", deployment.Spec.Template.Spec.Containers[0].Lifecycle.PreStop.Exec.Command[2]) } + +func (s *TemplateTest) TestCanSetTerminationGracePeriodSeconds() { + options := &helm.Options{ + SetValues: map[string]string{ + "terminationGracePeriodSeconds": "60", + }, + KubectlOptions: k8s.NewKubectlOptions("", "", s.Namespace), + } + + output := helm.RenderTemplate(s.T(), options, s.ChartPath, s.Release, []string{"templates/deployment.yaml"}) + var deployment appsv1.Deployment + helm.UnmarshalK8SYaml(s.T(), output, &deployment) + + s.Require().Equal(int64(60), *deployment.Spec.Template.Spec.TerminationGracePeriodSeconds) +} + +func (s *TemplateTest) TestNotSetTerminationGracePeriodSeconds() { + options := &helm.Options{ + KubectlOptions: k8s.NewKubectlOptions("", "", s.Namespace), + } + output := helm.RenderTemplate(s.T(), options, s.ChartPath, s.Release, []string{"templates/deployment.yaml"}) + var deployment appsv1.Deployment + + helm.UnmarshalK8SYaml(s.T(), output, &deployment) + + s.Require().Empty(deployment.Spec.Template.Spec.TerminationGracePeriodSeconds) +} diff --git a/values.yaml b/values.yaml index 0eff014..6b63340 100644 --- a/values.yaml +++ b/values.yaml @@ -51,6 +51,8 @@ pod: # topologyKey: topology.kubernetes.io/zone # whenUnsatisfiable: DoNotSchedule +# terminationGracePeriodSeconds: 90 + securityContext: {} # capabilities: # drop: