Skip to content

Commit 2244a55

Browse files
davidlivingroomsDavid Salas
andauthored
feature/init-containers (#104)
* adding initContainers property * indentation * adding doc and unit test * formatting Co-authored-by: David Salas <[email protected]>
1 parent cb199b7 commit 2244a55

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

charts/k8s-service/templates/_deployment_spec.tpl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,15 @@ spec:
314314
{{ toYaml $value | indent 10 }}
315315
{{- end }}
316316
317+
318+
{{- if gt (len .Values.initContainers) 0 }}
319+
initContainers:
320+
{{- range $key, $value := .Values.initContainers }}
321+
- name: {{ $key }}
322+
{{ toYaml $value | indent 10 }}
323+
{{- end }}
324+
{{- end }}
325+
317326
{{- /* START IMAGE PULL SECRETS LOGIC */ -}}
318327
{{- if gt (len .Values.imagePullSecrets) 0 }}
319328
imagePullSecrets:

charts/k8s-service/values.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,24 @@ shutdownDelay: 5
154154
# value: docker
155155
sideCarContainers: {}
156156

157+
# initContainers specifies any additional containers that should be deployed as init containers to the main application
158+
# container. This will be included in the Deployment container spec so that it will be included in the application Pod.
159+
# This is a nested map, where the first map key is used to name the container, with the nested map being injected as the
160+
# container spec.
161+
#
162+
# The following example specifies a flyway image as an init container with an environment variable, binding the
163+
# name `flyway`:
164+
#
165+
# EXAMPLE:
166+
#
167+
# initContainers:
168+
# flyway:
169+
# image: flyway/flyway
170+
# env:
171+
# - name: FLYWAY_LOCATIONS
172+
# value: 'filesystem:/flyway/migrations'
173+
initContainers: {}
174+
157175
# canary specifies test pod(s) that are deployed alongside your application's stable track pods.
158176
# It is useful for testing a new release candidate in a production environment with minimal disruption and
159177
# for allowing you to find any issues early.

test/k8s_service_template_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,19 @@ func TestK8SServiceSideCarContainersRendersCorrectly(t *testing.T) {
635635
assert.Equal(t, sideCarContainer.Image, "datadog/agent:latest")
636636
}
637637

638+
func TestK8SServiceInitContainersRendersCorrectly(t *testing.T) {
639+
t.Parallel()
640+
deployment := renderK8SServiceDeploymentWithSetValues(
641+
t,
642+
map[string]string{
643+
"initContainers.flyway.image": "flyway/flyway",
644+
},
645+
)
646+
renderedContainers := deployment.Spec.Template.Spec.InitContainers
647+
require.Equal(t, len(renderedContainers), 1)
648+
assert.Equal(t, renderedContainers[0].Image, "flyway/flyway")
649+
}
650+
638651
func TestK8SServiceDisableDefaultPort(t *testing.T) {
639652
t.Parallel()
640653
deployment := renderK8SServiceDeploymentWithSetValues(

0 commit comments

Comments
 (0)