blob: 9ac2dc5696f6c07b5eb48a9f32ee99760936c686 [file] [log] [blame]
Mohammed Naser9ad0d462023-01-15 20:36:37 -05001{{/* vim: set filetype=mustache: */}}
2{{/*
3Expand the name of the chart.
4*/}}
5{{- define "ingress-nginx.name" -}}
6{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
7{{- end -}}
8
9{{/*
10Create chart name and version as used by the chart label.
11*/}}
12{{- define "ingress-nginx.chart" -}}
13{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
14{{- end -}}
15
16{{/*
17Create a default fully qualified app name.
18We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
19*/}}
20{{- define "ingress-nginx.fullname" -}}
21{{- if .Values.fullnameOverride -}}
22{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}}
23{{- else -}}
24{{- $name := default .Chart.Name .Values.nameOverride -}}
25{{- if contains $name .Release.Name -}}
26{{- .Release.Name | trunc 63 | trimSuffix "-" -}}
27{{- else -}}
28{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
29{{- end -}}
30{{- end -}}
31{{- end -}}
32
Mohammed Naser65cda132024-05-02 14:34:08 -040033{{/*
34Expand the namespace of the release.
35Allows overriding it for multi-namespace deployments in combined charts.
36*/}}
37{{- define "ingress-nginx.namespace" -}}
38{{- default .Release.Namespace .Values.namespaceOverride | trunc 63 | trimSuffix "-" -}}
39{{- end -}}
Mohammed Naser9ad0d462023-01-15 20:36:37 -050040
41{{/*
Mohammed Naser65cda132024-05-02 14:34:08 -040042Controller container security context.
Mohammed Naser9ad0d462023-01-15 20:36:37 -050043*/}}
Mohammed Naser65cda132024-05-02 14:34:08 -040044{{- define "ingress-nginx.controller.containerSecurityContext" -}}
Mohammed Naser9ad0d462023-01-15 20:36:37 -050045{{- if .Values.controller.containerSecurityContext -}}
46{{- toYaml .Values.controller.containerSecurityContext -}}
47{{- else -}}
Mohammed Naser65cda132024-05-02 14:34:08 -040048runAsNonRoot: {{ .Values.controller.image.runAsNonRoot }}
49runAsUser: {{ .Values.controller.image.runAsUser }}
50allowPrivilegeEscalation: {{ or .Values.controller.image.allowPrivilegeEscalation .Values.controller.image.chroot }}
51{{- if .Values.controller.image.seccompProfile }}
52seccompProfile: {{ toYaml .Values.controller.image.seccompProfile | nindent 2 }}
53{{- end }}
Mohammed Naser9ad0d462023-01-15 20:36:37 -050054capabilities:
55 drop:
56 - ALL
57 add:
58 - NET_BIND_SERVICE
Mohammed Naser65cda132024-05-02 14:34:08 -040059 {{- if .Values.controller.image.chroot }}
60 {{- if .Values.controller.image.seccompProfile }}
61 - SYS_ADMIN
62 {{- end }}
63 - SYS_CHROOT
64 {{- end }}
65readOnlyRootFilesystem: {{ .Values.controller.image.readOnlyRootFilesystem }}
66{{- end -}}
67{{- end -}}
68
69{{/*
70Get specific image
71*/}}
72{{- define "ingress-nginx.image" -}}
73{{- if .chroot -}}
74{{- printf "%s-chroot" .image -}}
75{{- else -}}
76{{- printf "%s" .image -}}
Mohammed Naser9ad0d462023-01-15 20:36:37 -050077{{- end }}
78{{- end -}}
79
80{{/*
Mohammed Naser65cda132024-05-02 14:34:08 -040081Get specific image digest
82*/}}
83{{- define "ingress-nginx.imageDigest" -}}
84{{- if .chroot -}}
85{{- if .digestChroot -}}
86{{- printf "@%s" .digestChroot -}}
87{{- end }}
88{{- else -}}
89{{ if .digest -}}
90{{- printf "@%s" .digest -}}
91{{- end -}}
92{{- end -}}
93{{- end -}}
94
95{{/*
Mohammed Naser9ad0d462023-01-15 20:36:37 -050096Create a default fully qualified controller name.
97We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
98*/}}
99{{- define "ingress-nginx.controller.fullname" -}}
100{{- printf "%s-%s" (include "ingress-nginx.fullname" .) .Values.controller.name | trunc 63 | trimSuffix "-" -}}
101{{- end -}}
102
103{{/*
Mohammed Naser65cda132024-05-02 14:34:08 -0400104Construct a unique electionID.
105Users can provide an override for an explicit electionID if they want via `.Values.controller.electionID`
106*/}}
107{{- define "ingress-nginx.controller.electionID" -}}
108{{- $defElectionID := printf "%s-leader" (include "ingress-nginx.fullname" .) -}}
109{{- $electionID := default $defElectionID .Values.controller.electionID -}}
110{{- print $electionID -}}
111{{- end -}}
112
113{{/*
Mohammed Naser9ad0d462023-01-15 20:36:37 -0500114Construct the path for the publish-service.
115
116By convention this will simply use the <namespace>/<controller-name> to match the name of the
117service generated.
118
119Users can provide an override for an explicit service they want bound via `.Values.controller.publishService.pathOverride`
Mohammed Naser9ad0d462023-01-15 20:36:37 -0500120*/}}
121{{- define "ingress-nginx.controller.publishServicePath" -}}
122{{- $defServiceName := printf "%s/%s" "$(POD_NAMESPACE)" (include "ingress-nginx.controller.fullname" .) -}}
123{{- $servicePath := default $defServiceName .Values.controller.publishService.pathOverride }}
124{{- print $servicePath | trimSuffix "-" -}}
125{{- end -}}
126
127{{/*
Mohammed Naser9ad0d462023-01-15 20:36:37 -0500128Common labels
129*/}}
130{{- define "ingress-nginx.labels" -}}
131helm.sh/chart: {{ include "ingress-nginx.chart" . }}
132{{ include "ingress-nginx.selectorLabels" . }}
133{{- if .Chart.AppVersion }}
134app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
135{{- end }}
136app.kubernetes.io/part-of: {{ template "ingress-nginx.name" . }}
137app.kubernetes.io/managed-by: {{ .Release.Service }}
138{{- if .Values.commonLabels}}
139{{ toYaml .Values.commonLabels }}
140{{- end }}
141{{- end -}}
142
143{{/*
144Selector labels
145*/}}
146{{- define "ingress-nginx.selectorLabels" -}}
147app.kubernetes.io/name: {{ include "ingress-nginx.name" . }}
148app.kubernetes.io/instance: {{ .Release.Name }}
149{{- end -}}
150
151{{/*
152Create the name of the controller service account to use
153*/}}
154{{- define "ingress-nginx.serviceAccountName" -}}
155{{- if .Values.serviceAccount.create -}}
156 {{ default (include "ingress-nginx.fullname" .) .Values.serviceAccount.name }}
157{{- else -}}
158 {{ default "default" .Values.serviceAccount.name }}
159{{- end -}}
160{{- end -}}
161
162{{/*
Mohammed Naser65cda132024-05-02 14:34:08 -0400163Create a default fully qualified admission webhook name.
164We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
165*/}}
166{{- define "ingress-nginx.admissionWebhooks.fullname" -}}
167{{- printf "%s-%s" (include "ingress-nginx.fullname" .) .Values.controller.admissionWebhooks.name | trunc 63 | trimSuffix "-" -}}
168{{- end -}}
169
170{{/*
171Create a default fully qualified admission webhook secret creation job name.
172We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
173*/}}
174{{- define "ingress-nginx.admissionWebhooks.createSecretJob.fullname" -}}
175{{- printf "%s-%s" (include "ingress-nginx.admissionWebhooks.fullname" .) .Values.controller.admissionWebhooks.createSecretJob.name | trunc 63 | trimSuffix "-" -}}
176{{- end -}}
177
178{{/*
179Create a default fully qualified admission webhook patch job name.
180We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
181*/}}
182{{- define "ingress-nginx.admissionWebhooks.patchWebhookJob.fullname" -}}
183{{- printf "%s-%s" (include "ingress-nginx.admissionWebhooks.fullname" .) .Values.controller.admissionWebhooks.patchWebhookJob.name | trunc 63 | trimSuffix "-" -}}
184{{- end -}}
185
186{{/*
187Create a default fully qualified default backend name.
188We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
189*/}}
190{{- define "ingress-nginx.defaultBackend.fullname" -}}
191{{- printf "%s-%s" (include "ingress-nginx.fullname" .) .Values.defaultBackend.name | trunc 63 | trimSuffix "-" -}}
192{{- end -}}
193
194{{/*
Mohammed Naser9ad0d462023-01-15 20:36:37 -0500195Create the name of the backend service account to use - only used when podsecuritypolicy is also enabled
196*/}}
197{{- define "ingress-nginx.defaultBackend.serviceAccountName" -}}
198{{- if .Values.defaultBackend.serviceAccount.create -}}
199 {{ default (printf "%s-backend" (include "ingress-nginx.fullname" .)) .Values.defaultBackend.serviceAccount.name }}
200{{- else -}}
201 {{ default "default-backend" .Values.defaultBackend.serviceAccount.name }}
202{{- end -}}
203{{- end -}}
204
205{{/*
Mohammed Naser65cda132024-05-02 14:34:08 -0400206Default backend container security context.
207*/}}
208{{- define "ingress-nginx.defaultBackend.containerSecurityContext" -}}
209{{- if .Values.defaultBackend.containerSecurityContext -}}
210{{- toYaml .Values.defaultBackend.containerSecurityContext -}}
211{{- else -}}
212runAsNonRoot: {{ .Values.defaultBackend.image.runAsNonRoot }}
213runAsUser: {{ .Values.defaultBackend.image.runAsUser }}
214allowPrivilegeEscalation: {{ .Values.defaultBackend.image.allowPrivilegeEscalation }}
215{{- if .Values.defaultBackend.image.seccompProfile }}
216seccompProfile: {{ toYaml .Values.defaultBackend.image.seccompProfile | nindent 2 }}
217{{- end }}
218capabilities:
219 drop:
220 - ALL
221readOnlyRootFilesystem: {{ .Values.defaultBackend.image.readOnlyRootFilesystem }}
222{{- end -}}
223{{- end -}}
224
225{{/*
Mohammed Naser9ad0d462023-01-15 20:36:37 -0500226Return the appropriate apiGroup for PodSecurityPolicy.
227*/}}
228{{- define "podSecurityPolicy.apiGroup" -}}
229{{- if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}}
230{{- print "policy" -}}
231{{- else -}}
232{{- print "extensions" -}}
233{{- end -}}
234{{- end -}}
235
236{{/*
237Check the ingress controller version tag is at most three versions behind the last release
238*/}}
239{{- define "isControllerTagValid" -}}
240{{- if not (semverCompare ">=0.27.0-0" .Values.controller.image.tag) -}}
241{{- fail "Controller container image tag should be 0.27.0 or higher" -}}
242{{- end -}}
243{{- end -}}
244
245{{/*
Mohammed Naser65cda132024-05-02 14:34:08 -0400246Extra modules.
247*/}}
248{{- define "extraModules" -}}
249- name: {{ .name }}
250 {{- with .image }}
251 image: {{ if .repository }}{{ .repository }}{{ else }}{{ .registry }}/{{ .image }}{{ end }}:{{ .tag }}{{ if .digest }}@{{ .digest }}{{ end }}
252 command:
253 {{- if .distroless }}
254 - /init_module
255 {{- else }}
256 - sh
257 - -c
258 - /usr/local/bin/init_module.sh
259 {{- end }}
260 {{- end }}
261 {{- if .containerSecurityContext }}
262 securityContext: {{ toYaml .containerSecurityContext | nindent 4 }}
263 {{- end }}
264 {{- if .resources }}
265 resources: {{ toYaml .resources | nindent 4 }}
266 {{- end }}
267 volumeMounts:
268 - name: modules
269 mountPath: /modules_mount
270{{- end -}}