Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add option to define terminationGracePeriodSeconds #60

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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