1 {{/* vim: set filetype=mustache: */}}
3 Create a default fully qualified app name.
4 We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
7 {{- define "kong.name" -}}
8 {{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
11 {{- define "kong.fullname" -}}
12 {{- $name := default .Chart.Name .Values.nameOverride -}}
13 {{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
16 {{- define "kong.chart" -}}
17 {{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
20 {{- define "kong.metaLabels" -}}
21 app.kubernetes.io/name: {{ template "kong.name" . }}
22 helm.sh/chart: {{ template "kong.chart" . }}
23 app.kubernetes.io/instance: "{{ .Release.Name }}"
24 app.kubernetes.io/managed-by: "{{ .Release.Service }}"
25 app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
28 {{- define "kong.selectorLabels" -}}
29 app.kubernetes.io/name: {{ template "kong.name" . }}
30 app.kubernetes.io/component: app
31 app.kubernetes.io/instance: "{{ .Release.Name }}"
34 {{- define "kong.postgresql.fullname" -}}
35 {{- $name := default "postgresql" .Values.postgresql.nameOverride -}}
36 {{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
39 {{- define "kong.dblessConfig.fullname" -}}
40 {{- $name := default "kong-custom-dbless-config" .Values.dblessConfig.nameOverride -}}
41 {{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
45 Create the name of the service account to use
47 {{- define "kong.serviceAccountName" -}}
48 {{- if .Values.ingressController.serviceAccount.create -}}
49 {{ default (include "kong.fullname" .) .Values.ingressController.serviceAccount.name }}
51 {{ default "default" .Values.ingressController.serviceAccount.name }}
56 Create the KONG_PROXY_LISTEN value string
58 {{- define "kong.kongProxyListenValue" -}}
60 {{- if and .Values.proxy.http.enabled .Values.proxy.tls.enabled -}}
61 0.0.0.0:{{ .Values.proxy.http.containerPort }},0.0.0.0:{{ .Values.proxy.tls.containerPort }} ssl
63 {{- if .Values.proxy.http.enabled -}}
64 0.0.0.0:{{ .Values.proxy.http.containerPort }}
66 {{- if .Values.proxy.tls.enabled -}}
67 0.0.0.0:{{ .Values.proxy.tls.containerPort }} ssl
74 Create the KONG_ADMIN_GUI_LISTEN value string
76 {{- define "kong.kongManagerListenValue" -}}
78 {{- if and .Values.manager.http.enabled .Values.manager.tls.enabled -}}
79 0.0.0.0:{{ .Values.manager.http.containerPort }},0.0.0.0:{{ .Values.manager.tls.containerPort }} ssl
81 {{- if .Values.manager.http.enabled -}}
82 0.0.0.0:{{ .Values.manager.http.containerPort }}
84 {{- if .Values.manager.tls.enabled -}}
85 0.0.0.0:{{ .Values.manager.tls.containerPort }} ssl
92 Create the KONG_PORTAL_GUI_LISTEN value string
94 {{- define "kong.kongPortalListenValue" -}}
96 {{- if and .Values.portal.http.enabled .Values.portal.tls.enabled -}}
97 0.0.0.0:{{ .Values.portal.http.containerPort }},0.0.0.0:{{ .Values.portal.tls.containerPort }} ssl
99 {{- if .Values.portal.http.enabled -}}
100 0.0.0.0:{{ .Values.portal.http.containerPort }}
102 {{- if .Values.portal.tls.enabled -}}
103 0.0.0.0:{{ .Values.portal.tls.containerPort }} ssl
110 Create the KONG_PORTAL_API_LISTEN value string
112 {{- define "kong.kongPortalApiListenValue" -}}
114 {{- if and .Values.portalapi.http.enabled .Values.portalapi.tls.enabled -}}
115 0.0.0.0:{{ .Values.portalapi.http.containerPort }},0.0.0.0:{{ .Values.portalapi.tls.containerPort }} ssl
117 {{- if .Values.portalapi.http.enabled -}}
118 0.0.0.0:{{ .Values.portalapi.http.containerPort }}
120 {{- if .Values.portalapi.tls.enabled -}}
121 0.0.0.0:{{ .Values.portalapi.tls.containerPort }} ssl
128 Create the ingress servicePort value string
131 {{- define "kong.ingress.servicePort" -}}
132 {{- if .tls.enabled -}}
133 {{ .tls.servicePort }}
135 {{ .http.servicePort }}
140 Generate an appropriate external URL from a Kong service's ingress configuration
141 Strips trailing slashes from the path. Manager at least does not handle these
142 intelligently and will append its own slash regardless, and the admin API cannot handle
146 {{- define "kong.ingress.serviceUrl" -}}
148 https://{{ .hostname }}{{ .path | trimSuffix "/" }}
150 http://{{ .hostname }}{{ .path | trimSuffix "/" }}
155 The name of the service used for the ingress controller's validation webhook
158 {{- define "kong.service.validationWebhook" -}}
159 {{ include "kong.fullname" . }}-validation-webhook
162 {{- define "kong.env" -}}
163 {{- range $key, $val := .Values.env }}
164 - name: KONG_{{ $key | upper}}
165 {{- $valueType := printf "%T" $val -}}
166 {{ if eq $valueType "map[string]interface {}" }}
167 {{ toYaml $val | indent 2 -}}
169 value: {{ $val | quote -}}
174 {{- define "kong.ingressController.env" -}}
175 {{- range $key, $val := .Values.ingressController.env }}
176 - name: CONTROLLER_{{ $key | upper}}
177 {{- $valueType := printf "%T" $val -}}
178 {{ if eq $valueType "map[string]interface {}" }}
179 {{ toYaml $val | indent 2 -}}
181 value: {{ $val | quote -}}
186 {{- define "kong.volumes" -}}
187 - name: {{ template "kong.fullname" . }}-prefix-dir
189 - name: {{ template "kong.fullname" . }}-tmp
191 {{- range .Values.plugins.configMaps }}
192 - name: kong-plugin-{{ .pluginName }}
196 {{- range .Values.plugins.secrets }}
197 - name: kong-plugin-{{ .pluginName }}
199 secretName: {{ .name }}
201 - name: custom-nginx-template-volume
203 name: {{ template "kong.fullname" . }}-default-custom-server-blocks
204 {{- if (and (not .Values.ingressController.enabled) (eq .Values.env.database "off")) }}
205 - name: kong-custom-dbless-config-volume
207 {{- if .Values.dblessConfig.configMap }}
208 name: {{ .Values.dblessConfig.configMap }}
210 name: {{ template "kong.dblessConfig.fullname" . }}
213 {{- if .Values.ingressController.admissionWebhook.enabled }}
216 secretName: {{ template "kong.fullname" . }}-validation-webhook-keypair
218 {{- range $secretVolume := .Values.secretVolumes }}
225 {{- define "kong.volumeMounts" -}}
226 - name: {{ template "kong.fullname" . }}-prefix-dir
227 mountPath: /kong_prefix/
228 - name: {{ template "kong.fullname" . }}-tmp
230 - name: custom-nginx-template-volume
232 {{- if (and (not .Values.ingressController.enabled) (eq .Values.env.database "off")) }}
233 - name: kong-custom-dbless-config-volume
234 mountPath: /kong_dbless/
236 {{- range .Values.secretVolumes }}
238 mountPath: /etc/secrets/{{ . }}
240 {{- range .Values.plugins.configMaps }}
241 - name: kong-plugin-{{ .pluginName }}
242 mountPath: /opt/kong/plugins/{{ .pluginName }}
245 {{- range .Values.plugins.secrets }}
246 - name: kong-plugin-{{ .pluginName }}
247 mountPath: /opt/kong/plugins/{{ .pluginName }}
252 {{- define "kong.plugins" -}}
253 {{ $myList := list "bundled" }}
254 {{- range .Values.plugins.configMaps -}}
255 {{- $myList = append $myList .pluginName -}}
257 {{- range .Values.plugins.secrets -}}
258 {{ $myList = append $myList .pluginName -}}
260 {{- $myList | join "," -}}
263 {{- define "kong.wait-for-db" -}}
265 image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
266 imagePullPolicy: {{ .Values.image.pullPolicy }}
268 {{- if .Values.enterprise.enabled }}
269 {{- include "kong.license" . | nindent 2 }}
271 {{- if .Values.postgresql.enabled }}
273 value: {{ template "kong.postgresql.fullname" . }}
275 value: "{{ .Values.postgresql.service.port }}"
276 - name: KONG_PG_PASSWORD
279 name: {{ template "kong.postgresql.fullname" . }}
280 key: postgresql-password
282 - name: KONG_LUA_PACKAGE_PATH
283 value: "/opt/?.lua;;"
285 value: {{ template "kong.plugins" . }}
286 {{- include "kong.env" . | nindent 2 }}
287 command: [ "/bin/sh", "-c", "until kong start; do echo 'waiting for db'; sleep 1; done; kong stop" ]
289 {{- include "kong.volumeMounts" . | nindent 4 }}
292 {{- define "kong.controller-container" -}}
293 - name: ingress-controller
295 - /kong-ingress-controller
296 # Service from were we extract the IP address/es to use in Ingress status
297 - --publish-service={{ .Release.Namespace }}/{{ template "kong.fullname" . }}-proxy
298 # Set the ingress class
299 - --ingress-class={{ .Values.ingressController.ingressClass }}
300 - --election-id=kong-ingress-controller-leader-{{ .Values.ingressController.ingressClass }}
301 # the kong URL points to the kong admin api server
302 {{- if .Values.admin.useTLS }}
303 - --kong-url=https://localhost:{{ .Values.admin.containerPort }}
304 - --admin-tls-skip-verify # TODO make this configurable
306 - --kong-url=http://localhost:{{ .Values.admin.containerPort }}
308 {{- if .Values.ingressController.admissionWebhook.enabled }}
309 - --admission-webhook-listen=0.0.0.0:{{ .Values.ingressController.admissionWebhook.port }}
316 fieldPath: metadata.name
317 - name: POD_NAMESPACE
321 fieldPath: metadata.namespace
322 {{- include "kong.ingressController.env" . | indent 2 }}
323 image: "{{ .Values.ingressController.image.repository }}:{{ .Values.ingressController.image.tag }}"
324 imagePullPolicy: {{ .Values.image.pullPolicy }}
326 {{ toYaml .Values.ingressController.readinessProbe | indent 4 }}
328 {{ toYaml .Values.ingressController.livenessProbe | indent 4 }}
330 {{ toYaml .Values.ingressController.resources | indent 4 }}
331 {{- if .Values.ingressController.admissionWebhook.enabled }}
334 mountPath: /admission-webhook
340 Retrieve Kong Enterprise license from a secret and make it available in env vars
342 {{- define "kong.license" -}}
343 - name: KONG_LICENSE_DATA
346 name: {{ .Values.enterprise.license_secret }}
351 Use the Pod security context defined in Values or set the UID by default
353 {{- define "kong.podsecuritycontext" -}}
354 {{ .Values.securityContext | toYaml }}
358 The environment values passed to Kong; this should come after all
359 the template that it itself is using form the above sections.
361 {{- define "kong.final_env" -}}
362 - name: KONG_LUA_PACKAGE_PATH
363 value: "/opt/?.lua;;"
364 {{- if not .Values.env.admin_listen }}
365 {{- if .Values.admin.useTLS }}
366 - name: KONG_ADMIN_LISTEN
367 value: "0.0.0.0:{{ .Values.admin.containerPort }} ssl"
369 - name: KONG_ADMIN_LISTEN
370 value: 0.0.0.0:{{ .Values.admin.containerPort }}
373 {{- if .Values.admin.ingress.enabled }}
374 - name: KONG_ADMIN_API_URI
375 value: {{ include "kong.ingress.serviceUrl" .Values.admin.ingress }}
377 {{- if not .Values.env.proxy_listen }}
378 - name: KONG_PROXY_LISTEN
379 value: {{ template "kong.kongProxyListenValue" . }}
381 {{- if and (not .Values.env.admin_gui_listen) (.Values.enterprise.enabled) }}
382 - name: KONG_ADMIN_GUI_LISTEN
383 value: {{ template "kong.kongManagerListenValue" . }}
385 {{- if and (.Values.manager.ingress.enabled) (.Values.enterprise.enabled) }}
386 - name: KONG_ADMIN_GUI_URL
387 value: {{ include "kong.ingress.serviceUrl" .Values.manager.ingress }}
389 {{- if and (not .Values.env.portal_gui_listen) (.Values.enterprise.enabled) (.Values.enterprise.portal.enabled) }}
390 - name: KONG_PORTAL_GUI_LISTEN
391 value: {{ template "kong.kongPortalListenValue" . }}
393 {{- if and (.Values.portal.ingress.enabled) (.Values.enterprise.enabled) (.Values.enterprise.portal.enabled) }}
394 - name: KONG_PORTAL_GUI_HOST
395 value: {{ .Values.portal.ingress.hostname }}
396 {{- if .Values.portal.ingress.tls }}
397 - name: KONG_PORTAL_GUI_PROTOCOL
400 - name: KONG_PORTAL_GUI_PROTOCOL
404 {{- if and (not .Values.env.portal_api_listen) (.Values.enterprise.enabled) (.Values.enterprise.portal.enabled) }}
405 - name: KONG_PORTAL_API_LISTEN
406 value: {{ template "kong.kongPortalApiListenValue" . }}
408 {{- if and (.Values.portalapi.ingress.enabled) (.Values.enterprise.enabled) (.Values.enterprise.portal.enabled) }}
409 - name: KONG_PORTAL_API_URL
410 value: {{ include "kong.ingress.serviceUrl" .Values.portalapi.ingress }}
412 - name: KONG_NGINX_DAEMON
414 {{- if .Values.enterprise.enabled }}
415 {{- if not .Values.enterprise.vitals.enabled }}
419 {{- if .Values.enterprise.portal.enabled }}
422 {{- if .Values.enterprise.portal.portal_auth }}
423 - name: KONG_PORTAL_AUTH
424 value: {{ .Values.enterprise.portal.portal_auth }}
425 - name: KONG_PORTAL_SESSION_CONF
428 name: {{ .Values.enterprise.portal.session_conf_secret }}
429 key: portal_session_conf
432 {{- if .Values.enterprise.rbac.enabled }}
433 - name: KONG_ENFORCE_RBAC
435 - name: KONG_ADMIN_GUI_AUTH
436 value: {{ .Values.enterprise.rbac.admin_gui_auth | default "basic-auth" }}
437 {{- if not (eq .Values.enterprise.rbac.admin_gui_auth "basic-auth") }}
438 - name: KONG_ADMIN_GUI_AUTH_CONF
441 name: {{ .Values.enterprise.rbac.admin_gui_auth_conf_secret }}
442 key: admin_gui_auth_conf
444 - name: KONG_ADMIN_GUI_SESSION_CONF
447 name: {{ .Values.enterprise.rbac.session_conf_secret }}
448 key: admin_gui_session_conf
450 {{- if .Values.enterprise.smtp.enabled }}
451 - name: KONG_PORTAL_EMAILS_FROM
452 value: {{ .Values.enterprise.smtp.portal_emails_from }}
453 - name: KONG_PORTAL_EMAILS_REPLY_TO
454 value: {{ .Values.enterprise.smtp.portal_emails_reply_to }}
455 - name: KONG_ADMIN_EMAILS_FROM
456 value: {{ .Values.enterprise.smtp.admin_emails_from }}
457 - name: KONG_ADMIN_EMAILS_REPLY_TO
458 value: {{ .Values.enterprise.smtp.admin_emails_reply_to }}
459 - name: KONG_SMTP_HOST
460 value: {{ .Values.enterprise.smtp.smtp_host }}
461 - name: KONG_SMTP_PORT
462 value: {{ .Values.enterprise.smtp.smtp_port | quote }}
463 - name: KONG_SMTP_STARTTLS
464 value: {{ .Values.enterprise.smtp.smtp_starttls | quote }}
465 {{- if .Values.enterprise.smtp.auth.smtp_username }}
466 - name: KONG_SMTP_USERNAME
467 value: {{ .Values.enterprise.smtp.auth.smtp_username }}
468 - name: KONG_SMTP_PASSWORD
471 name: {{ .Values.enterprise.smtp.auth.smtp_password_secret }}
475 - name: KONG_SMTP_MOCK
478 {{ include "kong.license" . }}
480 - name: KONG_NGINX_HTTP_INCLUDE
481 value: /kong/servers.conf
482 {{- if .Values.postgresql.enabled }}
484 value: {{ template "kong.postgresql.fullname" . }}
486 value: "{{ .Values.postgresql.service.port }}"
487 - name: KONG_PG_PASSWORD
490 name: {{ template "kong.postgresql.fullname" . }}
491 key: postgresql-password
493 {{- if (and (not .Values.ingressController.enabled) (eq .Values.env.database "off")) }}
494 - name: KONG_DECLARATIVE_CONFIG
495 value: "/kong_dbless/kong.yml"
498 value: {{ template "kong.plugins" . }}
499 {{- include "kong.env" . }}
502 {{- define "kong.wait-for-postgres" -}}
503 - name: wait-for-postgres
504 image: "{{ .Values.waitImage.repository }}:{{ .Values.waitImage.tag }}"
505 imagePullPolicy: {{ .Values.waitImage.pullPolicy }}
507 {{- include "kong.final_env" . | nindent 2 }}
508 command: [ "/bin/sh", "-c", "until nc -zv $KONG_PG_HOST $KONG_PG_PORT -w1; do echo 'waiting for db'; sleep 1; done" ]