blob: c8134059936e65ded3f6793e3ddd9de18faaf57e [file] [log] [blame]
Oleksandr Kozachenkob0093492023-09-06 21:43:47 +02001{{/*
2Copyright VMware, Inc.
3SPDX-License-Identifier: APACHE-2.0
4*/}}
5
6{{/*
7Return the proper Keycloak image name
8*/}}
9{{- define "keycloak.image" -}}
10{{ include "common.images.image" (dict "imageRoot" .Values.image "global" .Values.global) }}
11{{- end -}}
12
13{{/*
14Return the proper keycloak-config-cli image name
15*/}}
16{{- define "keycloak.keycloakConfigCli.image" -}}
17{{ include "common.images.image" (dict "imageRoot" .Values.keycloakConfigCli.image "global" .Values.global) }}
18{{- end -}}
19
20{{/*
21Return the keycloak-config-cli configuration configmap.
22*/}}
23{{- define "keycloak.keycloakConfigCli.configmapName" -}}
24{{- if .Values.keycloakConfigCli.existingConfigmap -}}
25 {{- printf "%s" (tpl .Values.keycloakConfigCli.existingConfigmap $) -}}
26{{- else -}}
27 {{- printf "%s-keycloak-config-cli-configmap" (include "common.names.fullname" .) -}}
28{{- end -}}
29{{- end -}}
30
31{{/*
32Return true if a configmap object should be created for keycloak-config-cli
33*/}}
34{{- define "keycloak.keycloakConfigCli.createConfigmap" -}}
35{{- if and .Values.keycloakConfigCli.enabled .Values.keycloakConfigCli.configuration (not .Values.keycloakConfigCli.existingConfigmap) -}}
36 {{- true -}}
37{{- end -}}
38{{- end -}}
39
40{{/*
41Return the proper Docker Image Registry Secret Names
42*/}}
43{{- define "keycloak.imagePullSecrets" -}}
44{{- include "common.images.pullSecrets" (dict "images" (list .Values.image .Values.keycloakConfigCli.image) "global" .Values.global) -}}
45{{- end -}}
46
47{{/*
48Create a default fully qualified app name.
49We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
50*/}}
51{{- define "keycloak.postgresql.fullname" -}}
52{{- include "common.names.dependency.fullname" (dict "chartName" "postgresql" "chartValues" .Values.postgresql "context" $) -}}
53{{- end -}}
54
55{{/*
56Create the name of the service account to use
57*/}}
58{{- define "keycloak.serviceAccountName" -}}
59{{- if .Values.serviceAccount.create -}}
60 {{ default (include "common.names.fullname" .) .Values.serviceAccount.name }}
61{{- else -}}
62 {{ default "default" .Values.serviceAccount.name }}
63{{- end -}}
64{{- end -}}
65
66{{/*
67Return the path Keycloak is hosted on. This looks at httpRelativePath and returns it with a trailing slash. For example:
68 / -> / (the default httpRelativePath)
69 /auth -> /auth/ (trailing slash added)
70 /custom/ -> /custom/ (unchanged)
71*/}}
72{{- define "keycloak.httpPath" -}}
73{{ ternary .Values.httpRelativePath (printf "%s%s" .Values.httpRelativePath "/") (hasSuffix "/" .Values.httpRelativePath) }}
74{{- end -}}
75
76{{/*
77Return the Keycloak configuration configmap
78*/}}
79{{- define "keycloak.configmapName" -}}
80{{- if .Values.existingConfigmap -}}
81 {{- printf "%s" (tpl .Values.existingConfigmap $) -}}
82{{- else -}}
83 {{- printf "%s-configuration" (include "common.names.fullname" .) -}}
84{{- end -}}
85{{- end -}}
86
87{{/*
88Return true if a configmap object should be created
89*/}}
90{{- define "keycloak.createConfigmap" -}}
91{{- if and .Values.configuration (not .Values.existingConfigmap) }}
92 {{- true -}}
93{{- end -}}
94{{- end -}}
95
96{{/*
97Return the Database hostname
98*/}}
99{{- define "keycloak.databaseHost" -}}
100{{- if eq .Values.postgresql.architecture "replication" }}
101{{- ternary (include "keycloak.postgresql.fullname" .) (tpl .Values.externalDatabase.host $) .Values.postgresql.enabled -}}-primary
102{{- else -}}
103{{- ternary (include "keycloak.postgresql.fullname" .) (tpl .Values.externalDatabase.host $) .Values.postgresql.enabled -}}
104{{- end -}}
105{{- end -}}
106
107{{/*
108Return the Database port
109*/}}
110{{- define "keycloak.databasePort" -}}
111{{- ternary "5432" .Values.externalDatabase.port .Values.postgresql.enabled | quote -}}
112{{- end -}}
113
114{{/*
115Return the Database database name
116*/}}
117{{- define "keycloak.databaseName" -}}
118{{- if .Values.postgresql.enabled }}
119 {{- if .Values.global.postgresql }}
120 {{- if .Values.global.postgresql.auth }}
121 {{- coalesce .Values.global.postgresql.auth.database .Values.postgresql.auth.database -}}
122 {{- else -}}
123 {{- .Values.postgresql.auth.database -}}
124 {{- end -}}
125 {{- else -}}
126 {{- .Values.postgresql.auth.database -}}
127 {{- end -}}
128{{- else -}}
129 {{- .Values.externalDatabase.database -}}
130{{- end -}}
131{{- end -}}
132
133{{/*
134Return the Database user
135*/}}
136{{- define "keycloak.databaseUser" -}}
137{{- if .Values.postgresql.enabled -}}
138 {{- if .Values.global.postgresql -}}
139 {{- if .Values.global.postgresql.auth -}}
140 {{- coalesce .Values.global.postgresql.auth.username .Values.postgresql.auth.username -}}
141 {{- else -}}
142 {{- .Values.postgresql.auth.username -}}
143 {{- end -}}
144 {{- else -}}
145 {{- .Values.postgresql.auth.username -}}
146 {{- end -}}
147{{- else -}}
148 {{- .Values.externalDatabase.user -}}
149{{- end -}}
150{{- end -}}
151
152{{/*
153Return the Database encrypted password
154*/}}
155{{- define "keycloak.databaseSecretName" -}}
156{{- if .Values.postgresql.enabled -}}
157 {{- if .Values.global.postgresql -}}
158 {{- if .Values.global.postgresql.auth -}}
159 {{- if .Values.global.postgresql.auth.existingSecret -}}
160 {{- tpl .Values.global.postgresql.auth.existingSecret $ -}}
161 {{- else -}}
162 {{- default (include "keycloak.postgresql.fullname" .) (tpl .Values.postgresql.auth.existingSecret $) -}}
163 {{- end -}}
164 {{- else -}}
165 {{- default (include "keycloak.postgresql.fullname" .) (tpl .Values.postgresql.auth.existingSecret $) -}}
166 {{- end -}}
167 {{- else -}}
168 {{- default (include "keycloak.postgresql.fullname" .) (tpl .Values.postgresql.auth.existingSecret $) -}}
169 {{- end -}}
170{{- else -}}
171 {{- default (printf "%s-externaldb" .Release.Name) (tpl .Values.externalDatabase.existingSecret $) -}}
172{{- end -}}
173{{- end -}}
174
175{{/*
176Add environment variables to configure database values
177*/}}
178{{- define "keycloak.databaseSecretPasswordKey" -}}
179{{- if .Values.postgresql.enabled -}}
180 {{- print "password" -}}
181{{- else -}}
182 {{- if .Values.externalDatabase.existingSecret -}}
183 {{- if .Values.externalDatabase.existingSecretPasswordKey -}}
184 {{- printf "%s" .Values.externalDatabase.existingSecretPasswordKey -}}
185 {{- else -}}
186 {{- print "db-password" -}}
187 {{- end -}}
188 {{- else -}}
189 {{- print "db-password" -}}
190 {{- end -}}
191{{- end -}}
192{{- end -}}
193
194{{- define "keycloak.databaseSecretHostKey" -}}
195 {{- if .Values.externalDatabase.existingSecretHostKey -}}
196 {{- printf "%s" .Values.externalDatabase.existingSecretHostKey -}}
197 {{- else -}}
198 {{- print "db-host" -}}
199 {{- end -}}
200{{- end -}}
201{{- define "keycloak.databaseSecretPortKey" -}}
202 {{- if .Values.externalDatabase.existingSecretPortKey -}}
203 {{- printf "%s" .Values.externalDatabase.existingSecretPortKey -}}
204 {{- else -}}
205 {{- print "db-port" -}}
206 {{- end -}}
207{{- end -}}
208{{- define "keycloak.databaseSecretUserKey" -}}
209 {{- if .Values.externalDatabase.existingSecretUserKey -}}
210 {{- printf "%s" .Values.externalDatabase.existingSecretUserKey -}}
211 {{- else -}}
212 {{- print "db-port" -}}
213 {{- end -}}
214{{- end -}}
215{{- define "keycloak.databaseSecretDatabaseKey" -}}
216 {{- if .Values.externalDatabase.existingSecretDatabaseKey -}}
217 {{- printf "%s" .Values.externalDatabase.existingSecretDatabaseKey -}}
218 {{- else -}}
219 {{- print "db-port" -}}
220 {{- end -}}
221{{- end -}}
222
223{{/*
224Return the Keycloak initdb scripts configmap
225*/}}
226{{- define "keycloak.initdbScriptsCM" -}}
227{{- if .Values.initdbScriptsConfigMap -}}
228 {{- printf "%s" .Values.initdbScriptsConfigMap -}}
229{{- else -}}
230 {{- printf "%s-init-scripts" (include "common.names.fullname" .) -}}
231{{- end -}}
232{{- end -}}
233
234{{/*
235Return the secret containing the Keycloak admin password
236*/}}
237{{- define "keycloak.secretName" -}}
238{{- $secretName := .Values.auth.existingSecret -}}
239{{- if $secretName -}}
240 {{- printf "%s" (tpl $secretName $) -}}
241{{- else -}}
242 {{- printf "%s" (include "common.names.fullname" .) | trunc 63 | trimSuffix "-" -}}
243{{- end -}}
244{{- end -}}
245
246{{/*
247Return the secret key that contains the Keycloak admin password
248*/}}
249{{- define "keycloak.secretKey" -}}
250{{- $secretName := .Values.auth.existingSecret -}}
251{{- if and $secretName .Values.auth.passwordSecretKey -}}
252 {{- printf "%s" .Values.auth.passwordSecretKey -}}
253{{- else -}}
254 {{- print "admin-password" -}}
255{{- end -}}
256{{- end -}}
257
258{{/*
259Return the secret containing Keycloak HTTPS/TLS certificates
260*/}}
261{{- define "keycloak.tlsSecretName" -}}
262{{- $secretName := .Values.tls.existingSecret -}}
263{{- if $secretName -}}
264 {{- printf "%s" (tpl $secretName $) -}}
265{{- else -}}
266 {{- printf "%s-crt" (include "common.names.fullname" .) -}}
267{{- end -}}
268{{- end -}}
269
270{{/*
271Return the secret containing Keycloak HTTPS/TLS keystore and truststore passwords
272*/}}
273{{- define "keycloak.tlsPasswordsSecretName" -}}
274{{- $secretName := .Values.tls.passwordsSecret -}}
275{{- if $secretName -}}
276 {{- printf "%s" (tpl $secretName $) -}}
277{{- else -}}
278 {{- printf "%s-tls-passwords" (include "common.names.fullname" .) | trunc 63 | trimSuffix "-" -}}
279{{- end -}}
280{{- end -}}
281
282{{/*
283Return the secret containing Keycloak SPI TLS certificates
284*/}}
285{{- define "keycloak.spiPasswordsSecretName" -}}
286{{- $secretName := .Values.spi.passwordsSecret -}}
287{{- if $secretName -}}
288 {{- printf "%s" (tpl $secretName $) -}}
289{{- else -}}
290 {{- printf "%s-spi-passwords" (include "common.names.fullname" .) | trunc 63 | trimSuffix "-" -}}
291{{- end -}}
292{{- end -}}
293
294{{/*
295Return true if a TLS secret object should be created
296*/}}
297{{- define "keycloak.createTlsSecret" -}}
298{{- if and .Values.tls.enabled .Values.tls.autoGenerated (not .Values.tls.existingSecret) }}
299 {{- true -}}
300{{- end -}}
301{{- end -}}
302
303{{/*
304Compile all warnings into a single message.
305*/}}
306{{- define "keycloak.validateValues" -}}
307{{- $messages := list -}}
308{{- $messages := append $messages (include "keycloak.validateValues.database" .) -}}
309{{- $messages := append $messages (include "keycloak.validateValues.tls" .) -}}
310{{- $messages := append $messages (include "keycloak.validateValues.production" .) -}}
311{{- $messages := without $messages "" -}}
312{{- $message := join "\n" $messages -}}
313
314{{- if $message -}}
315{{- printf "\nVALUES VALIDATION:\n%s" $message | fail -}}
316{{- end -}}
317{{- end -}}
318
319{{/* Validate values of Keycloak - database */}}
320{{- define "keycloak.validateValues.database" -}}
321{{- if and (not .Values.postgresql.enabled) (not .Values.externalDatabase.host) (and (not .Values.externalDatabase.password) (not .Values.externalDatabase.existingSecret)) -}}
322keycloak: database
323 You disabled the PostgreSQL sub-chart but did not specify an external PostgreSQL host.
324 Either deploy the PostgreSQL sub-chart (--set postgresql.enabled=true),
325 or set a value for the external database host (--set externalDatabase.host=FOO)
326 and set a value for the external database password (--set externalDatabase.password=BAR)
327 or existing secret (--set externalDatabase.existingSecret=BAR).
328{{- end -}}
329{{- end -}}
330
331{{/* Validate values of Keycloak - TLS enabled */}}
332{{- define "keycloak.validateValues.tls" -}}
333{{- if and .Values.tls.enabled (not .Values.tls.autoGenerated) (not .Values.tls.existingSecret) }}
334keycloak: tls.enabled
335 In order to enable TLS, you also need to provide
336 an existing secret containing the Keystore and Truststore or
337 enable auto-generated certificates.
338{{- end -}}
339{{- end -}}
340
341{{/* Validate values of Keycloak - Production mode enabled */}}
342{{- define "keycloak.validateValues.production" -}}
343{{- if and .Values.production (not .Values.tls.enabled) (not (eq .Values.proxy "edge")) -}}
344keycloak: production
345 In order to enable Production mode, you also need to enable HTTPS/TLS
346 using the value 'tls.enabled' and providing an existing secret containing the Keystore and Trustore.
347{{- end -}}
348{{- end -}}