Skip to content

Commit

Permalink
feature/init-containers (#104)
Browse files Browse the repository at this point in the history
* adding initContainers property

* indentation

* adding doc and unit test

* formatting

Co-authored-by: David Salas <dsalas@alteryx.com>
  • Loading branch information
davidlivingrooms and David Salas committed Aug 25, 2021
1 parent cb199b7 commit 2244a55
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
9 changes: 9 additions & 0 deletions charts/k8s-service/templates/_deployment_spec.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,15 @@ spec:
{{ toYaml $value | indent 10 }}
{{- end }}
{{- if gt (len .Values.initContainers) 0 }}
initContainers:
{{- range $key, $value := .Values.initContainers }}
- name: {{ $key }}
{{ toYaml $value | indent 10 }}
{{- end }}
{{- end }}
{{- /* START IMAGE PULL SECRETS LOGIC */ -}}
{{- if gt (len .Values.imagePullSecrets) 0 }}
imagePullSecrets:
Expand Down
18 changes: 18 additions & 0 deletions charts/k8s-service/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,24 @@ shutdownDelay: 5
# value: docker
sideCarContainers: {}

# initContainers specifies any additional containers that should be deployed as init containers to the main application
# container. This will be included in the Deployment container spec so that it will be included in the application Pod.
# This is a nested map, where the first map key is used to name the container, with the nested map being injected as the
# container spec.
#
# The following example specifies a flyway image as an init container with an environment variable, binding the
# name `flyway`:
#
# EXAMPLE:
#
# initContainers:
# flyway:
# image: flyway/flyway
# env:
# - name: FLYWAY_LOCATIONS
# value: 'filesystem:/flyway/migrations'
initContainers: {}

# canary specifies test pod(s) that are deployed alongside your application's stable track pods.
# It is useful for testing a new release candidate in a production environment with minimal disruption and
# for allowing you to find any issues early.
Expand Down
13 changes: 13 additions & 0 deletions test/k8s_service_template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,19 @@ func TestK8SServiceSideCarContainersRendersCorrectly(t *testing.T) {
assert.Equal(t, sideCarContainer.Image, "datadog/agent:latest")
}

func TestK8SServiceInitContainersRendersCorrectly(t *testing.T) {
t.Parallel()
deployment := renderK8SServiceDeploymentWithSetValues(
t,
map[string]string{
"initContainers.flyway.image": "flyway/flyway",
},
)
renderedContainers := deployment.Spec.Template.Spec.InitContainers
require.Equal(t, len(renderedContainers), 1)
assert.Equal(t, renderedContainers[0].Image, "flyway/flyway")
}

func TestK8SServiceDisableDefaultPort(t *testing.T) {
t.Parallel()
deployment := renderK8SServiceDeploymentWithSetValues(
Expand Down

0 comments on commit 2244a55

Please sign in to comment.