Skip to content

Commit cd3c6fb

Browse files
fdroletlmiGacko
andauthored
Chart: Make extra init containers templatable. (#14070)
Co-authored-by: Marco Ebert <[email protected]>
1 parent fd4c8ac commit cd3c6fb

File tree

6 files changed

+45
-4
lines changed

6 files changed

+45
-4
lines changed

charts/ingress-nginx/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ metadata:
335335
| controller.extraArgs | object | `{}` | Additional command line arguments to pass to Ingress-Nginx Controller E.g. to specify the default SSL certificate you can use |
336336
| controller.extraContainers | list | `[]` | Additional containers to be added to the controller pod. See https://github.com/lemonldap-ng-controller/lemonldap-ng-controller as example. |
337337
| controller.extraEnvs | list | `[]` | Additional environment variables to set |
338-
| controller.extraInitContainers | list | `[]` | Containers, which are run before the app containers are started. |
338+
| controller.extraInitContainers | list | `[]` | Containers, which are run before the app containers are started. Values may contain Helm templates. |
339339
| controller.extraModules | list | `[]` | Modules, which are mounted into the core nginx image. |
340340
| controller.extraVolumeMounts | list | `[]` | Additional volumeMounts to the controller main container. |
341341
| controller.extraVolumes | list | `[]` | Additional volumes to the controller pod. |

charts/ingress-nginx/templates/controller-daemonset.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ spec:
185185
{{- if (or .Values.controller.extraInitContainers .Values.controller.extraModules) }}
186186
initContainers:
187187
{{- if .Values.controller.extraInitContainers }}
188-
{{- toYaml .Values.controller.extraInitContainers | nindent 8 }}
188+
{{- tpl (toYaml .Values.controller.extraInitContainers) $ | nindent 8 }}
189189
{{- end }}
190190
{{- if .Values.controller.extraModules }}
191191
{{- range .Values.controller.extraModules }}

charts/ingress-nginx/templates/controller-deployment.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ spec:
191191
{{- if (or .Values.controller.extraInitContainers .Values.controller.extraModules) }}
192192
initContainers:
193193
{{- if .Values.controller.extraInitContainers }}
194-
{{- toYaml .Values.controller.extraInitContainers | nindent 8 }}
194+
{{- tpl (toYaml .Values.controller.extraInitContainers) $ | nindent 8 }}
195195
{{- end }}
196196
{{- if .Values.controller.extraModules }}
197197
{{- range .Values.controller.extraModules }}

charts/ingress-nginx/tests/controller-daemonset_test.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,24 @@ tests:
9696
maxSkew: 1
9797
whenUnsatisfiable: ScheduleAnyway
9898

99+
- it: should create a DaemonSet with templated init containers if `controller.extraInitContainers` contains Helm templates
100+
set:
101+
controller.kind: DaemonSet
102+
controller.extraInitContainers:
103+
- name: '{{ .Release.Name }}-init'
104+
image: busybox
105+
command:
106+
- sh
107+
- -c
108+
- echo '{{ .Release.Namespace }}';
109+
asserts:
110+
- equal:
111+
path: spec.template.spec.initContainers[0].name
112+
value: RELEASE-NAME-init
113+
- contains:
114+
path: spec.template.spec.initContainers[0].command
115+
content: echo 'NAMESPACE';
116+
99117
- it: should create a DaemonSet with affinity if `controller.affinity` is set
100118
set:
101119
controller.kind: DaemonSet

charts/ingress-nginx/tests/controller-deployment_test.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,23 @@ tests:
119119
maxSkew: 1
120120
whenUnsatisfiable: ScheduleAnyway
121121

122+
- it: should create a Deployment with templated init containers if `controller.extraInitContainers` contains Helm templates
123+
set:
124+
controller.extraInitContainers:
125+
- name: '{{ .Release.Name }}-init'
126+
image: busybox
127+
command:
128+
- sh
129+
- -c
130+
- echo '{{ .Release.Namespace }}';
131+
asserts:
132+
- equal:
133+
path: spec.template.spec.initContainers[0].name
134+
value: RELEASE-NAME-init
135+
- contains:
136+
path: spec.template.spec.initContainers[0].command
137+
content: echo 'NAMESPACE';
138+
122139
- it: should create a Deployment with affinity if `controller.affinity` is set
123140
set:
124141
controller.affinity:

charts/ingress-nginx/values.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -709,11 +709,17 @@ controller:
709709
# - name: copy-portal-skins
710710
# emptyDir: {}
711711

712-
# -- Containers, which are run before the app containers are started.
712+
# -- Containers, which are run before the app containers are started. Values may contain Helm templates.
713713
extraInitContainers: []
714714
# - name: init-myservice
715715
# image: busybox
716716
# command: ['sh', '-c', 'until nslookup myservice; do echo waiting for myservice; sleep 2; done;']
717+
# - name: init-dynamic
718+
# image: busybox
719+
# command:
720+
# - sh
721+
# - -c
722+
# - echo "Release={{ .Release.Name }} Namespace={{ .Release.Namespace }}"
717723

718724
# -- Modules, which are mounted into the core nginx image.
719725
extraModules: []

0 commit comments

Comments
 (0)