Skip to content

Commit

Permalink
feat: add option to define terminationGracePeriodSeconds
Browse files Browse the repository at this point in the history
  • Loading branch information
Helinanu committed Mar 19, 2024
1 parent ca57104 commit b5f2838
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
3 changes: 3 additions & 0 deletions templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ spec:
securityContext:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- if .Values.terminationGracePeriodSeconds }}
terminationGracePeriodSeconds: {{ .Values.terminationGracePeriodSeconds }}
{{- end}}
containers:
- name: {{ .Chart.Name }}
{{- if $has_volumes }}
Expand Down
27 changes: 27 additions & 0 deletions test/deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
2 changes: 2 additions & 0 deletions values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ pod:
# topologyKey: topology.kubernetes.io/zone
# whenUnsatisfiable: DoNotSchedule

# terminationGracePeriodSeconds: 90

securityContext: {}
# capabilities:
# drop:
Expand Down

0 comments on commit b5f2838

Please sign in to comment.