Skip to content

Commit 85e7c93

Browse files
authored
Adding termination grace period logic (#107)
1 parent 63e9905 commit 85e7c93

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

charts/k8s-service/templates/_deployment_spec.tpl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,12 @@ spec:
339339
{{- end }}
340340
{{- /* END IMAGE PULL SECRETS LOGIC */ -}}
341341
342+
{{- /* START TERMINATION GRACE PERIOD LOGIC */ -}}
343+
{{- if .Values.terminationGracePeriodSeconds }}
344+
terminationGracePeriodSeconds: {{ .Values.terminationGracePeriodSeconds }}
345+
{{- end}}
346+
{{- /* END TERMINATION GRACE PERIOD LOGIC */ -}}
347+
342348
{{- /* START VOLUME LOGIC */ -}}
343349
{{- if index $hasInjectionTypes "hasVolume" }}
344350
volumes:

charts/k8s-service/values.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,14 @@ tolerations: []
545545
# list is a string that corresponds to the Secret name.
546546
imagePullSecrets: []
547547

548+
# terminationGracePeriodSeconds sets grace period Kubernetes will wait before terminating the pod. The timeout happens
549+
# in parallel to preStop hook and the SIGTERM signal, Kubernetes does not wait for preStop to finish before beginning
550+
# the grace period.
551+
#
552+
# EXAMPLE:
553+
# terminationGracePeriodSeconds: 30
554+
terminationGracePeriodSeconds: {}
555+
548556
# serviceAccount is a map that configures the ServiceAccount information for the Pod.
549557
# The expected keys of serviceAccount are:
550558
# - name (string) : The name of the ServiceAccount in the Namespace where the Pod is deployed

test/k8s_service_volume_template_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package test
88

99
import (
1010
"fmt"
11+
"strconv"
1112
"testing"
1213

1314
"github.com/stretchr/testify/assert"
@@ -115,3 +116,26 @@ func TestK8SServiceDeploymentAddingEmptyDirs(t *testing.T) {
115116
assert.Equal(t, volName, volume.Name)
116117
assert.Empty(t, volume.EmptyDir)
117118
}
119+
120+
func TestK8SServiceDeploymentAddingTerminationGracePeriod(t *testing.T) {
121+
122+
gracePeriod := "30"
123+
124+
deployment := renderK8SServiceDeploymentWithSetValues(
125+
t,
126+
map[string]string{
127+
"terminationGracePeriodSeconds": gracePeriod,
128+
},
129+
)
130+
131+
// Verify that there is only one container
132+
renderedPodContainers := deployment.Spec.Template.Spec.Containers
133+
require.Equal(t, len(renderedPodContainers), 1)
134+
135+
expectedGracePeriodInt64, err := strconv.ParseInt(gracePeriod, 10, 64)
136+
137+
// Verify termination grace period has been set for container
138+
assert.NoError(t, err)
139+
renderedTerminationGracePeriodSeconds := deployment.Spec.Template.Spec.TerminationGracePeriodSeconds
140+
require.Equal(t, expectedGracePeriodInt64, *renderedTerminationGracePeriodSeconds)
141+
}

0 commit comments

Comments
 (0)