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