diff --git a/CHANGELOG.md b/CHANGELOG.md index 66de91324f..17f3b4d878 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,7 @@ ## UNRELEASED +IMPROVEMENTS: +* Helm + * Allow customization of `terminationGracePeriodSeconds` on the ingress gateways. [[GH-947](https://github.com/hashicorp/consul-k8s/pull/947)] ## 0.39.0 (December 15, 2021) diff --git a/charts/consul/templates/ingress-gateways-deployment.yaml b/charts/consul/templates/ingress-gateways-deployment.yaml index 5b8c8dc4b7..8d0ba09cdb 100644 --- a/charts/consul/templates/ingress-gateways-deployment.yaml +++ b/charts/consul/templates/ingress-gateways-deployment.yaml @@ -88,7 +88,7 @@ spec: tolerations: {{ tpl (default $defaults.tolerations .tolerations) $root | nindent 8 | trim }} {{- end }} - terminationGracePeriodSeconds: 10 + terminationGracePeriodSeconds: {{ default $defaults.terminationGracePeriodSeconds .terminationGracePeriodSeconds }} serviceAccountName: {{ template "consul.fullname" $root }}-{{ .name }} volumes: - name: consul-bin diff --git a/charts/consul/test/unit/ingress-gateways-deployment.bats b/charts/consul/test/unit/ingress-gateways-deployment.bats index c22e325771..b72819c8ff 100644 --- a/charts/consul/test/unit/ingress-gateways-deployment.bats +++ b/charts/consul/test/unit/ingress-gateways-deployment.bats @@ -1609,4 +1609,44 @@ EOF [ "${actual}" = "ca" ] local actual=$(echo $object | yq -r '.metadata.annotations."vault.hashicorp.com/ca-cert"') [ "${actual}" = "/vault/custom/tls.crt" ] -} \ No newline at end of file +} + +#-------------------------------------------------------------------- +# terminationGracePeriodSeconds + +@test "ingressGateways/Deployment: terminationGracePeriodSeconds defaults to 10" { + cd `chart_dir` + local actual=$(helm template \ + -s templates/ingress-gateways-deployment.yaml \ + --set 'ingressGateways.enabled=true' \ + --set 'connectInject.enabled=true' \ + . | tee /dev/stderr | + yq -s -r '.[0].spec.template.spec.terminationGracePeriodSeconds' | tee /dev/stderr) + [ "${actual}" = "10" ] +} + +@test "ingressGateways/Deployment: terminationGracePeriodSeconds can be set through defaults" { + cd `chart_dir` + local actual=$(helm template \ + -s templates/ingress-gateways-deployment.yaml \ + --set 'ingressGateways.enabled=true' \ + --set 'connectInject.enabled=true' \ + --set 'ingressGateways.defaults.terminationGracePeriodSeconds=5' \ + . | tee /dev/stderr | + yq -s -r '.[0].spec.template.spec.terminationGracePeriodSeconds' | tee /dev/stderr) + [ "${actual}" = "5" ] +} + +@test "ingressGateways/Deployment: can set terminationGracePeriodSeconds through specific gateway overriding defaults" { + cd `chart_dir` + local actual=$(helm template \ + -s templates/ingress-gateways-deployment.yaml \ + --set 'ingressGateways.enabled=true' \ + --set 'connectInject.enabled=true' \ + --set 'ingressGateways.defaults.terminationGracePeriodSeconds=5' \ + --set 'ingressGateways.gateways[0].name=gateway1' \ + --set 'ingressGateways.gateways[0].terminationGracePeriodSeconds=30' \ + . | tee /dev/stderr | + yq -s -r '.[0].spec.template.spec.terminationGracePeriodSeconds' | tee /dev/stderr) + [ "${actual}" = "30" ] +} diff --git a/charts/consul/values.yaml b/charts/consul/values.yaml index 800c640528..c97aef15ce 100644 --- a/charts/consul/values.yaml +++ b/charts/consul/values.yaml @@ -2304,6 +2304,9 @@ ingressGateways: # Optional priorityClassName. priorityClassName: "" + # Amount of seconds to wait for graceful termination before killing the pod. + terminationGracePeriodSeconds: 10 + # Annotations to apply to the ingress gateway deployment. Annotations defined # here will be applied to all ingress gateway deployments in addition to any # annotations defined for a specific gateway in `ingressGateways.gateways`.