Mohammed Naser | 9ad0d46 | 2023-01-15 20:36:37 -0500 | [diff] [blame] | 1 | {{/* vim: set filetype=mustache: */}} |
| 2 | {{/* |
| 3 | Expand the name of the chart. |
| 4 | */}} |
| 5 | {{- define "ingress-nginx.name" -}} |
| 6 | {{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}} |
| 7 | {{- end -}} |
| 8 | |
| 9 | {{/* |
| 10 | Create 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 | {{/* |
| 17 | Create a default fully qualified app name. |
| 18 | We 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 Naser | 65cda13 | 2024-05-02 14:34:08 -0400 | [diff] [blame] | 33 | {{/* |
| 34 | Expand the namespace of the release. |
| 35 | Allows 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 Naser | 9ad0d46 | 2023-01-15 20:36:37 -0500 | [diff] [blame] | 40 | |
| 41 | {{/* |
Mohammed Naser | 65cda13 | 2024-05-02 14:34:08 -0400 | [diff] [blame] | 42 | Controller container security context. |
Mohammed Naser | 9ad0d46 | 2023-01-15 20:36:37 -0500 | [diff] [blame] | 43 | */}} |
Mohammed Naser | 65cda13 | 2024-05-02 14:34:08 -0400 | [diff] [blame] | 44 | {{- define "ingress-nginx.controller.containerSecurityContext" -}} |
Mohammed Naser | 9ad0d46 | 2023-01-15 20:36:37 -0500 | [diff] [blame] | 45 | {{- if .Values.controller.containerSecurityContext -}} |
| 46 | {{- toYaml .Values.controller.containerSecurityContext -}} |
| 47 | {{- else -}} |
Mohammed Naser | 65cda13 | 2024-05-02 14:34:08 -0400 | [diff] [blame] | 48 | runAsNonRoot: {{ .Values.controller.image.runAsNonRoot }} |
| 49 | runAsUser: {{ .Values.controller.image.runAsUser }} |
| 50 | allowPrivilegeEscalation: {{ or .Values.controller.image.allowPrivilegeEscalation .Values.controller.image.chroot }} |
| 51 | {{- if .Values.controller.image.seccompProfile }} |
| 52 | seccompProfile: {{ toYaml .Values.controller.image.seccompProfile | nindent 2 }} |
| 53 | {{- end }} |
Mohammed Naser | 9ad0d46 | 2023-01-15 20:36:37 -0500 | [diff] [blame] | 54 | capabilities: |
| 55 | drop: |
| 56 | - ALL |
| 57 | add: |
| 58 | - NET_BIND_SERVICE |
Mohammed Naser | 65cda13 | 2024-05-02 14:34:08 -0400 | [diff] [blame] | 59 | {{- if .Values.controller.image.chroot }} |
| 60 | {{- if .Values.controller.image.seccompProfile }} |
| 61 | - SYS_ADMIN |
| 62 | {{- end }} |
| 63 | - SYS_CHROOT |
| 64 | {{- end }} |
| 65 | readOnlyRootFilesystem: {{ .Values.controller.image.readOnlyRootFilesystem }} |
| 66 | {{- end -}} |
| 67 | {{- end -}} |
| 68 | |
| 69 | {{/* |
| 70 | Get specific image |
| 71 | */}} |
| 72 | {{- define "ingress-nginx.image" -}} |
| 73 | {{- if .chroot -}} |
| 74 | {{- printf "%s-chroot" .image -}} |
| 75 | {{- else -}} |
| 76 | {{- printf "%s" .image -}} |
Mohammed Naser | 9ad0d46 | 2023-01-15 20:36:37 -0500 | [diff] [blame] | 77 | {{- end }} |
| 78 | {{- end -}} |
| 79 | |
| 80 | {{/* |
Mohammed Naser | 65cda13 | 2024-05-02 14:34:08 -0400 | [diff] [blame] | 81 | Get 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 Naser | 9ad0d46 | 2023-01-15 20:36:37 -0500 | [diff] [blame] | 96 | Create a default fully qualified controller name. |
| 97 | We 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 Naser | 65cda13 | 2024-05-02 14:34:08 -0400 | [diff] [blame] | 104 | Construct a unique electionID. |
| 105 | Users 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 Naser | 9ad0d46 | 2023-01-15 20:36:37 -0500 | [diff] [blame] | 114 | Construct the path for the publish-service. |
| 115 | |
| 116 | By convention this will simply use the <namespace>/<controller-name> to match the name of the |
| 117 | service generated. |
| 118 | |
| 119 | Users can provide an override for an explicit service they want bound via `.Values.controller.publishService.pathOverride` |
Mohammed Naser | 9ad0d46 | 2023-01-15 20:36:37 -0500 | [diff] [blame] | 120 | */}} |
| 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 Naser | 9ad0d46 | 2023-01-15 20:36:37 -0500 | [diff] [blame] | 128 | Common labels |
| 129 | */}} |
| 130 | {{- define "ingress-nginx.labels" -}} |
| 131 | helm.sh/chart: {{ include "ingress-nginx.chart" . }} |
| 132 | {{ include "ingress-nginx.selectorLabels" . }} |
| 133 | {{- if .Chart.AppVersion }} |
| 134 | app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} |
| 135 | {{- end }} |
| 136 | app.kubernetes.io/part-of: {{ template "ingress-nginx.name" . }} |
| 137 | app.kubernetes.io/managed-by: {{ .Release.Service }} |
| 138 | {{- if .Values.commonLabels}} |
| 139 | {{ toYaml .Values.commonLabels }} |
| 140 | {{- end }} |
| 141 | {{- end -}} |
| 142 | |
| 143 | {{/* |
| 144 | Selector labels |
| 145 | */}} |
| 146 | {{- define "ingress-nginx.selectorLabels" -}} |
| 147 | app.kubernetes.io/name: {{ include "ingress-nginx.name" . }} |
| 148 | app.kubernetes.io/instance: {{ .Release.Name }} |
| 149 | {{- end -}} |
| 150 | |
| 151 | {{/* |
| 152 | Create 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 Naser | 65cda13 | 2024-05-02 14:34:08 -0400 | [diff] [blame] | 163 | Create a default fully qualified admission webhook name. |
| 164 | We 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 | {{/* |
| 171 | Create a default fully qualified admission webhook secret creation job name. |
| 172 | We 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 | {{/* |
| 179 | Create a default fully qualified admission webhook patch job name. |
| 180 | We 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 | {{/* |
| 187 | Create a default fully qualified default backend name. |
| 188 | We 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 Naser | 9ad0d46 | 2023-01-15 20:36:37 -0500 | [diff] [blame] | 195 | Create 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 Naser | 65cda13 | 2024-05-02 14:34:08 -0400 | [diff] [blame] | 206 | Default backend container security context. |
| 207 | */}} |
| 208 | {{- define "ingress-nginx.defaultBackend.containerSecurityContext" -}} |
| 209 | {{- if .Values.defaultBackend.containerSecurityContext -}} |
| 210 | {{- toYaml .Values.defaultBackend.containerSecurityContext -}} |
| 211 | {{- else -}} |
| 212 | runAsNonRoot: {{ .Values.defaultBackend.image.runAsNonRoot }} |
| 213 | runAsUser: {{ .Values.defaultBackend.image.runAsUser }} |
| 214 | allowPrivilegeEscalation: {{ .Values.defaultBackend.image.allowPrivilegeEscalation }} |
| 215 | {{- if .Values.defaultBackend.image.seccompProfile }} |
| 216 | seccompProfile: {{ toYaml .Values.defaultBackend.image.seccompProfile | nindent 2 }} |
| 217 | {{- end }} |
| 218 | capabilities: |
| 219 | drop: |
| 220 | - ALL |
| 221 | readOnlyRootFilesystem: {{ .Values.defaultBackend.image.readOnlyRootFilesystem }} |
| 222 | {{- end -}} |
| 223 | {{- end -}} |
| 224 | |
| 225 | {{/* |
Mohammed Naser | 9ad0d46 | 2023-01-15 20:36:37 -0500 | [diff] [blame] | 226 | Return 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 | {{/* |
| 237 | Check 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 Naser | 65cda13 | 2024-05-02 14:34:08 -0400 | [diff] [blame] | 246 | Extra 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 -}} |