2dab586950dd13072871ebada6d950d5e8b84c9d
[ric-plt/ric-dep.git] / helm / infrastructure / subcharts / kong / templates / _helpers.tpl
1 {{/* vim: set filetype=mustache: */}}
2 {{/*
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).
5 */}}
6
7 {{- define "kong.namespace" -}}
8 {{- default .Release.Namespace .Values.namespace -}}
9 {{- end -}}
10
11 {{- define "kong.release" -}}
12 {{- default .Release.Name -}}
13 {{- end -}}
14
15 {{- define "kong.name" -}}
16 {{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
17 {{- end -}}
18
19 {{- define "kong.fullname" -}}
20 {{- $name := default .Chart.Name .Values.nameOverride -}}
21 {{- default (printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-") .Values.fullnameOverride -}}
22 {{- end -}}
23
24 {{- define "kong.chart" -}}
25 {{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
26 {{- end -}}
27
28 {{- define "kong.metaLabels" -}}
29 app.kubernetes.io/name: {{ template "kong.name" . }}
30 helm.sh/chart: {{ template "kong.chart" . }}
31 app.kubernetes.io/instance: "{{ .Release.Name }}"
32 app.kubernetes.io/managed-by: "{{ .Release.Service }}"
33 app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
34 {{- range $key, $value := .Values.extraLabels }}
35 {{ $key }}: {{ include "kong.renderTpl" (dict "value" $value "context" $) | quote }}
36 {{- end }}
37 {{- end -}}
38
39 {{- define "kong.selectorLabels" -}}
40 app.kubernetes.io/name: {{ template "kong.name" . }}
41 app.kubernetes.io/component: app
42 app.kubernetes.io/instance: "{{ .Release.Name }}"
43 {{- end -}}
44
45 {{- define "kong.postgresql.fullname" -}}
46 {{- $name := default "postgresql" .Values.postgresql.nameOverride -}}
47 {{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
48 {{- end -}}
49
50 {{- define "kong.dblessConfig.fullname" -}}
51 {{- $name := default "kong-custom-dbless-config" .Values.dblessConfig.nameOverride -}}
52 {{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
53 {{- end -}}
54
55 {{/*
56 Create the name of the service account to use
57 */}}
58 {{- define "kong.serviceAccountName" -}}
59 {{- if .Values.deployment.serviceAccount.create -}}
60     {{ default (include "kong.fullname" .) .Values.deployment.serviceAccount.name }}
61 {{- else -}}
62     {{ default "default" .Values.deployment.serviceAccount.name }}
63 {{- end -}}
64 {{- end -}}
65
66 {{/*
67 Create the name of the secret for service account token to use
68 */}}
69 {{- define "kong.serviceAccountTokenName" -}}
70 {{ include "kong.serviceAccountName" . }}-token
71 {{- end -}}
72
73 {{/*
74 Create Ingress resource for a Kong service
75 */}}
76 {{- define "kong.ingress" -}}
77 {{- $servicePort := include "kong.ingress.servicePort" . }}
78 {{- $path := .ingress.path -}}
79 {{- $hostname := .ingress.hostname -}}
80 {{- $pathType := .ingress.pathType -}}
81 apiVersion: networking.k8s.io/v1
82 kind: Ingress
83 metadata:
84   name: {{ .fullName }}-{{ .serviceName }}
85   namespace: {{ .namespace }}
86   labels:
87   {{- .metaLabels | nindent 4 }}
88   {{- range $key, $value := .ingress.labels }}
89     {{- $key | nindent 4 }}: {{ $value | quote }}
90   {{- end }}
91   {{- if .ingress.annotations }}
92   annotations:
93     {{- range $key, $value := .ingress.annotations }}
94     {{ $key }}: {{ $value | quote }}
95     {{- end }}
96   {{- end }}
97 spec:
98 {{- if .ingress.ingressClassName }}
99   ingressClassName: {{ .ingress.ingressClassName }}
100 {{- end }}
101   rules:
102   {{- if ( not (or $hostname .ingress.hosts)) }}
103   - http:
104       paths:
105         - backend:
106             service:
107               name: {{ .fullName }}-{{ .serviceName }}
108               port:
109                 number: {{ $servicePort }}
110           path: {{ $path }}
111           pathType: {{ $pathType }}
112   {{- else if $hostname }}
113   - host: {{ $hostname | quote }}
114     http:
115       paths:
116         - backend:
117             service:
118               name: {{ .fullName }}-{{ .serviceName }}
119               port:
120                 number: {{ $servicePort }}
121           path: {{ $path }}
122           pathType: {{ $pathType }}
123   {{- end }}
124   {{- range .ingress.hosts }}
125   - host: {{ .host | quote }}
126     http:
127       paths:
128         {{- range .paths }}
129         - backend:
130           {{- if .backend -}}
131             {{ .backend | toYaml | nindent 12 }}
132           {{- else }}
133             service:
134               name: {{ $.fullName }}-{{ $.serviceName }}
135               port:
136                 number: {{ $servicePort }}
137           {{- end }}
138           {{- if (and $hostname (and (eq $path .path))) }}
139           {{- fail "duplication of specified ingress path" }}
140           {{- end }}
141           path: {{ .path }}
142           pathType: {{ .pathType }}
143         {{- end }}
144   {{- end }}
145   {{- if (hasKey .ingress "tls") }}
146   tls:
147   {{- if (kindIs "string" .ingress.tls) }}
148     - hosts:
149       {{- range .ingress.hosts }}
150         - {{ .host | quote }}
151       {{- end }}
152       {{- if $hostname }}
153         - {{ $hostname | quote }}
154       {{- end }}
155       secretName: {{ .ingress.tls }}
156   {{- else if (kindIs "slice" .ingress.tls) }}
157     {{- range .ingress.tls }}
158     - hosts:
159         {{- range .hosts }}
160         - {{ . | quote }}
161         {{- end }}
162       secretName: {{ .secretName }}
163     {{- end }}
164   {{- end }}
165   {{- end }}
166 {{- end -}}
167
168 {{/*
169 Create Service resource for a Kong service
170 */}}
171 {{- define "kong.service" -}}
172 apiVersion: v1
173 kind: Service
174 metadata:
175   name: {{ .fullName }}-{{ .serviceName }}
176   namespace: {{ .namespace }}
177   {{- if .annotations }}
178   annotations:
179   {{- range $key, $value := .annotations }}
180     {{ $key }}: {{ $value | quote }}
181   {{- end }}
182   {{- end }}
183   labels:
184     {{- .metaLabels | nindent 4 }}
185   {{- range $key, $value := .labels }}
186     {{ $key }}: {{ $value | quote }}
187   {{- end }}
188 spec:
189   type: {{ .type }}
190   {{- if eq .type "LoadBalancer" }}
191   {{- if .loadBalancerIP }}
192   loadBalancerIP: {{ .loadBalancerIP }}
193   {{- end }}
194   {{- if .loadBalancerSourceRanges }}
195   loadBalancerSourceRanges:
196   {{- range $cidr := .loadBalancerSourceRanges }}
197   - {{ $cidr }}
198   {{- end }}
199   {{- end }}
200   {{- if .loadBalancerClass }}
201   loadBalancerClass: {{ .loadBalancerClass }}
202   {{- end }}
203   {{- end }}
204   {{- if .externalIPs }}
205   externalIPs:
206   {{- range $ip := .externalIPs }}
207   - {{ $ip }}
208   {{- end -}}
209   {{- end }}
210   ports:
211   {{- if .http }}
212   {{- if .http.enabled }}
213   - name: kong-{{ .serviceName }}
214     port: {{ .http.servicePort }}
215     targetPort: {{ .http.containerPort }}
216   {{- if .http.appProtocol }}
217     appProtocol: {{ .http.appProtocol }}
218   {{- end }}
219   {{- if (and (or (eq .type "LoadBalancer") (eq .type "NodePort")) (not (empty .http.nodePort))) }}
220     nodePort: {{ .http.nodePort }}
221   {{- end }}
222     protocol: TCP
223   {{- end }}
224   {{- end }}
225   {{- if .tls.enabled }}
226   - name: kong-{{ .serviceName }}-tls
227     port: {{ .tls.servicePort }}
228     targetPort: {{ .tls.overrideServiceTargetPort | default .tls.containerPort }}
229   {{- if .tls.appProtocol }}
230     appProtocol: {{ .tls.appProtocol }}
231   {{- end }}
232   {{- if (and (or (eq .type "LoadBalancer") (eq .type "NodePort")) (not (empty .tls.nodePort))) }}
233     nodePort: {{ .tls.nodePort }}
234   {{- end }}
235     protocol: TCP
236   {{- end }}
237   {{- if (hasKey . "stream") }}
238     {{- $defaultProtocol := "TCP" }}
239     {{- if (hasSuffix "udp-proxy" .serviceName) }}
240       {{- $defaultProtocol = "UDP" }}
241     {{- end }}
242     {{- range $index, $streamEntry := .stream }}
243       {{- if (not (hasKey $streamEntry "protocol")) }}
244         {{- $_ := set $streamEntry "protocol" $defaultProtocol }}
245       {{- end }}
246     {{- end }}
247   {{- range .stream }}
248   - name: stream{{ if (eq (default "TCP" .protocol) "UDP") }}udp{{ end }}-{{ .containerPort }}
249     port: {{ .servicePort }}
250     targetPort: {{ .containerPort }}
251     {{- if (and (or (eq $.type "LoadBalancer") (eq $.type "NodePort")) (not (empty .nodePort))) }}
252     nodePort: {{ .nodePort }}
253     {{- end }}
254     protocol: {{ .protocol | default "TCP" }}
255   {{- end }}
256   {{- end }}
257   {{- if .externalTrafficPolicy }}
258   externalTrafficPolicy: {{ .externalTrafficPolicy }}
259   {{- end }}
260   {{- if .clusterIP }}
261   {{- if (or (not (eq .clusterIP "None")) (and (eq .type "ClusterIP") (eq .clusterIP "None"))) }}
262   clusterIP: {{ .clusterIP }}
263   {{- end }}
264   {{- end }}
265   selector:
266     {{- .selectorLabels | nindent 4 }}
267 {{- end -}}
268
269
270 {{/*
271 Create KONG_SERVICE_LISTEN strings
272 Generic tool for creating KONG_PROXY_LISTEN, KONG_ADMIN_LISTEN, etc.
273 */}}
274 {{- define "kong.listen" -}}
275   {{- $unifiedListen := list -}}
276   {{- $defaultAddrs := (list "0.0.0.0" "[::]") -}}
277
278   {{/* Some services do not support these blocks at all, so these checks are a
279        two-stage "is it safe to evaluate this?" and then "should we evaluate
280        this?"
281   */}}
282   {{- if .http -}}
283     {{- if .http.enabled -}}
284       {{- $listenConfig := dict -}}
285       {{- $listenConfig := merge $listenConfig .http -}}
286       {{- $addresses := (default $defaultAddrs .addresses) -}}
287       {{- range $addresses -}}
288         {{- $_ := set $listenConfig "address" . -}}
289         {{- $httpListen := (include "kong.singleListen" $listenConfig) -}}
290         {{- $unifiedListen = append $unifiedListen $httpListen -}}
291       {{- end -}}
292     {{- end -}}
293   {{- end -}}
294
295   {{- if .tls -}}
296     {{- if .tls.enabled -}}
297       {{/*
298       This is a bit of a hack to support always including "ssl" in the parameter
299       list for TLS listens. It's not possible to set a variable to an object from
300       .Values and then modify one of the objects values locally, although
301       https://github.com/helm/helm/issues/4987 indicates it should be. Instead,
302       this creates a new object and new parameters list built from the original.
303       */}}
304       {{- $listenConfig := dict -}}
305       {{- $listenConfig := merge $listenConfig .tls -}}
306       {{- $parameters := append .tls.parameters "ssl" -}}
307       {{- $_ := set $listenConfig "parameters" $parameters -}}
308       {{- $addresses := (default $defaultAddrs .addresses) -}}
309       {{- range $addresses -}}
310         {{- $_ := set $listenConfig "address" . -}}
311         {{- $tlsListen := (include "kong.singleListen" $listenConfig) -}}
312         {{- $unifiedListen = append $unifiedListen $tlsListen -}}
313       {{- end -}}
314     {{- end -}}
315   {{- end -}}
316
317   {{- $listenString := ($unifiedListen | join ", ") -}}
318   {{- if eq (len $listenString) 0 -}}
319     {{- $listenString = "off" -}}
320   {{- end -}}
321   {{- $listenString -}}
322 {{- end -}}
323
324 {{/*
325 Create KONG_PORT_MAPS string
326 Parameters: takes a service (e.g. .Values.proxy) as its argument and returns KONG_PORT_MAPS for that service.
327 */}}
328 {{- define "kong.port_maps" -}}
329   {{- $portMaps := list -}}
330
331   {{- if .http.enabled -}}
332         {{- $portMaps = append $portMaps (printf "%d:%d" (int64 .http.servicePort) (int64 .http.containerPort)) -}}
333   {{- end -}}
334
335   {{- if .tls.enabled -}}
336         {{- $portMaps = append $portMaps (printf "%d:%d" (int64 .tls.servicePort) (int64 .tls.containerPort)) -}}
337   {{- end -}}
338
339   {{- $portMapsString := ($portMaps | join ", ") -}}
340   {{- $portMapsString -}}
341 {{- end -}}
342
343 {{/*
344 Create KONG_STREAM_LISTEN string
345 */}}
346 {{- define "kong.streamListen" -}}
347   {{- $unifiedListen := list -}}
348   {{- $defaultAddrs := (list "0.0.0.0" "[::]") -}}
349   {{- range .stream -}}
350     {{- $listenConfig := dict -}}
351     {{- $listenConfig := merge $listenConfig . -}}
352     {{- $addresses := (default $defaultAddrs .addresses) -}}
353     {{- range $addresses -}}
354       {{- $_ := set $listenConfig "address" . -}}
355       {{/* You set NGINX stream listens to UDP using a parameter due to historical reasons.
356            Our configuration is dual-purpose, for both the Service and listen string, so we
357            forcibly inject this parameter if that's the Service protocol. The default handles
358            configs that predate the addition of the protocol field, where we only supported TCP. */}}
359       {{- if (eq (default "TCP" $listenConfig.protocol) "UDP") -}}
360         {{- $_ := set $listenConfig "parameters" (append (default (list) $listenConfig.parameters) "udp") -}}
361       {{- end -}}
362       {{- $unifiedListen = append $unifiedListen (include "kong.singleListen" $listenConfig ) -}}
363     {{- end -}}
364   {{- end -}}
365
366   {{- $listenString := ($unifiedListen | join ", ") -}}
367   {{- if eq (len $listenString) 0 -}}
368     {{- $listenString = "" -}}
369   {{- end -}}
370   {{- $listenString -}}
371 {{- end -}}
372
373 {{/*
374 Create a single listen (IP+port+parameter combo)
375 */}}
376 {{- define "kong.singleListen" -}}
377   {{- $listen := list -}}
378   {{- $listen = append $listen (printf "%s:%d" .address (int64 .containerPort)) -}}
379   {{- range $param := .parameters | default (list) | uniq }}
380     {{- $listen = append $listen $param -}}
381   {{- end -}}
382   {{- $listen | join " " -}}
383 {{- end -}}
384
385 {{/*
386 Return the admin API service name for service discovery
387 */}}
388 {{- define "kong.adminSvc" -}}
389 {{- $gatewayDiscovery := .Values.ingressController.gatewayDiscovery -}}
390 {{- if $gatewayDiscovery.enabled -}}
391   {{- $adminApiService := $gatewayDiscovery.adminApiService -}}
392   {{- $adminApiServiceName := $gatewayDiscovery.adminApiService.name -}}
393   {{- $generateAdminApiService := $gatewayDiscovery.generateAdminApiService -}}
394
395   {{- if and $generateAdminApiService $adminApiService.name -}}
396     {{- fail (printf ".Values.ingressController.gatewayDiscovery.adminApiService and .Values.ingressController.gatewayDiscovery.generateAdminApiService must not be provided at the same time")  -}}
397   {{- end -}}
398
399   {{- if $generateAdminApiService -}}
400     {{- $adminApiServiceName = (printf "%s-%s" .Release.Name "gateway-admin") -}}
401   {{- else }}
402     {{- $_ := required ".ingressController.gatewayDiscovery.adminApiService.name has to be provided when .Values.ingressController.gatewayDiscovery.enabled is set to true"  $adminApiServiceName -}}
403   {{- end }}
404
405   {{- if (semverCompare "< 2.9.0" (include "kong.effectiveVersion" .Values.ingressController.image)) }}
406   {{- fail (printf "Gateway discovery is available in controller versions 2.9 and up. Detected %s" (include "kong.effectiveVersion" .Values.ingressController.image)) }}
407   {{- end }}
408
409   {{- if .Values.deployment.kong.enabled }}
410   {{- fail "deployment.kong.enabled and ingressController.gatewayDiscovery.enabled are mutually exclusive and cannot be enabled at once. Gateway discovery requires a split release installation of Gateways and Ingress Controller." }}
411   {{- end }}
412
413   {{- $namespace := $adminApiService.namespace | default ( include "kong.namespace" . ) -}}
414   {{- printf "%s/%s" $namespace $adminApiServiceName -}}
415 {{- else -}}
416   {{- fail "Can't use gateway discovery when .Values.ingressController.gatewayDiscovery.enabled is set to false." -}}
417 {{- end -}}
418 {{- end -}}
419
420 {{/*
421 Return the local admin API URL, preferring HTTPS if available
422 */}}
423 {{- define "kong.adminLocalURL" -}}
424   {{- if .Values.admin.tls.enabled -}}
425 https://localhost:{{ .Values.admin.tls.containerPort }}
426   {{- else if .Values.admin.http.enabled -}}
427 http://localhost:{{ .Values.admin.http.containerPort }}
428   {{- else -}}
429 http://localhost:9999 # You have no admin listens! The controller will not work unless you set .Values.admin.http.enabled=true or .Values.admin.tls.enabled=true!
430   {{- end -}}
431 {{- end -}}
432
433 {{/*
434 Create the ingress servicePort value string
435 */}}
436
437 {{- define "kong.ingress.servicePort" -}}
438 {{- if .tls.enabled -}}
439    {{ .tls.servicePort }}
440 {{- else -}}
441    {{ .http.servicePort }}
442 {{- end -}}
443 {{- end -}}
444
445 {{/*
446 Generate an appropriate external URL from a Kong service's ingress configuration
447 Strips trailing slashes from the path. Manager at least does not handle these
448 intelligently and will append its own slash regardless, and the admin API cannot handle
449 the extra slash.
450 */}}
451
452 {{- define "kong.ingress.serviceUrl" -}}
453 {{- if .tls -}}
454     https://{{ .hostname }}{{ .path | trimSuffix "/" }}
455 {{- else -}}
456     http://{{ .hostname }}{{ .path | trimSuffix "/" }}
457 {{- end -}}
458 {{- end -}}
459
460 {{/*
461 The name of the service used for the ingress controller's validation webhook
462 */}}
463
464 {{- define "kong.service.validationWebhook" -}}
465 {{ include "kong.fullname" . }}-validation-webhook
466 {{- end -}}
467
468
469 {{/*
470 The name of the Service which will be used by the controller to update the Ingress status field.
471 */}}
472
473 {{- define "kong.controller-publish-service" -}}
474 {{- $proxyOverride := "" -}}
475   {{- if .Values.proxy.nameOverride -}}
476     {{- $proxyOverride = ( tpl .Values.proxy.nameOverride . ) -}}
477   {{- end -}}
478 {{- (printf "%s/%s" ( include "kong.namespace" . ) ( default ( printf "%s-proxy" (include "kong.fullname" . )) $proxyOverride )) -}}
479 {{- end -}}
480
481 {{- define "kong.ingressController.env" -}}
482 {{/*
483     ====== AUTO-GENERATED ENVIRONMENT VARIABLES ======
484 */}}
485
486
487 {{- $autoEnv := dict -}}
488   {{- $_ := set $autoEnv "CONTROLLER_KONG_ADMIN_TLS_SKIP_VERIFY" true -}}
489   {{- $_ := set $autoEnv "CONTROLLER_PUBLISH_SERVICE" ( include "kong.controller-publish-service" . ) -}}
490   {{- $_ := set $autoEnv "CONTROLLER_INGRESS_CLASS" .Values.ingressController.ingressClass -}}
491   {{- $_ := set $autoEnv "CONTROLLER_ELECTION_ID" (printf "kong-ingress-controller-leader-%s" .Values.ingressController.ingressClass) -}}
492
493   {{- if .Values.ingressController.admissionWebhook.enabled }}
494     {{- $address := (default "0.0.0.0" .Values.ingressController.admissionWebhook.address) -}}
495     {{- $_ := set $autoEnv "CONTROLLER_ADMISSION_WEBHOOK_LISTEN" (printf "%s:%d" $address (int64 .Values.ingressController.admissionWebhook.port)) -}}
496   {{- end }}
497   {{- if (not (eq (len .Values.ingressController.watchNamespaces) 0)) }}
498     {{- $_ := set $autoEnv "CONTROLLER_WATCH_NAMESPACE" (.Values.ingressController.watchNamespaces | join ",") -}}
499   {{- end }}
500
501 {{/*
502     ====== ADMIN API CONFIGURATION ======
503 */}}
504
505   {{- if .Values.ingressController.gatewayDiscovery.enabled -}}
506     {{- $_ := set $autoEnv "CONTROLLER_KONG_ADMIN_SVC" (include "kong.adminSvc" . ) -}}
507   {{- else -}}
508     {{- $_ := set $autoEnv "CONTROLLER_KONG_ADMIN_URL" (include "kong.adminLocalURL" .) -}}
509   {{- end -}}
510
511   {{- if .Values.ingressController.adminApi.tls.client.enabled }}
512     {{- $_ := set $autoEnv "CONTROLLER_KONG_ADMIN_TLS_CLIENT_CERT_FILE" "/etc/secrets/admin-api-cert/tls.crt" -}}
513     {{- $_ := set $autoEnv "CONTROLLER_KONG_ADMIN_TLS_CLIENT_KEY_FILE" "/etc/secrets/admin-api-cert/tls.key" -}}
514   {{- end }}
515
516 {{/*
517     ====== KONNECT ENVIRONMENT VARIABLES ======
518 */}}
519
520 {{- if .Values.ingressController.konnect.enabled }}
521   {{- if (semverCompare "< 2.9.0" (include "kong.effectiveVersion" .Values.ingressController.image)) }}
522   {{- fail (printf "Konnect sync is available in controller versions 2.9 and up. Detected %s" (include "kong.effectiveVersion" .Values.ingressController.image)) }}
523   {{- end }}
524
525   {{- if not .Values.ingressController.gatewayDiscovery.enabled }}
526   {{- fail "ingressController.gatewayDiscovery.enabled has to be true when ingressController.konnect.enabled"}}
527   {{- end }}
528
529   {{- $konnect := .Values.ingressController.konnect -}}
530   {{- $_ := required "ingressController.konnect.runtimeGroupID is required when ingressController.konnect.enabled" $konnect.runtimeGroupID -}}
531
532   {{- $_ = set $autoEnv "CONTROLLER_KONNECT_SYNC_ENABLED" true -}}
533   {{- $_ = set $autoEnv "CONTROLLER_KONNECT_RUNTIME_GROUP_ID" $konnect.runtimeGroupID -}}
534   {{- $_ = set $autoEnv "CONTROLLER_KONNECT_ADDRESS" (printf "https://%s" .Values.ingressController.konnect.apiHostname) -}}
535
536   {{- $tlsCert := include "secretkeyref" (dict "name" $konnect.tlsClientCertSecretName "key" "tls.crt") -}}
537   {{- $tlsKey := include "secretkeyref" (dict "name" $konnect.tlsClientCertSecretName "key" "tls.key") -}}
538   {{- $_ = set $autoEnv "CONTROLLER_KONNECT_TLS_CLIENT_CERT" $tlsCert -}}
539   {{- $_ = set $autoEnv "CONTROLLER_KONNECT_TLS_CLIENT_KEY" $tlsKey -}}
540
541   {{- if $konnect.license.enabled }}
542   {{- $_ = set $autoEnv "CONTROLLER_KONNECT_LICENSING_ENABLED" true -}}
543   {{- end }}
544 {{- end }}
545
546 {{/*
547     ====== USER-SET ENVIRONMENT VARIABLES ======
548 */}}
549
550 {{- $userEnv := dict -}}
551 {{- range $key, $val := .Values.ingressController.env }}
552   {{- $upper := upper $key -}}
553   {{- $var := printf "CONTROLLER_%s" $upper -}}
554   {{- $_ := set $userEnv $var $val -}}
555 {{- end -}}
556
557 {{/*
558     ====== CUSTOM-SET INGRESS CONTROLLER ENVIRONMENT VARIABLES ======
559 */}}
560
561 {{- $customIngressEnv := dict -}}
562 {{- range $key, $val := .Values.ingressController.customEnv }}
563   {{- $upper := upper $key -}}
564   {{- $_ := set $customIngressEnv $upper $val -}}
565 {{- end -}}
566
567 {{/*
568       ====== MERGE AND RENDER ENV BLOCK ======
569 */}}
570
571 {{- $completeEnv := mergeOverwrite $autoEnv $userEnv $customIngressEnv -}}
572 {{- template "kong.renderEnv" $completeEnv -}}
573
574 {{- end -}}
575
576 {{- define "kong.userDefinedVolumes" -}}
577 {{- if .Values.deployment.userDefinedVolumes }}
578 {{- toYaml .Values.deployment.userDefinedVolumes }}
579 {{- end }}
580 {{- end -}}
581
582 {{- define "kong.volumes" -}}
583 - name: {{ template "kong.fullname" . }}-prefix-dir
584   emptyDir:
585     sizeLimit: {{ .Values.deployment.prefixDir.sizeLimit }}
586 - name: {{ template "kong.fullname" . }}-tmp
587   emptyDir:
588     sizeLimit: {{ .Values.deployment.tmpDir.sizeLimit }}
589 {{- if (and (not .Values.deployment.serviceAccount.automountServiceAccountToken) (or .Values.deployment.serviceAccount.create .Values.deployment.serviceAccount.name)) }}
590 - name: {{ template "kong.serviceAccountTokenName" . }}
591   {{- /* Due to GKE versions (e.g. v1.23.15-gke.1900) we need to handle pre-release part of the version as well.
592   See the related documentation of semver module that Helm depends on for semverCompare:
593   https://github.com/Masterminds/semver#working-with-prerelease-versions
594   Related Helm issue: https://github.com/helm/helm/issues/3810 */}}
595   {{- if semverCompare ">=1.20.0-0" .Capabilities.KubeVersion.Version }}
596   projected:
597     sources:
598     - serviceAccountToken:
599         expirationSeconds: 3607
600         path: token
601     - configMap:
602         items:
603         - key: ca.crt
604           path: ca.crt
605         name: kube-root-ca.crt
606     - downwardAPI:
607         items:
608         - fieldRef:
609             apiVersion: v1
610             fieldPath: metadata.namespace
611           path: namespace
612   {{- else }}
613   secret:
614     secretName: {{ template "kong.serviceAccountTokenName" . }}
615     items:
616     - key: token
617       path: token
618     - key: ca.crt
619       path: ca.crt
620     - key: namespace
621       path: namespace
622   {{- end }}
623 {{- end }}
624 {{- if and ( .Capabilities.APIVersions.Has "cert-manager.io/v1" ) .Values.certificates.enabled -}}
625 {{- if .Values.certificates.cluster.enabled }}
626 - name: {{ include "kong.fullname" . }}-cluster-cert
627   secret:
628     secretName: {{ include "kong.fullname" . }}-cluster-cert
629 {{- end }}
630 {{- if .Values.certificates.proxy.enabled }}
631 - name: {{ include "kong.fullname" . }}-proxy-cert
632   secret:
633     secretName: {{ include "kong.fullname" . }}-proxy-cert
634 {{- end }}
635 {{- if .Values.certificates.admin.enabled }}
636 - name: {{ include "kong.fullname" . }}-admin-cert
637   secret:
638     secretName: {{ include "kong.fullname" . }}-admin-cert
639 {{- end }}
640 {{- if .Values.enterprise.enabled }}
641 {{- if .Values.certificates.portal.enabled }}
642 - name: {{ include "kong.fullname" . }}-portal-cert
643   secret:
644     secretName: {{ include "kong.fullname" . }}-portal-cert
645 {{- end }}
646 {{- end }}
647 {{- end }}
648 {{- if (and (.Values.postgresql.enabled) .Values.waitImage.enabled) }}
649 - name: {{ template "kong.fullname" . }}-bash-wait-for-postgres
650   configMap:
651     name: {{ template "kong.fullname" . }}-bash-wait-for-postgres
652     defaultMode: 0755
653 {{- end }}
654 {{- range .Values.plugins.configMaps }}
655 - name: kong-plugin-{{ .pluginName }}
656   configMap:
657     name: {{ .name }}
658 {{- range .subdirectories }}
659 - name: {{ .name }}
660   configMap:
661     name: {{ .name }}
662 {{- end }}
663 {{- end }}
664 {{- range .Values.plugins.secrets }}
665 - name: kong-plugin-{{ .pluginName }}
666   secret:
667     secretName: {{ .name }}
668 {{- range .subdirectories }}
669 - name: {{ .name }}
670   secret:
671     secretName: {{ .name }}
672 {{- end }}
673 {{- end }}
674
675 {{- if (and (not .Values.ingressController.enabled) (eq .Values.env.database "off")) }}
676   {{- $dblessSourceCount := (add (.Values.dblessConfig.configMap | len | min 1) (.Values.dblessConfig.secret | len | min 1) (.Values.dblessConfig.config | len | min 1)) -}}
677   {{- if gt $dblessSourceCount 1 -}}
678     {{- fail "Ambiguous configuration: only one of of .Values.dblessConfig.configMap, .Values.dblessConfig.secret, and .Values.dblessConfig.config can be set." -}}
679   {{- else if eq $dblessSourceCount 1 }}
680 - name: kong-custom-dbless-config-volume
681     {{- if .Values.dblessConfig.configMap }}
682   configMap:
683     name: {{ .Values.dblessConfig.configMap }}
684     {{- else if .Values.dblessConfig.secret }}
685   secret:
686     secretName: {{ .Values.dblessConfig.secret }}
687     {{- else }}
688   configMap:
689     name: {{ template "kong.dblessConfig.fullname" . }}
690     {{- end }}
691   {{- end }}
692 {{- end }}
693
694 {{- if and .Values.ingressController.enabled .Values.ingressController.admissionWebhook.enabled }}
695 - name: webhook-cert
696   secret:
697     {{- if .Values.ingressController.admissionWebhook.certificate.provided }}
698     secretName: {{ .Values.ingressController.admissionWebhook.certificate.secretName }}
699     {{- else }}
700     secretName: {{ template "kong.fullname" . }}-validation-webhook-keypair
701     {{- end }}
702 {{- end }}
703 {{- if or $.Values.admin.tls.client.secretName $.Values.admin.tls.client.caBundle }}
704 - name: admin-client-ca
705   configMap:
706     name: {{ template "kong.fullname" . }}-admin-client-ca
707 {{- end -}}
708 {{- range $secretVolume := .Values.secretVolumes }}
709 - name: {{ . }}
710   secret:
711     secretName: {{ . }}
712 {{- end }}
713 {{- range .Values.extraConfigMaps }}
714 - name: {{ .name }}
715   configMap:
716     name: {{ .name }}
717 {{- end }}
718 {{- range .Values.extraSecrets }}
719 - name: {{ .name }}
720   secret:
721     secretName: {{ .name }}
722 {{- end }}
723 {{- if and .Values.ingressController.adminApi.tls.client.enabled .Values.ingressController.enabled }}
724 - name: admin-api-cert
725   secret:
726     secretName: {{ template "adminApiService.certSecretName" . }}
727 {{- end }}
728 {{- end -}}
729
730 {{- define "controller.adminApiCertVolumeMount" -}}
731 {{- if and .Values.ingressController.adminApi.tls.client.enabled .Values.ingressController.enabled }}
732 - name: admin-api-cert
733   mountPath: /etc/secrets/admin-api-cert
734   readOnly: true
735 {{- end -}}
736 {{- end -}}
737
738 {{- define "kong.userDefinedVolumeMounts" -}}
739 {{- if .userDefinedVolumeMounts }}
740 {{- toYaml .userDefinedVolumeMounts }}
741 {{- end }}
742 {{- end -}}
743
744 {{- define "kong.volumeMounts" -}}
745 - name: {{ template "kong.fullname" . }}-prefix-dir
746   mountPath: /kong_prefix/
747 - name: {{ template "kong.fullname" . }}-tmp
748   mountPath: /tmp
749 {{- if and ( .Capabilities.APIVersions.Has "cert-manager.io/v1" ) .Values.certificates.enabled -}}
750 {{- if .Values.certificates.cluster.enabled }}
751 - name: {{ include "kong.fullname" . }}-cluster-cert
752   mountPath: /etc/cert-manager/cluster/
753 {{- end }}
754 {{- if .Values.certificates.proxy.enabled }}
755 - name: {{ include "kong.fullname" . }}-proxy-cert
756   mountPath: /etc/cert-manager/proxy/
757 {{- end }}
758 {{- if .Values.certificates.admin.enabled }}
759 - name: {{ include "kong.fullname" . }}-admin-cert
760   mountPath: /etc/cert-manager/admin/
761 {{- end }}
762 {{- if .Values.enterprise.enabled }}
763 {{- if .Values.certificates.portal.enabled }}
764 - name: {{ include "kong.fullname" . }}-portal-cert
765   mountPath: /etc/cert-manager/portal/
766 {{- end }}
767 {{- end }}
768 {{- end }}
769 {{- $dblessSourceCount := (add (.Values.dblessConfig.configMap | len | min 1) (.Values.dblessConfig.secret | len | min 1) (.Values.dblessConfig.config | len | min 1)) -}}
770   {{- if eq $dblessSourceCount 1 -}}
771     {{- if (and (not .Values.ingressController.enabled) (eq .Values.env.database "off")) }}
772 - name: kong-custom-dbless-config-volume
773   mountPath: /kong_dbless/
774     {{- end }}
775   {{- end }}
776 {{- if or $.Values.admin.tls.client.caBundle $.Values.admin.tls.client.secretName }}
777 - name: admin-client-ca
778   mountPath: /etc/admin-client-ca/
779   readOnly: true
780 {{- end -}}
781 {{- range .Values.secretVolumes }}
782 - name:  {{ . }}
783   mountPath: /etc/secrets/{{ . }}
784 {{- end }}
785 {{- range .Values.plugins.configMaps }}
786 {{- $mountPath := printf "/opt/kong/plugins/%s" .pluginName }}
787 - name:  kong-plugin-{{ .pluginName }}
788   mountPath: {{ $mountPath }}
789   readOnly: true
790 {{- range .subdirectories }}
791 - name: {{ .name  }}
792   mountPath: {{ printf "%s/%s" $mountPath ( .path | default .name ) }}
793   readOnly: true
794 {{- end }}
795 {{- end }}
796 {{- range .Values.plugins.secrets }}
797 {{- $mountPath := printf "/opt/kong/plugins/%s" .pluginName }}
798 - name:  kong-plugin-{{ .pluginName }}
799   mountPath: {{ $mountPath }}
800   readOnly: true
801 {{- range .subdirectories }}
802 - name: {{ .name }}
803   mountPath: {{ printf "%s/%s" $mountPath .path }}
804   readOnly: true
805 {{- end }}
806 {{- end }}
807
808 {{- range .Values.extraConfigMaps }}
809 - name:  {{ .name }}
810   mountPath: {{ .mountPath }}
811
812   {{- if .subPath }}
813   subPath: {{ .subPath }}
814   {{- end }}
815 {{- end }}
816 {{- range .Values.extraSecrets }}
817 - name:  {{ .name }}
818   mountPath: {{ .mountPath }}
819
820   {{- if .subPath }}
821   subPath: {{ .subPath }}
822   {{- end }}
823 {{- end }}
824
825 {{- end -}}
826
827 {{- define "kong.plugins" -}}
828 {{ $myList := list "bundled" }}
829 {{- range .Values.plugins.configMaps -}}
830 {{- $myList = append $myList .pluginName -}}
831 {{- end -}}
832 {{- range .Values.plugins.secrets -}}
833   {{ $myList = append $myList .pluginName -}}
834 {{- end }}
835 {{- $myList | uniq | join "," -}}
836 {{- end -}}
837
838 {{- define "kong.wait-for-db" -}}
839 - name: wait-for-db
840   image: {{ include "kong.getRepoTag" .Values.image }}
841   imagePullPolicy: {{ .Values.image.pullPolicy }}
842   securityContext:
843   {{ toYaml .Values.containerSecurityContext | nindent 4 }}
844   env:
845   {{- include "kong.env" . | nindent 2 }}
846   {{- include "kong.envFrom" .Values.envFrom | nindent 2 }}
847 {{/* TODO the prefix override is to work around https://github.com/Kong/charts/issues/295
848      Note that we use args instead of command here to /not/ override the standard image entrypoint. */}}
849   args: [ "/bin/bash", "-c", "export KONG_NGINX_DAEMON=on KONG_PREFIX=`mktemp -d` KONG_KEYRING_ENABLED=off; until kong start; do echo 'waiting for db'; sleep 1; done; kong stop"]
850   volumeMounts:
851   {{- include "kong.volumeMounts" . | nindent 4 }}
852   {{- include "kong.userDefinedVolumeMounts" .Values.deployment | nindent 4 }}
853   resources:
854   {{- toYaml .Values.resources | nindent 4 }}
855 {{- end -}}
856
857 {{/* effectiveVersion takes an image dict from values.yaml. if .effectiveSemver is set, it returns that, else it returns .tag */}}
858 {{- define "kong.effectiveVersion" -}}
859 {{- /* Because Kong Gateway enterprise uses versions with 4 segments and not 3 */ -}}
860 {{- /* as semver does, we need to account for that here by extracting */ -}}
861 {{- /* first 3 segments for comparison */ -}}
862 {{- if .effectiveSemver -}}
863   {{- if regexMatch "^[0-9]+.[0-9]+.[0-9]+" .effectiveSemver -}}
864   {{- regexFind "^[0-9]+.[0-9]+.[0-9]+" .effectiveSemver -}}
865   {{- else -}}
866   {{- .effectiveSemver -}}
867   {{- end -}}
868 {{- else -}}
869   {{- $tag := (trimSuffix "-redhat" .tag) -}}
870   {{- if regexMatch "^[0-9]+.[0-9]+.[0-9]+" .tag -}}
871   {{- regexFind "^[0-9]+.[0-9]+.[0-9]+" .tag -}}
872   {{- else -}}
873   {{- .tag -}}
874   {{- end -}}
875 {{- end -}}
876 {{- end -}}
877
878 {{- define "kong.controller-container" -}}
879 - name: ingress-controller
880   securityContext:
881 {{ toYaml .Values.containerSecurityContext | nindent 4 }}
882   args:
883   {{ if .Values.ingressController.args}}
884   {{- range $val := .Values.ingressController.args }}
885   - {{ $val }}
886   {{- end }}
887   {{- end }}
888   ports:
889   {{- if .Values.ingressController.admissionWebhook.enabled }}
890   - name: webhook
891     containerPort: {{ .Values.ingressController.admissionWebhook.port }}
892     protocol: TCP
893   {{- end }}
894   {{ if (semverCompare ">= 2.0.0" (include "kong.effectiveVersion" .Values.ingressController.image)) -}}
895   - name: cmetrics
896     containerPort: 10255
897     protocol: TCP
898   {{- end }}
899   - name: cstatus
900     containerPort: 10254
901     protocol: TCP
902   env:
903   - name: POD_NAME
904     valueFrom:
905       fieldRef:
906         apiVersion: v1
907         fieldPath: metadata.name
908   - name: POD_NAMESPACE
909     valueFrom:
910       fieldRef:
911         apiVersion: v1
912         fieldPath: metadata.namespace
913 {{- include "kong.ingressController.env" .  | indent 2 }}
914 {{ include "kong.envFrom" .Values.ingressController.envFrom | indent 2 }}
915   image: {{ include "kong.getRepoTag" .Values.ingressController.image }}
916   imagePullPolicy: {{ .Values.image.pullPolicy }}
917 {{/* disableReadiness is a hidden setting to drop this block entirely for use with a debugger
918      Helm value interpretation doesn't let you replace the default HTTP checks with any other
919      check type, and all HTTP checks freeze when a debugger pauses operation.
920      Setting disableReadiness to ANY value disables the probes.
921 */}}
922 {{- if (not (hasKey .Values.ingressController "disableProbes")) }}
923   readinessProbe:
924 {{ toYaml .Values.ingressController.readinessProbe | indent 4 }}
925   livenessProbe:
926 {{ toYaml .Values.ingressController.livenessProbe | indent 4 }}
927 {{- end }}
928   resources:
929 {{ toYaml .Values.ingressController.resources | indent 4 }}
930   volumeMounts:
931 {{- if .Values.ingressController.admissionWebhook.enabled }}
932   - name: webhook-cert
933     mountPath: /admission-webhook
934     readOnly: true
935 {{- end }}
936 {{- if (and (not .Values.deployment.serviceAccount.automountServiceAccountToken) (or .Values.deployment.serviceAccount.create .Values.deployment.serviceAccount.name)) }}
937   - name: {{ template "kong.serviceAccountTokenName" . }}
938     mountPath: /var/run/secrets/kubernetes.io/serviceaccount
939     readOnly: true
940 {{- end }}
941   {{- include "kong.userDefinedVolumeMounts" .Values.ingressController | nindent 2 }}
942   {{- include "controller.adminApiCertVolumeMount" . | nindent 2 }}
943 {{- end -}}
944
945 {{- define "secretkeyref" -}}
946 valueFrom:
947   secretKeyRef:
948     name: {{ .name }}
949     key: {{ .key }}
950 {{- end -}}
951
952 {{/*
953 Use the Pod security context defined in Values or set the UID by default
954 */}}
955 {{- define "kong.podsecuritycontext" -}}
956 {{ .Values.securityContext | toYaml }}
957 {{- end -}}
958
959 {{- define "kong.no_daemon_env" -}}
960 {{- template "kong.env" . }}
961 - name: KONG_NGINX_DAEMON
962   value: "off"
963 {{- end -}}
964
965 {{/*
966 The environment values passed to Kong; this should come after all
967 the template that it itself is using form the above sections.
968 */}}
969 {{- define "kong.env" -}}
970 {{/*
971     ====== AUTO-GENERATED ENVIRONMENT VARIABLES ======
972 */}}
973 {{- $autoEnv := dict -}}
974
975 {{- $_ := set $autoEnv "KONG_LUA_PACKAGE_PATH" "/opt/?.lua;/opt/?/init.lua;;" -}}
976
977 {{- $_ := set $autoEnv "KONG_PROXY_ACCESS_LOG" "/dev/stdout" -}}
978 {{- $_ := set $autoEnv "KONG_PROXY_STREAM_ACCESS_LOG" "/dev/stdout basic" -}}
979 {{- $_ := set $autoEnv "KONG_ADMIN_ACCESS_LOG" "/dev/stdout" -}}
980 {{- $_ := set $autoEnv "KONG_STATUS_ACCESS_LOG" "off" -}}
981 {{- $_ := set $autoEnv "KONG_PROXY_ERROR_LOG" "/dev/stderr" -}}
982 {{- $_ := set $autoEnv "KONG_PROXY_STREAM_ERROR_LOG" "/dev/stderr" -}}
983 {{- $_ := set $autoEnv "KONG_ADMIN_ERROR_LOG" "/dev/stderr" -}}
984 {{- $_ := set $autoEnv "KONG_STATUS_ERROR_LOG" "/dev/stderr" -}}
985
986 {{- if .Values.ingressController.enabled -}}
987   {{- $_ := set $autoEnv "KONG_KIC" "on" -}}
988 {{- end -}}
989
990 {{- with .Values.admin -}}
991   {{- $listenConfig := dict -}}
992   {{- $listenConfig := merge $listenConfig . -}}
993   {{- if (and (not (hasKey . "addresses")) (not .enabled)) -}}
994     {{- $_ := set $listenConfig "addresses" (list "127.0.0.1" "[::1]") -}}
995   {{- end -}}
996   {{- $_ := set $autoEnv "KONG_ADMIN_LISTEN" (include "kong.listen" $listenConfig) -}}
997
998   {{- if or .tls.client.secretName .tls.client.caBundle -}}
999     {{- $_ := set $autoEnv "KONG_NGINX_ADMIN_SSL_VERIFY_CLIENT" "on" -}}
1000     {{- $_ := set $autoEnv "KONG_NGINX_ADMIN_SSL_CLIENT_CERTIFICATE" "/etc/admin-client-ca/tls.crt" -}}
1001   {{- end -}}
1002
1003 {{- end -}}
1004
1005 {{- if and ( .Capabilities.APIVersions.Has "cert-manager.io/v1" ) .Values.certificates.enabled -}}
1006   {{- if (and .Values.certificates.cluster.enabled .Values.cluster.enabled) -}}
1007     {{- $_ := set $autoEnv "KONG_CLUSTER_MTLS" "pki" -}}
1008     {{- $_ := set $autoEnv "KONG_CLUSTER_SERVER_NAME" .Values.certificates.cluster.commonName -}}
1009     {{- $_ := set $autoEnv "KONG_CLUSTER_CA_CERT" "/etc/cert-manager/cluster/ca.crt" -}}
1010     {{- $_ := set $autoEnv "KONG_CLUSTER_CERT" "/etc/cert-manager/cluster/tls.crt" -}}
1011     {{- $_ := set $autoEnv "KONG_CLUSTER_CERT_KEY" "/etc/cert-manager/cluster/tls.key" -}}
1012   {{- end -}}
1013
1014   {{- if .Values.certificates.proxy.enabled -}}
1015     {{- $_ := set $autoEnv "KONG_SSL_CERT" "/etc/cert-manager/proxy/tls.crt" -}}
1016     {{- $_ := set $autoEnv "KONG_SSL_CERT_KEY" "/etc/cert-manager/proxy/tls.key" -}}
1017   {{- end -}}
1018
1019   {{- if .Values.certificates.admin.enabled -}}
1020     {{- $_ := set $autoEnv "KONG_ADMIN_SSL_CERT" "/etc/cert-manager/admin/tls.crt" -}}
1021     {{- $_ := set $autoEnv "KONG_ADMIN_SSL_CERT_KEY" "/etc/cert-manager/admin/tls.key" -}}
1022     {{- if .Values.enterprise.enabled }}
1023       {{- $_ := set $autoEnv "KONG_ADMIN_GUI_SSL_CERT" "/etc/cert-manager/admin/tls.crt" -}}
1024       {{- $_ := set $autoEnv "KONG_ADMIN_GUI_SSL_CERT_KEY" "/etc/cert-manager/admin/tls.key" -}}
1025     {{- end -}}
1026   {{- end -}}
1027
1028   {{- if .Values.enterprise.enabled }}
1029     {{- if .Values.certificates.portal.enabled -}}
1030       {{- $_ := set $autoEnv "KONG_PORTAL_API_SSL_CERT" "/etc/cert-manager/portal/tls.crt" -}}
1031       {{- $_ := set $autoEnv "KONG_PORTAL_API_SSL_CERT_KEY" "/etc/cert-manager/portal/tls.key" -}}
1032       {{- $_ := set $autoEnv "KONG_PORTAL_GUI_SSL_CERT" "/etc/cert-manager/portal/tls.crt" -}}
1033       {{- $_ := set $autoEnv "KONG_PORTAL_GUI_SSL_CERT_KEY" "/etc/cert-manager/portal/tls.key" -}}
1034     {{- end -}}
1035   {{- end -}}
1036 {{- end -}}
1037
1038 {{- if .Values.admin.ingress.enabled }}
1039   {{- $_ := set $autoEnv "KONG_ADMIN_GUI_API_URL" (include "kong.ingress.serviceUrl" .Values.admin.ingress) -}}
1040   {{- $_ := set $autoEnv "KONG_ADMIN_API_URI" (include "kong.ingress.serviceUrl" .Values.admin.ingress) -}}
1041 {{- end -}}
1042
1043 {{- $_ := set $autoEnv "KONG_PROXY_LISTEN" (include "kong.listen" .Values.proxy) -}}
1044
1045 {{- $streamStrings := list -}}
1046 {{- if .Values.proxy.enabled -}}
1047   {{- $tcpStreamString := (include "kong.streamListen" .Values.proxy) -}}
1048   {{- if (not (eq $tcpStreamString "")) -}}
1049     {{- $streamStrings = (append $streamStrings $tcpStreamString) -}}
1050   {{- end -}}
1051 {{- end -}}
1052 {{- if .Values.udpProxy.enabled -}}
1053   {{- $udpStreamString := (include "kong.streamListen" .Values.udpProxy) -}}
1054   {{- if (not (eq $udpStreamString "")) -}}
1055     {{- $streamStrings = (append $streamStrings $udpStreamString) -}}
1056   {{- end -}}
1057 {{- end -}}
1058 {{- $streamString := $streamStrings | join ", " -}}
1059 {{- if (eq (len $streamString) 0)  -}}
1060   {{- $streamString = "off" -}}
1061 {{- end -}}
1062 {{- $_ := set $autoEnv "KONG_STREAM_LISTEN" $streamString -}}
1063
1064 {{- $_ := set $autoEnv "KONG_STATUS_LISTEN" (include "kong.listen" .Values.status) -}}
1065
1066 {{- if .Values.proxy.enabled -}}
1067   {{- $_ := set $autoEnv "KONG_PORT_MAPS" (include "kong.port_maps" .Values.proxy) -}}
1068 {{- end -}}
1069
1070 {{- $_ := set $autoEnv "KONG_CLUSTER_LISTEN" (include "kong.listen" .Values.cluster) -}}
1071
1072 {{- if .Values.enterprise.enabled }}
1073   {{- $_ := set $autoEnv "KONG_PORTAL_API_ACCESS_LOG" "/dev/stdout" -}}
1074   {{- $_ := set $autoEnv "KONG_PORTAL_GUI_ACCESS_LOG" "/dev/stdout" -}}
1075   {{- $_ := set $autoEnv "KONG_ADMIN_GUI_ACCESS_LOG" "/dev/stdout" -}}
1076   {{- $_ := set $autoEnv "KONG_PORTAL_API_ERROR_LOG" "/dev/stderr" -}}
1077   {{- $_ := set $autoEnv "KONG_PORTAL_GUI_ERROR_LOG" "/dev/stderr" -}}
1078   {{- $_ := set $autoEnv "KONG_ADMIN_GUI_ERROR_LOG" "/dev/stderr" -}}
1079
1080   {{- $_ := set $autoEnv "KONG_ADMIN_GUI_LISTEN" (include "kong.listen" .Values.manager) -}}
1081   {{- if .Values.manager.ingress.enabled }}
1082     {{- $_ := set $autoEnv "KONG_ADMIN_GUI_URL" (include "kong.ingress.serviceUrl" .Values.manager.ingress) -}}
1083   {{- end -}}
1084
1085   {{- if not .Values.enterprise.vitals.enabled }}
1086     {{- $_ := set $autoEnv "KONG_VITALS" "off" -}}
1087   {{- end }}
1088   {{- $_ := set $autoEnv "KONG_CLUSTER_TELEMETRY_LISTEN" (include "kong.listen" .Values.clustertelemetry) -}}
1089
1090   {{- if .Values.enterprise.portal.enabled }}
1091     {{- $_ := set $autoEnv "KONG_PORTAL" "on" -}}
1092       {{- $_ := set $autoEnv "KONG_PORTAL_GUI_LISTEN" (include "kong.listen" .Values.portal) -}}
1093     {{- $_ := set $autoEnv "KONG_PORTAL_API_LISTEN" (include "kong.listen" .Values.portalapi) -}}
1094
1095     {{- if .Values.portal.ingress.enabled }}
1096       {{- $_ := set $autoEnv "KONG_PORTAL_GUI_HOST" .Values.portal.ingress.hostname -}}
1097       {{- if .Values.portal.ingress.tls }}
1098         {{- $_ := set $autoEnv "KONG_PORTAL_GUI_PROTOCOL" "https" -}}
1099       {{- else }}
1100         {{- $_ := set $autoEnv "KONG_PORTAL_GUI_PROTOCOL" "http" -}}
1101       {{- end }}
1102     {{- end }}
1103
1104     {{- if .Values.portalapi.ingress.enabled }}
1105       {{- $_ := set $autoEnv "KONG_PORTAL_API_URL" (include "kong.ingress.serviceUrl" .Values.portalapi.ingress) -}}
1106     {{- end }}
1107   {{- end }}
1108
1109   {{- if .Values.enterprise.rbac.enabled }}
1110     {{- $_ := set $autoEnv "KONG_ENFORCE_RBAC" "on" -}}
1111     {{- $_ := set $autoEnv "KONG_ADMIN_GUI_AUTH" .Values.enterprise.rbac.admin_gui_auth | default "basic-auth" -}}
1112
1113     {{- if not (eq .Values.enterprise.rbac.admin_gui_auth "basic-auth") }}
1114       {{- $guiAuthConf := include "secretkeyref" (dict "name" .Values.enterprise.rbac.admin_gui_auth_conf_secret "key" "admin_gui_auth_conf") -}}
1115       {{- $_ := set $autoEnv "KONG_ADMIN_GUI_AUTH_CONF" $guiAuthConf -}}
1116     {{- end }}
1117
1118     {{- $guiSessionConf := include "secretkeyref" (dict "name" .Values.enterprise.rbac.session_conf_secret "key" "admin_gui_session_conf") -}}
1119     {{- $_ := set $autoEnv "KONG_ADMIN_GUI_SESSION_CONF" $guiSessionConf -}}
1120   {{- end }}
1121
1122   {{- if .Values.enterprise.smtp.enabled }}
1123     {{- $_ := set $autoEnv "KONG_SMTP_MOCK" "off" -}}
1124     {{- $_ := set $autoEnv "KONG_PORTAL_EMAILS_FROM" .Values.enterprise.smtp.portal_emails_from -}}
1125     {{- $_ := set $autoEnv "KONG_PORTAL_EMAILS_REPLY_TO" .Values.enterprise.smtp.portal_emails_reply_to -}}
1126     {{- $_ := set $autoEnv "KONG_ADMIN_EMAILS_FROM" .Values.enterprise.smtp.admin_emails_from -}}
1127     {{- $_ := set $autoEnv "KONG_ADMIN_EMAILS_REPLY_TO" .Values.enterprise.smtp.admin_emails_reply_to -}}
1128     {{- $_ := set $autoEnv "KONG_SMTP_ADMIN_EMAILS" .Values.enterprise.smtp.smtp_admin_emails -}}
1129     {{- $_ := set $autoEnv "KONG_SMTP_HOST" .Values.enterprise.smtp.smtp_host -}}
1130     {{- $_ := set $autoEnv "KONG_SMTP_AUTH_TYPE" .Values.enterprise.smtp.smtp_auth_type -}}
1131     {{- $_ := set $autoEnv "KONG_SMTP_SSL" .Values.enterprise.smtp.smtp_ssl -}}
1132     {{- $_ := set $autoEnv "KONG_SMTP_PORT" .Values.enterprise.smtp.smtp_port -}}
1133     {{- $_ := set $autoEnv "KONG_SMTP_STARTTLS" (quote .Values.enterprise.smtp.smtp_starttls) -}}
1134     {{- if .Values.enterprise.smtp.auth.smtp_username }}
1135       {{- $_ := set $autoEnv "KONG_SMTP_USERNAME" .Values.enterprise.smtp.auth.smtp_username -}}
1136       {{- $smtpPassword := include "secretkeyref" (dict "name" .Values.enterprise.smtp.auth.smtp_password_secret "key" "smtp_password") -}}
1137       {{- $_ := set $autoEnv "KONG_SMTP_PASSWORD" $smtpPassword -}}
1138     {{- end }}
1139   {{- else }}
1140     {{- $_ := set $autoEnv "KONG_SMTP_MOCK" "on" -}}
1141   {{- end }}
1142
1143   {{- if .Values.enterprise.license_secret -}}
1144     {{- $lic := include "secretkeyref" (dict "name" .Values.enterprise.license_secret "key" "license") -}}
1145     {{- $_ := set $autoEnv "KONG_LICENSE_DATA" $lic -}}
1146   {{- end }}
1147
1148 {{- end }} {{/* End of the Enterprise settings block */}}
1149
1150 {{- if .Values.postgresql.enabled }}
1151   {{- $_ := set $autoEnv "KONG_PG_HOST" (include "kong.postgresql.fullname" .) -}}
1152   {{- $_ := set $autoEnv "KONG_PG_PORT" .Values.postgresql.service.ports.postgresql -}}
1153   {{- $pgPassword := include "secretkeyref" (dict "name" (include "kong.postgresql.fullname" .) "key" "password") -}}
1154
1155   {{- $_ := set $autoEnv "KONG_PG_PASSWORD" $pgPassword -}}
1156 {{- else if eq .Values.env.database "postgres" }}
1157   {{- $_ := set $autoEnv "KONG_PG_PORT" "5432" }}
1158 {{- end }}
1159
1160 {{- if (and (not .Values.ingressController.enabled) (eq .Values.env.database "off")) }}
1161 {{- $dblessSourceCount := (add (.Values.dblessConfig.configMap | len | min 1) (.Values.dblessConfig.secret | len | min 1) (.Values.dblessConfig.config | len | min 1)) -}}
1162 {{- if eq $dblessSourceCount 1 -}}
1163   {{- $_ := set $autoEnv "KONG_DECLARATIVE_CONFIG" "/kong_dbless/kong.yml" -}}
1164 {{- end }}
1165 {{- end }}
1166
1167 {{- if (.Values.plugins) }}
1168 {{- $_ := set $autoEnv "KONG_PLUGINS" (include "kong.plugins" .) -}}
1169 {{- end }}
1170
1171 {{/*
1172     ====== USER-SET ENVIRONMENT VARIABLES ======
1173 */}}
1174
1175 {{- $userEnv := dict -}}
1176 {{- range $key, $val := .Values.env }}
1177   {{- if (contains "_log" $key) -}}
1178     {{- if (eq (typeOf $val) "bool") -}}
1179       {{- fail (printf "env.%s must use string 'off' to disable. Without quotes, YAML will coerce the value to a boolean and Kong will reject it" $key) -}}
1180         {{- end -}}
1181   {{- end -}}
1182   {{- $upper := upper $key -}}
1183   {{- $var := printf "KONG_%s" $upper -}}
1184   {{- $_ := set $userEnv $var $val -}}
1185 {{- end -}}
1186
1187 {{/*
1188     ====== CUSTOM-SET ENVIRONMENT VARIABLES ======
1189 */}}
1190
1191 {{- $customEnv := dict -}}
1192 {{- range $key, $val := .Values.customEnv }}
1193   {{- $upper := upper $key -}}
1194   {{- $_ := set $customEnv $upper $val -}}
1195 {{- end -}}
1196
1197 {{/*
1198       ====== MERGE AND RENDER ENV BLOCK ======
1199 */}}
1200
1201 {{- $completeEnv := mergeOverwrite $autoEnv $userEnv $customEnv -}}
1202 {{- template "kong.renderEnv" $completeEnv -}}
1203
1204 {{- end -}}
1205
1206 {{/*
1207 Given a dictionary of variable=value pairs, render a container env block.
1208 Environment variables are sorted alphabetically
1209 */}}
1210 {{- define "kong.renderEnv" -}}
1211
1212 {{- $dict := . -}}
1213
1214 {{- range keys . | sortAlpha }}
1215 {{- $val := pluck . $dict | first -}}
1216 {{- $valueType := printf "%T" $val -}}
1217 {{ if eq $valueType "map[string]interface {}" }}
1218 - name: {{ . }}
1219 {{ toYaml $val | indent 2 -}}
1220 {{- else if eq $valueType "string" }}
1221 {{- if regexMatch "valueFrom" $val }}
1222 - name: {{ . }}
1223 {{ $val | indent 2 }}
1224 {{- else }}
1225 - name: {{ . }}
1226   value: {{ $val | quote }}
1227 {{- end }}
1228 {{- else }}
1229 - name: {{ . }}
1230   value: {{ $val | quote }}
1231 {{- end }}
1232 {{- end -}}
1233
1234 {{- end -}}
1235
1236 {{- define "kong.wait-for-postgres" -}}
1237 - name: wait-for-postgres
1238 {{- if (or .Values.waitImage.unifiedRepoTag .Values.waitImage.repository) }}
1239   image: {{ include "kong.getRepoTag" .Values.waitImage }}
1240 {{- else }} {{/* default to the Kong image */}}
1241   image: {{ include "kong.getRepoTag" .Values.image }}
1242 {{- end }}
1243   imagePullPolicy: {{ .Values.waitImage.pullPolicy }}
1244   env:
1245   {{- include "kong.no_daemon_env" . | nindent 2 }}
1246   {{- include "kong.envFrom" .Values.envFrom | nindent 2 }}
1247   command: [ "bash", "/wait_postgres/wait.sh" ]
1248   volumeMounts:
1249   - name: {{ template "kong.fullname" . }}-bash-wait-for-postgres
1250     mountPath: /wait_postgres
1251   resources:
1252   {{- toYaml .Values.migrations.resources | nindent 4 }}
1253 {{- end -}}
1254
1255 {{- define "kong.deprecation-warnings" -}}
1256   {{- $warnings := list -}}
1257   {{- range $warning := . }}
1258     {{- $warnings = append $warnings (wrap 80 (printf "WARNING: %s" $warning)) -}}
1259     {{- $warnings = append $warnings "\n\n" -}}
1260   {{- end -}}
1261   {{- $warningString := ($warnings | join "") -}}
1262   {{- $warningString -}}
1263 {{- end -}}
1264
1265 {{- define "kong.getRepoTag" -}}
1266 {{- if .unifiedRepoTag }}
1267 {{- .unifiedRepoTag }}
1268 {{- else if .repository }}
1269 {{- .repository }}:{{ .tag }}
1270 {{- end -}}
1271 {{- end -}}
1272
1273 {{/*
1274 kong.kubernetesRBACRoles outputs a static list of RBAC rules (the "rules" block
1275 of a Role or ClusterRole) that provide the ingress controller access to the
1276 Kubernetes namespace-scoped resources it uses to build Kong configuration.
1277
1278 Collectively, these are built from:
1279 kubectl kustomize github.com/kong/kubernetes-ingress-controller/config/rbac?ref=main
1280 kubectl kustomize github.com/kong/kubernetes-ingress-controller/config/rbac/gateway?ref=main
1281
1282 However, there is no way to generate the split between cluster and namespaced
1283 role sets used in the charts. Updating these requires separating out cluster
1284 resource roles into their separate templates.
1285 */}}
1286 {{- define "kong.kubernetesRBACRules" -}}
1287 {{- if and (semverCompare ">= 3.1.0" (include "kong.effectiveVersion" .Values.ingressController.image))
1288            (contains (print .Values.ingressController.env.feature_gates) "KongServiceFacade=true") }}
1289 - apiGroups:
1290   - incubator.ingress-controller.konghq.com
1291   resources:
1292   - kongservicefacades
1293   verbs:
1294   - get
1295   - list
1296   - watch
1297 - apiGroups:
1298   - incubator.ingress-controller.konghq.com
1299   resources:
1300   - kongservicefacades/status
1301   verbs:
1302   - get
1303   - patch
1304   - update
1305 {{- end }}
1306 {{- if (semverCompare ">= 3.0.0" (include "kong.effectiveVersion" .Values.ingressController.image)) }}
1307 - apiGroups:
1308   - configuration.konghq.com
1309   resources:
1310   - kongupstreampolicies
1311   verbs:
1312   - get
1313   - list
1314   - watch
1315 - apiGroups:
1316   - configuration.konghq.com
1317   resources:
1318   - kongupstreampolicies/status
1319   verbs:
1320   - get
1321   - patch
1322   - update
1323 {{- end }}
1324 {{- if (semverCompare ">= 2.11.0" (include "kong.effectiveVersion" .Values.ingressController.image)) }}
1325 - apiGroups:
1326   - configuration.konghq.com
1327   resources:
1328   - kongconsumergroups
1329   verbs:
1330   - get
1331   - list
1332   - watch
1333 - apiGroups:
1334   - configuration.konghq.com
1335   resources:
1336   - kongconsumergroups/status
1337   verbs:
1338   - get
1339   - patch
1340   - update
1341 {{- end }}
1342 {{- if (semverCompare "< 2.10.0" (include "kong.effectiveVersion" .Values.ingressController.image)) }}
1343 - apiGroups:
1344   - ""
1345   resources:
1346   - endpoints
1347   verbs:
1348   - list
1349   - watch
1350 {{- end }}
1351 - apiGroups:
1352   - ""
1353   resources:
1354   - events
1355   verbs:
1356   - create
1357   - patch
1358 - apiGroups:
1359   - ""
1360   resources:
1361   - nodes
1362   verbs:
1363   - list
1364   - watch
1365 - apiGroups:
1366   - ""
1367   resources:
1368   - pods
1369   verbs:
1370   - get
1371   - list
1372   - watch
1373 - apiGroups:
1374   - ""
1375   resources:
1376   - secrets
1377   verbs:
1378   - list
1379   - watch
1380 - apiGroups:
1381   - ""
1382   resources:
1383   - services
1384   verbs:
1385   - get
1386   - list
1387   - watch
1388 - apiGroups:
1389   - ""
1390   resources:
1391   - services/status
1392   verbs:
1393   - get
1394   - patch
1395   - update
1396 - apiGroups:
1397   - configuration.konghq.com
1398   resources:
1399   - ingressclassparameterses
1400   verbs:
1401   - get
1402   - list
1403   - watch
1404 - apiGroups:
1405   - configuration.konghq.com
1406   resources:
1407   - kongconsumers
1408   verbs:
1409   - get
1410   - list
1411   - watch
1412 - apiGroups:
1413   - configuration.konghq.com
1414   resources:
1415   - kongconsumers/status
1416   verbs:
1417   - get
1418   - patch
1419   - update
1420 - apiGroups:
1421   - configuration.konghq.com
1422   resources:
1423   - kongingresses
1424   verbs:
1425   - get
1426   - list
1427   - watch
1428 - apiGroups:
1429   - configuration.konghq.com
1430   resources:
1431   - kongingresses/status
1432   verbs:
1433   - get
1434   - patch
1435   - update
1436 - apiGroups:
1437   - configuration.konghq.com
1438   resources:
1439   - kongplugins
1440   verbs:
1441   - get
1442   - list
1443   - watch
1444 - apiGroups:
1445   - configuration.konghq.com
1446   resources:
1447   - kongplugins/status
1448   verbs:
1449   - get
1450   - patch
1451   - update
1452 - apiGroups:
1453   - configuration.konghq.com
1454   resources:
1455   - tcpingresses
1456   verbs:
1457   - get
1458   - list
1459   - watch
1460 - apiGroups:
1461   - configuration.konghq.com
1462   resources:
1463   - tcpingresses/status
1464   verbs:
1465   - get
1466   - patch
1467   - update
1468 - apiGroups:
1469   - configuration.konghq.com
1470   resources:
1471   - udpingresses
1472   verbs:
1473   - get
1474   - list
1475   - watch
1476 - apiGroups:
1477   - configuration.konghq.com
1478   resources:
1479   - udpingresses/status
1480   verbs:
1481   - get
1482   - patch
1483   - update
1484 - apiGroups:
1485   - extensions
1486   resources:
1487   - ingresses
1488   verbs:
1489   - get
1490   - list
1491   - watch
1492 - apiGroups:
1493   - extensions
1494   resources:
1495   - ingresses/status
1496   verbs:
1497   - get
1498   - patch
1499   - update
1500 {{- if or (.Capabilities.APIVersions.Has "gateway.networking.k8s.io/v1alpha2") (.Capabilities.APIVersions.Has "gateway.networking.k8s.io/v1beta1") (.Capabilities.APIVersions.Has "gateway.networking.k8s.io/v1")}}
1501 - apiGroups:
1502   - gateway.networking.k8s.io
1503   resources:
1504   - gateways
1505   verbs:
1506   - get
1507   - list
1508   - update
1509   - watch
1510 - apiGroups:
1511   - gateway.networking.k8s.io
1512   resources:
1513   - gateways/status
1514   verbs:
1515   - get
1516   - update
1517 - apiGroups:
1518   - gateway.networking.k8s.io
1519   resources:
1520   - httproutes
1521   verbs:
1522   - get
1523   - list
1524   - watch
1525 - apiGroups:
1526   - gateway.networking.k8s.io
1527   resources:
1528   - httproutes/status
1529   verbs:
1530   - get
1531   - update
1532 - apiGroups:
1533   - gateway.networking.k8s.io
1534   resources:
1535   - referencegrants
1536   verbs:
1537   - get
1538   - list
1539   - watch
1540 - apiGroups:
1541   - gateway.networking.k8s.io
1542   resources:
1543   - referencegrants/status
1544   verbs:
1545   - get
1546 - apiGroups:
1547   - gateway.networking.k8s.io
1548   resources:
1549   - tcproutes
1550   verbs:
1551   - get
1552   - list
1553   - watch
1554 - apiGroups:
1555   - gateway.networking.k8s.io
1556   resources:
1557   - tcproutes/status
1558   verbs:
1559   - get
1560   - update
1561 - apiGroups:
1562   - gateway.networking.k8s.io
1563   resources:
1564   - tlsroutes
1565   verbs:
1566   - get
1567   - list
1568   - watch
1569 - apiGroups:
1570   - gateway.networking.k8s.io
1571   resources:
1572   - tlsroutes/status
1573   verbs:
1574   - get
1575   - update
1576 - apiGroups:
1577   - gateway.networking.k8s.io
1578   resources:
1579   - udproutes
1580   verbs:
1581   - get
1582   - list
1583   - watch
1584 - apiGroups:
1585   - gateway.networking.k8s.io
1586   resources:
1587   - udproutes/status
1588   verbs:
1589   - get
1590   - update
1591 - apiGroups:
1592   - gateway.networking.k8s.io
1593   resources:
1594   - grpcroutes
1595   verbs:
1596   - get
1597   - list
1598   - watch
1599 - apiGroups:
1600   - gateway.networking.k8s.io
1601   resources:
1602   - grpcroutes/status
1603   verbs:
1604   - get
1605   - patch
1606   - update
1607 {{- end }}
1608 {{- if (.Capabilities.APIVersions.Has "networking.internal.knative.dev/v1alpha1") }}
1609 - apiGroups:
1610   - networking.internal.knative.dev
1611   resources:
1612   - ingresses
1613   verbs:
1614   - get
1615   - list
1616   - watch
1617 - apiGroups:
1618   - networking.internal.knative.dev
1619   resources:
1620   - ingresses/status
1621   verbs:
1622   - get
1623   - patch
1624   - update
1625 {{- end }}
1626 - apiGroups:
1627   - networking.k8s.io
1628   resources:
1629   - ingresses
1630   verbs:
1631   - get
1632   - list
1633   - watch
1634 - apiGroups:
1635   - networking.k8s.io
1636   resources:
1637   - ingresses/status
1638   verbs:
1639   - get
1640   - patch
1641   - update
1642 - apiGroups:
1643   - discovery.k8s.io
1644   resources:
1645   - endpointslices
1646   verbs:
1647   - get
1648   - list
1649   - watch
1650 {{- if (semverCompare ">= 3.1.0" (include "kong.effectiveVersion" .Values.ingressController.image)) }}
1651 - apiGroups:
1652   - configuration.konghq.com
1653   resources:
1654   - konglicenses
1655   verbs:
1656   - get
1657   - list
1658   - watch
1659 - apiGroups:
1660   - configuration.konghq.com
1661   resources:
1662   - konglicenses/status
1663   verbs:
1664   - get
1665   - patch
1666   - update
1667 {{- end -}}
1668 {{- end -}}
1669
1670 {{/*
1671 kong.kubernetesRBACClusterRoles outputs a static list of RBAC rules (the "rules" block
1672 of a Role or ClusterRole) that provide the ingress controller access to the
1673 Kubernetes Cluster-scoped resources it uses to build Kong configuration.
1674 */}}
1675 {{- define "kong.kubernetesRBACClusterRules" -}}
1676 {{- if (semverCompare ">= 3.1.0" (include "kong.effectiveVersion" .Values.ingressController.image)) }}
1677 - apiGroups:
1678   - configuration.konghq.com
1679   resources:
1680   - kongvaults
1681   verbs:
1682   - get
1683   - list
1684   - watch
1685 - apiGroups:
1686   - configuration.konghq.com
1687   resources:
1688   - kongvaults/status
1689   verbs:
1690   - get
1691   - patch
1692   - update
1693 {{- end }}
1694 - apiGroups:
1695   - configuration.konghq.com
1696   resources:
1697   - kongclusterplugins
1698   verbs:
1699   - get
1700   - list
1701   - watch
1702 - apiGroups:
1703   - configuration.konghq.com
1704   resources:
1705   - kongclusterplugins/status
1706   verbs:
1707   - get
1708   - patch
1709   - update
1710 {{- if (semverCompare ">= 2.10.0" (include "kong.effectiveVersion" .Values.ingressController.image)) }}
1711 - apiGroups:
1712   - apiextensions.k8s.io
1713   resources:
1714   - customresourcedefinitions
1715   verbs:
1716   - list
1717   - watch
1718 {{- end }}
1719 {{- if or (.Capabilities.APIVersions.Has "gateway.networking.k8s.io/v1alpha2") (.Capabilities.APIVersions.Has "gateway.networking.k8s.io/v1beta1") (.Capabilities.APIVersions.Has "gateway.networking.k8s.io/v1")}}
1720 - apiGroups:
1721   - gateway.networking.k8s.io
1722   resources:
1723   - gatewayclasses
1724   verbs:
1725   - get
1726   - list
1727   - watch
1728 - apiGroups:
1729   - gateway.networking.k8s.io
1730   resources:
1731   - gatewayclasses/status
1732   verbs:
1733   - get
1734   - update
1735 - apiGroups:
1736   - ""
1737   resources:
1738   - namespaces
1739   verbs:
1740   - get
1741   - list
1742   - watch
1743 {{- end }}
1744 - apiGroups:
1745   - networking.k8s.io
1746   resources:
1747   - ingressclasses
1748   verbs:
1749   - get
1750   - list
1751   - watch
1752 {{- end -}}
1753
1754 {{- define "kong.autoscalingVersion" -}}
1755 {{- if (.Capabilities.APIVersions.Has "autoscaling/v2") -}}
1756 autoscaling/v2
1757 {{- else if (.Capabilities.APIVersions.Has "autoscaling/v2beta2") -}}
1758 autoscaling/v2beta2
1759 {{- else -}}
1760 autoscaling/v1
1761 {{- end -}}
1762 {{- end -}}
1763
1764 {{- define "kong.policyVersion" -}}
1765 {{- if (.Capabilities.APIVersions.Has "policy/v1beta1" ) -}}
1766 policy/v1beta1
1767 {{- else -}}
1768 {{- fail (printf "Cluster doesn't have policy/v1beta1 API." ) }}
1769 {{- end -}}
1770 {{- end -}}
1771
1772 {{- define "kong.renderTpl" -}}
1773     {{- if typeIs "string" .value }}
1774 {{- tpl .value .context }}
1775     {{- else }}
1776 {{- tpl (.value | toYaml) .context }}
1777     {{- end }}
1778 {{- end -}}
1779
1780 {{- define "kong.ingressVersion" -}}
1781 {{- if (.Capabilities.APIVersions.Has "networking.k8s.io/v1") -}}
1782 networking.k8s.io/v1
1783 {{- else if (.Capabilities.APIVersions.Has "networking.k8s.io/v1beta1") -}}
1784 networking.k8s.io/v1beta1
1785 {{- else -}}
1786 extensions/v1beta1
1787 {{- end -}}
1788 {{- end -}}
1789
1790 {{- define "kong.proxy.compatibleReadiness" -}}
1791 {{- $proxyReadiness := .Values.readinessProbe -}}
1792 {{- if (or (semverCompare "< 3.3.0" (include "kong.effectiveVersion" .Values.image)) (and .Values.ingressController.enabled (semverCompare "< 2.11.0" (include "kong.effectiveVersion" .Values.ingressController.image)))) -}}
1793     {{- if (eq $proxyReadiness.httpGet.path "/status/ready") -}}
1794         {{- $_ := set $proxyReadiness.httpGet "path" "/status" -}}
1795     {{- end -}}
1796 {{- end -}}
1797 {{- (toYaml $proxyReadiness) -}}
1798 {{- end -}}
1799
1800 {{- define "kong.envFrom" -}}
1801   {{- if (gt (len .) 0) -}}
1802 envFrom:
1803 {{- toYaml . | nindent 2 -}}
1804   {{- else -}}
1805   {{- end -}}
1806 {{- end -}}