3ee55726e7ddab8a3b25a2aff400d388eec03ceb
[it/dep.git] / ric-aux / helm / infrastructure / subcharts / kong / charts / postgresql / templates / _helpers.tpl
1 {{/* vim: set filetype=mustache: */}}
2 {{/*
3 Expand the name of the chart.
4 */}}
5 {{- define "postgresql.name" -}}
6 {{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
7 {{- end -}}
8
9 {{/*
10 Create a default fully qualified app name.
11 We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
12 */}}
13 {{- define "postgresql.fullname" -}}
14 {{- if .Values.fullnameOverride -}}
15 {{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}}
16 {{- else -}}
17 {{- $name := default .Chart.Name .Values.nameOverride -}}
18 {{- if contains $name .Release.Name -}}
19 {{- .Release.Name | trunc 63 | trimSuffix "-" -}}
20 {{- else -}}
21 {{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
22 {{- end -}}
23 {{- end -}}
24 {{- end -}}
25 {{/*
26 Create a default fully qualified app name.
27 We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
28 */}}
29 {{- define "postgresql.master.fullname" -}}
30 {{- $name := default .Chart.Name .Values.nameOverride -}}
31 {{- $fullname := default (printf "%s-%s" .Release.Name $name) .Values.fullnameOverride -}}
32 {{- if .Values.replication.enabled -}}
33 {{- printf "%s-%s" $fullname "master" | trunc 63 | trimSuffix "-" -}}
34 {{- else -}}
35 {{- printf "%s" $fullname | trunc 63 | trimSuffix "-" -}}
36 {{- end -}}
37 {{- end -}}
38
39 {{/*
40 Return the appropriate apiVersion for networkpolicy.
41 */}}
42 {{- define "postgresql.networkPolicy.apiVersion" -}}
43 {{- if semverCompare ">=1.4-0, <1.7-0" .Capabilities.KubeVersion.GitVersion -}}
44 "extensions/v1beta1"
45 {{- else if semverCompare "^1.7-0" .Capabilities.KubeVersion.GitVersion -}}
46 "networking.k8s.io/v1"
47 {{- end -}}
48 {{- end -}}
49
50 {{/*
51 Create chart name and version as used by the chart label.
52 */}}
53 {{- define "postgresql.chart" -}}
54 {{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
55 {{- end -}}
56
57 {{/*
58 Return the proper PostgreSQL image name
59 */}}
60 {{- define "postgresql.image" -}}
61 {{- $registryName := .Values.image.registry -}}
62 {{- $repositoryName := .Values.image.repository -}}
63 {{- $tag := .Values.image.tag | toString -}}
64 {{/*
65 Helm 2.11 supports the assignment of a value to a variable defined in a different scope,
66 but Helm 2.9 and 2.10 doesn't support it, so we need to implement this if-else logic.
67 Also, we can't use a single if because lazy evaluation is not an option
68 */}}
69 {{- if .Values.global }}
70     {{- if .Values.global.imageRegistry }}
71         {{- printf "%s/%s:%s" .Values.global.imageRegistry $repositoryName $tag -}}
72     {{- else -}}
73         {{- printf "%s/%s:%s" $registryName $repositoryName $tag -}}
74     {{- end -}}
75 {{- else -}}
76     {{- printf "%s/%s:%s" $registryName $repositoryName $tag -}}
77 {{- end -}}
78 {{- end -}}
79
80 {{/*
81 Return PostgreSQL postgres user password
82 */}}
83 {{- define "postgresql.postgres.password" -}}
84 {{- if .Values.global.postgresql.postgresqlPostgresPassword }}
85     {{- .Values.global.postgresql.postgresqlPostgresPassword -}}
86 {{- else if .Values.postgresqlPostgresPassword -}}
87     {{- .Values.postgresqlPostgresPassword -}}
88 {{- else -}}
89     {{- randAlphaNum 10 -}}
90 {{- end -}}
91 {{- end -}}
92
93 {{/*
94 Return PostgreSQL password
95 */}}
96 {{- define "postgresql.password" -}}
97 {{- if .Values.global.postgresql.postgresqlPassword }}
98     {{- .Values.global.postgresql.postgresqlPassword -}}
99 {{- else if .Values.postgresqlPassword -}}
100     {{- .Values.postgresqlPassword -}}
101 {{- else -}}
102     {{- randAlphaNum 10 -}}
103 {{- end -}}
104 {{- end -}}
105
106 {{/*
107 Return PostgreSQL replication password
108 */}}
109 {{- define "postgresql.replication.password" -}}
110 {{- if .Values.global.postgresql.replicationPassword }}
111     {{- .Values.global.postgresql.replicationPassword -}}
112 {{- else if .Values.replication.password -}}
113     {{- .Values.replication.password -}}
114 {{- else -}}
115     {{- randAlphaNum 10 -}}
116 {{- end -}}
117 {{- end -}}
118
119 {{/*
120 Return PostgreSQL username
121 */}}
122 {{- define "postgresql.username" -}}
123 {{- if .Values.global.postgresql.postgresqlUsername }}
124     {{- .Values.global.postgresql.postgresqlUsername -}}
125 {{- else -}}
126     {{- .Values.postgresqlUsername -}}
127 {{- end -}}
128 {{- end -}}
129
130
131 {{/*
132 Return PostgreSQL replication username
133 */}}
134 {{- define "postgresql.replication.username" -}}
135 {{- if .Values.global.postgresql.replicationUser }}
136     {{- .Values.global.postgresql.replicationUser -}}
137 {{- else -}}
138     {{- .Values.replication.user -}}
139 {{- end -}}
140 {{- end -}}
141
142 {{/*
143 Return PostgreSQL port
144 */}}
145 {{- define "postgresql.port" -}}
146 {{- if .Values.global.postgresql.servicePort }}
147     {{- .Values.global.postgresql.servicePort -}}
148 {{- else -}}
149     {{- .Values.service.port -}}
150 {{- end -}}
151 {{- end -}}
152
153 {{/*
154 Return PostgreSQL created database
155 */}}
156 {{- define "postgresql.database" -}}
157 {{- if .Values.global.postgresql.postgresqlDatabase }}
158     {{- .Values.global.postgresql.postgresqlDatabase -}}
159 {{- else if .Values.postgresqlDatabase -}}
160     {{- .Values.postgresqlDatabase -}}
161 {{- end -}}
162 {{- end -}}
163
164 {{/*
165 Return the proper image name to change the volume permissions
166 */}}
167 {{- define "postgresql.volumePermissions.image" -}}
168 {{- $registryName := .Values.volumePermissions.image.registry -}}
169 {{- $repositoryName := .Values.volumePermissions.image.repository -}}
170 {{- $tag := .Values.volumePermissions.image.tag | toString -}}
171 {{/*
172 Helm 2.11 supports the assignment of a value to a variable defined in a different scope,
173 but Helm 2.9 and 2.10 doesn't support it, so we need to implement this if-else logic.
174 Also, we can't use a single if because lazy evaluation is not an option
175 */}}
176 {{- if .Values.global }}
177     {{- if .Values.global.imageRegistry }}
178         {{- printf "%s/%s:%s" .Values.global.imageRegistry $repositoryName $tag -}}
179     {{- else -}}
180         {{- printf "%s/%s:%s" $registryName $repositoryName $tag -}}
181     {{- end -}}
182 {{- else -}}
183     {{- printf "%s/%s:%s" $registryName $repositoryName $tag -}}
184 {{- end -}}
185 {{- end -}}
186
187 {{/*
188 Return the proper PostgreSQL metrics image name
189 */}}
190 {{- define "postgresql.metrics.image" -}}
191 {{- $registryName :=  default "docker.io" .Values.metrics.image.registry -}}
192 {{- $repositoryName := .Values.metrics.image.repository -}}
193 {{- $tag := default "latest" .Values.metrics.image.tag | toString -}}
194 {{/*
195 Helm 2.11 supports the assignment of a value to a variable defined in a different scope,
196 but Helm 2.9 and 2.10 doesn't support it, so we need to implement this if-else logic.
197 Also, we can't use a single if because lazy evaluation is not an option
198 */}}
199 {{- if .Values.global }}
200     {{- if .Values.global.imageRegistry }}
201         {{- printf "%s/%s:%s" .Values.global.imageRegistry $repositoryName $tag -}}
202     {{- else -}}
203         {{- printf "%s/%s:%s" $registryName $repositoryName $tag -}}
204     {{- end -}}
205 {{- else -}}
206     {{- printf "%s/%s:%s" $registryName $repositoryName $tag -}}
207 {{- end -}}
208 {{- end -}}
209
210 {{/*
211 Get the password secret.
212 */}}
213 {{- define "postgresql.secretName" -}}
214 {{- if .Values.global.postgresql.existingSecret }}
215     {{- printf "%s" .Values.global.postgresql.existingSecret -}}
216 {{- else if .Values.existingSecret -}}
217     {{- printf "%s" .Values.existingSecret -}}
218 {{- else -}}
219     {{- printf "%s" (include "postgresql.fullname" .) -}}
220 {{- end -}}
221 {{- end -}}
222
223 {{/*
224 Return true if a secret object should be created
225 */}}
226 {{- define "postgresql.createSecret" -}}
227 {{- if .Values.global.postgresql.existingSecret }}
228 {{- else if .Values.existingSecret -}}
229 {{- else -}}
230     {{- true -}}
231 {{- end -}}
232 {{- end -}}
233
234 {{/*
235 Get the configuration ConfigMap name.
236 */}}
237 {{- define "postgresql.configurationCM" -}}
238 {{- if .Values.configurationConfigMap -}}
239 {{- printf "%s" (tpl .Values.configurationConfigMap $) -}}
240 {{- else -}}
241 {{- printf "%s-configuration" (include "postgresql.fullname" .) -}}
242 {{- end -}}
243 {{- end -}}
244
245 {{/*
246 Get the extended configuration ConfigMap name.
247 */}}
248 {{- define "postgresql.extendedConfigurationCM" -}}
249 {{- if .Values.extendedConfConfigMap -}}
250 {{- printf "%s" (tpl .Values.extendedConfConfigMap $) -}}
251 {{- else -}}
252 {{- printf "%s-extended-configuration" (include "postgresql.fullname" .) -}}
253 {{- end -}}
254 {{- end -}}
255
256 {{/*
257 Get the initialization scripts ConfigMap name.
258 */}}
259 {{- define "postgresql.initdbScriptsCM" -}}
260 {{- if .Values.initdbScriptsConfigMap -}}
261 {{- printf "%s" (tpl .Values.initdbScriptsConfigMap $) -}}
262 {{- else -}}
263 {{- printf "%s-init-scripts" (include "postgresql.fullname" .) -}}
264 {{- end -}}
265 {{- end -}}
266
267 {{/*
268 Get the initialization scripts Secret name.
269 */}}
270 {{- define "postgresql.initdbScriptsSecret" -}}
271 {{- printf "%s" (tpl .Values.initdbScriptsSecret $) -}}
272 {{- end -}}
273
274 {{/*
275 Get the metrics ConfigMap name.
276 */}}
277 {{- define "postgresql.metricsCM" -}}
278 {{- printf "%s-metrics" (include "postgresql.fullname" .) -}}
279 {{- end -}}
280
281 {{/*
282 Return the proper Docker Image Registry Secret Names
283 */}}
284 {{- define "postgresql.imagePullSecrets" -}}
285 {{/*
286 Helm 2.11 supports the assignment of a value to a variable defined in a different scope,
287 but Helm 2.9 and 2.10 does not support it, so we need to implement this if-else logic.
288 Also, we can not use a single if because lazy evaluation is not an option
289 */}}
290 {{- if .Values.global }}
291 {{- if .Values.global.imagePullSecrets }}
292 imagePullSecrets:
293 {{- range .Values.global.imagePullSecrets }}
294   - name: {{ . }}
295 {{- end }}
296 {{- else if or .Values.image.pullSecrets .Values.metrics.image.pullSecrets .Values.volumePermissions.image.pullSecrets }}
297 imagePullSecrets:
298 {{- range .Values.image.pullSecrets }}
299   - name: {{ . }}
300 {{- end }}
301 {{- range .Values.metrics.image.pullSecrets }}
302   - name: {{ . }}
303 {{- end }}
304 {{- range .Values.volumePermissions.image.pullSecrets }}
305   - name: {{ . }}
306 {{- end }}
307 {{- end -}}
308 {{- else if or .Values.image.pullSecrets .Values.metrics.image.pullSecrets .Values.volumePermissions.image.pullSecrets }}
309 imagePullSecrets:
310 {{- range .Values.image.pullSecrets }}
311   - name: {{ . }}
312 {{- end }}
313 {{- range .Values.metrics.image.pullSecrets }}
314   - name: {{ . }}
315 {{- end }}
316 {{- range .Values.volumePermissions.image.pullSecrets }}
317   - name: {{ . }}
318 {{- end }}
319 {{- end -}}
320 {{- end -}}
321
322 {{/*
323 Get the readiness probe command
324 */}}
325 {{- define "postgresql.readinessProbeCommand" -}}
326 - |
327 {{- if (include "postgresql.database" .) }}
328   exec pg_isready -U {{ include "postgresql.username" . | quote }} -d {{ (include "postgresql.database" .) | quote }} -h 127.0.0.1 -p {{ template "postgresql.port" . }}
329 {{- else }}
330   exec pg_isready -U {{ include "postgresql.username" . | quote }} -h 127.0.0.1 -p {{ template "postgresql.port" . }}
331 {{- end }}
332 {{- if contains "bitnami/" .Values.image.repository }}
333   [ -f /opt/bitnami/postgresql/tmp/.initialized ] || [ -f /bitnami/postgresql/.initialized ]
334 {{- end -}}
335 {{- end -}}
336
337 {{/*
338 Return  the proper Storage Class
339 */}}
340 {{- define "postgresql.storageClass" -}}
341 {{/*
342 Helm 2.11 supports the assignment of a value to a variable defined in a different scope,
343 but Helm 2.9 and 2.10 does not support it, so we need to implement this if-else logic.
344 */}}
345 {{- if .Values.global -}}
346     {{- if .Values.global.storageClass -}}
347         {{- if (eq "-" .Values.global.storageClass) -}}
348             {{- printf "storageClassName: \"\"" -}}
349         {{- else }}
350             {{- printf "storageClassName: %s" .Values.global.storageClass -}}
351         {{- end -}}
352     {{- else -}}
353         {{- if .Values.persistence.storageClass -}}
354               {{- if (eq "-" .Values.persistence.storageClass) -}}
355                   {{- printf "storageClassName: \"\"" -}}
356               {{- else }}
357                   {{- printf "storageClassName: %s" .Values.persistence.storageClass -}}
358               {{- end -}}
359         {{- end -}}
360     {{- end -}}
361 {{- else -}}
362     {{- if .Values.persistence.storageClass -}}
363         {{- if (eq "-" .Values.persistence.storageClass) -}}
364             {{- printf "storageClassName: \"\"" -}}
365         {{- else }}
366             {{- printf "storageClassName: %s" .Values.persistence.storageClass -}}
367         {{- end -}}
368     {{- end -}}
369 {{- end -}}
370 {{- end -}}
371
372 {{/*
373 Renders a value that contains template.
374 Usage:
375 {{ include "postgresql.tplValue" ( dict "value" .Values.path.to.the.Value "context" $) }}
376 */}}
377 {{- define "postgresql.tplValue" -}}
378     {{- if typeIs "string" .value }}
379         {{- tpl .value .context }}
380     {{- else }}
381         {{- tpl (.value | toYaml) .context }}
382     {{- end }}
383 {{- end -}}
384
385 {{/*
386 Return the appropriate apiVersion for statefulset.
387 */}}
388 {{- define "postgresql.statefulset.apiVersion" -}}
389 {{- if semverCompare "<1.14-0" .Capabilities.KubeVersion.GitVersion -}}
390 {{- print "apps/v1beta2" -}}
391 {{- else -}}
392 {{- print "apps/v1" -}}
393 {{- end -}}
394 {{- end -}}
395
396 {{/*
397 Compile all warnings into a single message, and call fail.
398 */}}
399 {{- define "postgresql.validateValues" -}}
400 {{- $messages := list -}}
401 {{- $messages := append $messages (include "postgresql.validateValues.ldapConfigurationMethod" .) -}}
402 {{- $messages := without $messages "" -}}
403 {{- $message := join "\n" $messages -}}
404
405 {{- if $message -}}
406 {{- printf "\nVALUES VALIDATION:\n%s" $message | fail -}}
407 {{- end -}}
408 {{- end -}}
409
410 {{/*
411 Validate values of Postgresql - If ldap.url is used then you don't need the other settings for ldap
412 */}}
413 {{- define "postgresql.validateValues.ldapConfigurationMethod" -}}
414 {{- if and .Values.ldap.enabled (and (not (empty .Values.ldap.url)) (not (empty .Values.ldap.server))) }}
415 postgresql: ldap.url, ldap.server
416     You cannot set both `ldap.url` and `ldap.server` at the same time.
417     Please provide a unique way to configure LDAP.
418     More info at https://www.postgresql.org/docs/current/auth-ldap.html
419 {{- end -}}
420 {{- end -}}