Extend K8S and RIC installation instructions
[it/dep.git] / ric-infra / 30-Kong / helm / kong / charts / 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.name" -}}
8 {{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
9 {{- end -}}
10
11 {{- define "kong.fullname" -}}
12 {{- $name := default .Chart.Name .Values.nameOverride -}}
13 {{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
14 {{- end -}}
15
16 {{- define "kong.postgresql.fullname" -}}
17 {{- $name := default "postgresql" .Values.postgresql.nameOverride -}}
18 {{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
19 {{- end -}}
20
21 {{- define "kong.cassandra.fullname" -}}
22 {{- $name := default "cassandra" .Values.cassandra.nameOverride -}}
23 {{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
24 {{- end -}}
25
26 {{- define "kong.dblessConfig.fullname" -}}
27 {{- $name := default "kong-custom-dbless-config" .Values.dblessConfig.nameOverride -}}
28 {{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
29 {{- end -}}
30
31 {{/*
32 Create the name of the service account to use
33 */}}
34 {{- define "kong.serviceAccountName" -}}
35 {{- if .Values.ingressController.serviceAccount.create -}}
36     {{ default (include "kong.fullname" .) .Values.ingressController.serviceAccount.name }}
37 {{- else -}}
38     {{ default "default" .Values.serviceAccount.name }}
39 {{- end -}}
40 {{- end -}}
41
42 {{/*
43 Create the KONG_PROXY_LISTEN value string
44 */}}
45 {{- define "kong.kongProxyListenValue" -}}
46
47 {{- if and .Values.proxy.http.enabled .Values.proxy.tls.enabled -}}
48    0.0.0.0:{{ .Values.proxy.http.containerPort }},0.0.0.0:{{ .Values.proxy.tls.containerPort }} ssl
49 {{- else -}}
50 {{- if .Values.proxy.http.enabled -}}
51    0.0.0.0:{{ .Values.proxy.http.containerPort }}
52 {{- end -}}
53 {{- if .Values.proxy.tls.enabled -}}
54    0.0.0.0:{{ .Values.proxy.tls.containerPort }} ssl
55 {{- end -}}
56 {{- end -}}
57
58 {{- end }}
59
60 {{/*
61 Create the KONG_ADMIN_GUI_LISTEN value string
62 */}}
63 {{- define "kong.kongManagerListenValue" -}}
64
65 {{- if and .Values.manager.http.enabled .Values.manager.tls.enabled -}}
66    0.0.0.0:{{ .Values.manager.http.containerPort }},0.0.0.0:{{ .Values.manager.tls.containerPort }} ssl
67 {{- else -}}
68 {{- if .Values.manager.http.enabled -}}
69    0.0.0.0:{{ .Values.manager.http.containerPort }}
70 {{- end -}}
71 {{- if .Values.manager.tls.enabled -}}
72    0.0.0.0:{{ .Values.manager.tls.containerPort }} ssl
73 {{- end -}}
74 {{- end -}}
75
76 {{- end }}
77
78 {{/*
79 Create the KONG_PORTAL_GUI_LISTEN value string
80 */}}
81 {{- define "kong.kongPortalListenValue" -}}
82
83 {{- if and .Values.portal.http.enabled .Values.portal.tls.enabled -}}
84    0.0.0.0:{{ .Values.portal.http.containerPort }},0.0.0.0:{{ .Values.portal.tls.containerPort }} ssl
85 {{- else -}}
86 {{- if .Values.portal.http.enabled -}}
87    0.0.0.0:{{ .Values.portal.http.containerPort }}
88 {{- end -}}
89 {{- if .Values.portal.tls.enabled -}}
90    0.0.0.0:{{ .Values.portal.tls.containerPort }} ssl
91 {{- end -}}
92 {{- end -}}
93
94 {{- end }}
95
96 {{/*
97 Create the KONG_PORTAL_API_LISTEN value string
98 */}}
99 {{- define "kong.kongPortalApiListenValue" -}}
100
101 {{- if and .Values.portalapi.http.enabled .Values.portalapi.tls.enabled -}}
102    0.0.0.0:{{ .Values.portalapi.http.containerPort }},0.0.0.0:{{ .Values.portalapi.tls.containerPort }} ssl
103 {{- else -}}
104 {{- if .Values.portalapi.http.enabled -}}
105    0.0.0.0:{{ .Values.portalapi.http.containerPort }}
106 {{- end -}}
107 {{- if .Values.portalapi.tls.enabled -}}
108    0.0.0.0:{{ .Values.portalapi.tls.containerPort }} ssl
109 {{- end -}}
110 {{- end -}}
111
112 {{- end }}
113
114 {{/*
115 Create the ingress servicePort value string
116 */}}
117
118 {{- define "kong.ingress.servicePort" -}}
119 {{- if .tls.enabled -}}
120    {{ .tls.servicePort }}
121 {{- else -}}
122    {{ .http.servicePort }}
123 {{- end -}}
124 {{- end -}}
125
126
127 {{- define "kong.env" -}}
128 {{- range $key, $val := .Values.env }}
129 - name: KONG_{{ $key | upper}}
130 {{- $valueType := printf "%T" $val -}}
131 {{ if eq $valueType "map[string]interface {}" }}
132 {{ toYaml $val | indent 2 -}}
133 {{- else }}
134   value: {{ $val | quote -}}
135 {{- end -}}
136 {{- end -}}
137 {{- end -}}
138
139 {{- define "kong.wait-for-db" -}}
140 - name: wait-for-db
141   image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
142   imagePullPolicy: {{ .Values.image.pullPolicy }}
143   env:
144   {{- if .Values.enterprise.enabled }}
145   {{- include "kong.license" . | nindent 2 }}
146   {{- end }}
147   {{- if .Values.postgresql.enabled }}
148   - name: KONG_PG_HOST
149     value: {{ template "kong.postgresql.fullname" . }}
150   - name: KONG_PG_PORT
151     value: "{{ .Values.postgresql.service.port }}"
152   - name: KONG_PG_PASSWORD
153     valueFrom:
154       secretKeyRef:
155         name: {{ template "kong.postgresql.fullname" . }}
156         key: postgresql-password
157   {{- end }}
158   {{- if .Values.cassandra.enabled }}
159   - name: KONG_CASSANDRA_CONTACT_POINTS
160     value: {{ template "kong.cassandra.fullname" . }}
161   {{- end }}
162   {{- include "kong.env" .  | nindent 2 }}
163   command: [ "/bin/sh", "-c", "until kong start; do echo 'waiting for db'; sleep 1; done; kong stop" ]
164 {{- end -}}
165
166 {{- define "kong.controller-container" -}}
167 - name: ingress-controller
168   args:
169   - /kong-ingress-controller
170   # Service from were we extract the IP address/es to use in Ingress status
171   - --publish-service={{ .Release.Namespace }}/{{ template "kong.fullname" . }}-proxy
172   # Set the ingress class
173   - --ingress-class={{ .Values.ingressController.ingressClass }}
174   - --election-id=kong-ingress-controller-leader-{{ .Values.ingressController.ingressClass }}
175   # the kong URL points to the kong admin api server
176   {{- if .Values.admin.useTLS }}
177   - --kong-url=https://localhost:{{ .Values.admin.containerPort }}
178   - --admin-tls-skip-verify # TODO make this configurable
179   {{- else }}
180   - --kong-url=http://localhost:{{ .Values.admin.containerPort }}
181   {{- end }}
182   env:
183   - name: POD_NAME
184     valueFrom:
185       fieldRef:
186         apiVersion: v1
187         fieldPath: metadata.name
188   - name: POD_NAMESPACE
189     valueFrom:
190       fieldRef:
191         apiVersion: v1
192         fieldPath: metadata.namespace
193   image: "{{ .Values.ingressController.image.repository }}:{{ .Values.ingressController.image.tag }}"
194   imagePullPolicy: {{ .Values.image.pullPolicy }}
195   livenessProbe:
196     failureThreshold: 3
197     httpGet:
198       path: /healthz
199       port: 10254
200       scheme: HTTP
201     initialDelaySeconds: 30
202     periodSeconds: 10
203     successThreshold: 1
204     timeoutSeconds: 1
205   readinessProbe:
206     failureThreshold: 3
207     httpGet:
208       path: /healthz
209       port: 10254
210       scheme: HTTP
211     periodSeconds: 10
212     successThreshold: 1
213     timeoutSeconds: 1
214   resources:
215 {{ toYaml .Values.ingressController.resources | indent 10 }}
216 {{- end -}}
217
218 {{/*
219 Retrieve Kong Enterprise license from a secret and make it available in env vars
220 */}}
221 {{- define "kong.license" -}}
222 - name: KONG_LICENSE_DATA
223   valueFrom:
224     secretKeyRef:
225       name: {{ .Values.enterprise.license_secret }}
226       key: license
227 {{- end -}}