1 {{/* vim: set filetype=mustache: */}}
3 Expand the name of the chart.
5 {{- define "postgresql.name" -}}
6 {{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
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).
13 {{- define "postgresql.fullname" -}}
14 {{- if .Values.fullnameOverride -}}
15 {{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}}
17 {{- $name := default .Chart.Name .Values.nameOverride -}}
18 {{- if contains $name .Release.Name -}}
19 {{- .Release.Name | trunc 63 | trimSuffix "-" -}}
21 {{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
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).
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 "-" -}}
35 {{- printf "%s" $fullname | trunc 63 | trimSuffix "-" -}}
40 Return the appropriate apiVersion for networkpolicy.
42 {{- define "postgresql.networkPolicy.apiVersion" -}}
43 {{- if semverCompare ">=1.4-0, <1.7-0" .Capabilities.KubeVersion.GitVersion -}}
45 {{- else if semverCompare "^1.7-0" .Capabilities.KubeVersion.GitVersion -}}
46 "networking.k8s.io/v1"
51 Create chart name and version as used by the chart label.
53 {{- define "postgresql.chart" -}}
54 {{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
58 Return the proper PostgreSQL image name
60 {{- define "postgresql.image" -}}
61 {{- $registryName := .Values.image.registry -}}
62 {{- $repositoryName := .Values.image.repository -}}
63 {{- $tag := .Values.image.tag | toString -}}
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
69 {{- if .Values.global }}
70 {{- if .Values.global.imageRegistry }}
71 {{- printf "%s/%s:%s" .Values.global.imageRegistry $repositoryName $tag -}}
73 {{- printf "%s/%s:%s" $registryName $repositoryName $tag -}}
76 {{- printf "%s/%s:%s" $registryName $repositoryName $tag -}}
81 Return PostgreSQL postgres user password
83 {{- define "postgresql.postgres.password" -}}
84 {{- if .Values.global.postgresql.postgresqlPostgresPassword }}
85 {{- .Values.global.postgresql.postgresqlPostgresPassword -}}
86 {{- else if .Values.postgresqlPostgresPassword -}}
87 {{- .Values.postgresqlPostgresPassword -}}
89 {{- randAlphaNum 10 -}}
94 Return PostgreSQL password
96 {{- define "postgresql.password" -}}
97 {{- if .Values.global.postgresql.postgresqlPassword }}
98 {{- .Values.global.postgresql.postgresqlPassword -}}
99 {{- else if .Values.postgresqlPassword -}}
100 {{- .Values.postgresqlPassword -}}
102 {{- randAlphaNum 10 -}}
107 Return PostgreSQL replication password
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 -}}
115 {{- randAlphaNum 10 -}}
120 Return PostgreSQL username
122 {{- define "postgresql.username" -}}
123 {{- if .Values.global.postgresql.postgresqlUsername }}
124 {{- .Values.global.postgresql.postgresqlUsername -}}
126 {{- .Values.postgresqlUsername -}}
132 Return PostgreSQL replication username
134 {{- define "postgresql.replication.username" -}}
135 {{- if .Values.global.postgresql.replicationUser }}
136 {{- .Values.global.postgresql.replicationUser -}}
138 {{- .Values.replication.user -}}
143 Return PostgreSQL port
145 {{- define "postgresql.port" -}}
146 {{- if .Values.global.postgresql.servicePort }}
147 {{- .Values.global.postgresql.servicePort -}}
149 {{- .Values.service.port -}}
154 Return PostgreSQL created database
156 {{- define "postgresql.database" -}}
157 {{- if .Values.global.postgresql.postgresqlDatabase }}
158 {{- .Values.global.postgresql.postgresqlDatabase -}}
159 {{- else if .Values.postgresqlDatabase -}}
160 {{- .Values.postgresqlDatabase -}}
165 Return the proper image name to change the volume permissions
167 {{- define "postgresql.volumePermissions.image" -}}
168 {{- $registryName := .Values.volumePermissions.image.registry -}}
169 {{- $repositoryName := .Values.volumePermissions.image.repository -}}
170 {{- $tag := .Values.volumePermissions.image.tag | toString -}}
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
176 {{- if .Values.global }}
177 {{- if .Values.global.imageRegistry }}
178 {{- printf "%s/%s:%s" .Values.global.imageRegistry $repositoryName $tag -}}
180 {{- printf "%s/%s:%s" $registryName $repositoryName $tag -}}
183 {{- printf "%s/%s:%s" $registryName $repositoryName $tag -}}
188 Return the proper PostgreSQL metrics image name
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 -}}
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
199 {{- if .Values.global }}
200 {{- if .Values.global.imageRegistry }}
201 {{- printf "%s/%s:%s" .Values.global.imageRegistry $repositoryName $tag -}}
203 {{- printf "%s/%s:%s" $registryName $repositoryName $tag -}}
206 {{- printf "%s/%s:%s" $registryName $repositoryName $tag -}}
211 Get the password secret.
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 -}}
219 {{- printf "%s" (include "postgresql.fullname" .) -}}
224 Return true if a secret object should be created
226 {{- define "postgresql.createSecret" -}}
227 {{- if .Values.global.postgresql.existingSecret }}
228 {{- else if .Values.existingSecret -}}
235 Get the configuration ConfigMap name.
237 {{- define "postgresql.configurationCM" -}}
238 {{- if .Values.configurationConfigMap -}}
239 {{- printf "%s" (tpl .Values.configurationConfigMap $) -}}
241 {{- printf "%s-configuration" (include "postgresql.fullname" .) -}}
246 Get the extended configuration ConfigMap name.
248 {{- define "postgresql.extendedConfigurationCM" -}}
249 {{- if .Values.extendedConfConfigMap -}}
250 {{- printf "%s" (tpl .Values.extendedConfConfigMap $) -}}
252 {{- printf "%s-extended-configuration" (include "postgresql.fullname" .) -}}
257 Get the initialization scripts ConfigMap name.
259 {{- define "postgresql.initdbScriptsCM" -}}
260 {{- if .Values.initdbScriptsConfigMap -}}
261 {{- printf "%s" (tpl .Values.initdbScriptsConfigMap $) -}}
263 {{- printf "%s-init-scripts" (include "postgresql.fullname" .) -}}
268 Get the initialization scripts Secret name.
270 {{- define "postgresql.initdbScriptsSecret" -}}
271 {{- printf "%s" (tpl .Values.initdbScriptsSecret $) -}}
275 Get the metrics ConfigMap name.
277 {{- define "postgresql.metricsCM" -}}
278 {{- printf "%s-metrics" (include "postgresql.fullname" .) -}}
282 Return the proper Docker Image Registry Secret Names
284 {{- define "postgresql.imagePullSecrets" -}}
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
290 {{- if .Values.global }}
291 {{- if .Values.global.imagePullSecrets }}
293 {{- range .Values.global.imagePullSecrets }}
296 {{- else if or .Values.image.pullSecrets .Values.metrics.image.pullSecrets .Values.volumePermissions.image.pullSecrets }}
298 {{- range .Values.image.pullSecrets }}
301 {{- range .Values.metrics.image.pullSecrets }}
304 {{- range .Values.volumePermissions.image.pullSecrets }}
308 {{- else if or .Values.image.pullSecrets .Values.metrics.image.pullSecrets .Values.volumePermissions.image.pullSecrets }}
310 {{- range .Values.image.pullSecrets }}
313 {{- range .Values.metrics.image.pullSecrets }}
316 {{- range .Values.volumePermissions.image.pullSecrets }}
323 Get the readiness probe command
325 {{- define "postgresql.readinessProbeCommand" -}}
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" . }}
330 exec pg_isready -U {{ include "postgresql.username" . | quote }} -h 127.0.0.1 -p {{ template "postgresql.port" . }}
332 {{- if contains "bitnami/" .Values.image.repository }}
333 [ -f /opt/bitnami/postgresql/tmp/.initialized ] || [ -f /bitnami/postgresql/.initialized ]
338 Return the proper Storage Class
340 {{- define "postgresql.storageClass" -}}
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.
345 {{- if .Values.global -}}
346 {{- if .Values.global.storageClass -}}
347 {{- if (eq "-" .Values.global.storageClass) -}}
348 {{- printf "storageClassName: \"\"" -}}
350 {{- printf "storageClassName: %s" .Values.global.storageClass -}}
353 {{- if .Values.persistence.storageClass -}}
354 {{- if (eq "-" .Values.persistence.storageClass) -}}
355 {{- printf "storageClassName: \"\"" -}}
357 {{- printf "storageClassName: %s" .Values.persistence.storageClass -}}
362 {{- if .Values.persistence.storageClass -}}
363 {{- if (eq "-" .Values.persistence.storageClass) -}}
364 {{- printf "storageClassName: \"\"" -}}
366 {{- printf "storageClassName: %s" .Values.persistence.storageClass -}}
373 Renders a value that contains template.
375 {{ include "postgresql.tplValue" ( dict "value" .Values.path.to.the.Value "context" $) }}
377 {{- define "postgresql.tplValue" -}}
378 {{- if typeIs "string" .value }}
379 {{- tpl .value .context }}
381 {{- tpl (.value | toYaml) .context }}
386 Return the appropriate apiVersion for statefulset.
388 {{- define "postgresql.statefulset.apiVersion" -}}
389 {{- if semverCompare "<1.14-0" .Capabilities.KubeVersion.GitVersion -}}
390 {{- print "apps/v1beta2" -}}
392 {{- print "apps/v1" -}}
397 Compile all warnings into a single message, and call fail.
399 {{- define "postgresql.validateValues" -}}
400 {{- $messages := list -}}
401 {{- $messages := append $messages (include "postgresql.validateValues.ldapConfigurationMethod" .) -}}
402 {{- $messages := without $messages "" -}}
403 {{- $message := join "\n" $messages -}}
406 {{- printf "\nVALUES VALIDATION:\n%s" $message | fail -}}
411 Validate values of Postgresql - If ldap.url is used then you don't need the other settings for ldap
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