@@ -199,79 +199,110 @@ app.kubernetes.io/managed-by: {{ .Release.Service }}
199
199
{{- end }}
200
200
{{- end -}}
201
201
202
- ######################### PostgreSQL username #########################
202
+ ######################### PostgreSQL connection configuration #########################
203
203
{{/*
204
204
This template renders the username used for the PostgreSQL instance.
205
205
*/}}
206
206
{{- define "invenio.postgresql.username" -}}
207
207
{{- if .Values.postgresql.enabled -}}
208
- {{- required "Missing .Values.postgresql.auth.username" .Values.postgresql.auth.username -}}
209
- {{/* NOTE: Specifying username explicitly like this is suboptmal. Would be desirable to refactor Invenio so it can take the postgres username as a spearate environment variable which we can populate dynamically from the secret. */}}
208
+ {{- required "Missing .Values.postgresql.auth.username" (tpl .Values.postgresql.auth.username .) -}}
210
209
{{- else -}}
211
- {{- required "Missing .Values.postgresqlExternal.username" .Values.postgresqlExternal.username -}}
210
+ {{- required "Missing .Values.postgresqlExternal.username" (tpl .Values.postgresqlExternal.username .) -}}
212
211
{{- end -}}
213
212
{{- end -}}
214
213
215
- ######################### PostgreSQL password #########################
216
214
{{/*
217
215
This template renders the password used for the PostgreSQL instance.
216
+ In production environments we encourage you to use secrets instead.
218
217
*/}}
219
218
{{- define "invenio.postgresql.password" -}}
220
219
{{- if .Values.postgresql.enabled -}}
221
220
{{- required "Missing .Values.postgresql.auth.password" .Values.postgresql.auth.password -}}
222
- {{/* NOTE: Specifying password explicitly like this is suboptmal. Would be desirable to refactor Invenio so it can take the postgres password as a spearate environment variable which we can populate dynamically from the secret. */}}
223
221
{{- else -}}
224
222
{{- required "Missing .Values.postgresqlExternal.password" .Values.postgresqlExternal.password -}}
225
223
{{- end -}}
226
224
{{- end -}}
227
225
228
- ######################### PostgreSQL hostname #########################
226
+ {{/*
227
+ Get the database password secret name
228
+ */}}
229
+ {{- define "invenio.postgresql.secretName" -}}
230
+ {{- if .Values.postgresql.enabled -}}
231
+ {{- required "Missing .Values.postgresql.auth.existingSecret" (tpl .Values.postgresql.auth.existingSecret .) -}}
232
+ {{- else -}}
233
+ {{- required "Missing .Values.postgresqlExternal.existingSecret" (tpl .Values.postgresqlExternal.existingSecret .) -}}
234
+ {{- end -}}
235
+ {{- end -}}
236
+
237
+ {{/*
238
+ Get the database password secret key
239
+ */}}
240
+ {{- define "invenio.postgresql.secretKey" -}}
241
+ {{- if .Values.postgresql.enabled -}}
242
+ {{- required "Missing .Values.postgresql.auth.secretKeys.userPasswordKey" .Values.postgresql.auth.secretKeys.userPasswordKey -}}
243
+ {{- else -}}
244
+ {{- required "Missing .Values.postgresqlExternal.existingSecretPasswordKey" .Values.postgresqlExternal.existingSecretPasswordKey -}}
245
+ {{- end -}}
246
+ {{- end -}}
247
+
229
248
{{/*
230
249
This template renders the hostname used for the PostgreSQL instance.
231
250
*/}}
232
251
{{- define "invenio.postgresql.hostname" -}}
233
252
{{- if .Values.postgresql.enabled -}}
234
253
{{- include "postgresql.v1.primary.fullname" .Subcharts.postgresql -}}
235
254
{{- else -}}
236
- {{- required "Missing .Values.postgresqlExternal.hostname" .Values.postgresqlExternal.hostname -}}
255
+ {{- required "Missing .Values.postgresqlExternal.hostname" (tpl .Values.postgresqlExternal.hostname .) -}}
237
256
{{- end -}}
238
257
{{- end -}}
239
258
240
- ########################### PostgreSQL port ###########################
241
259
{{/*
242
260
This template renders the port number used for the PostgreSQL instance.
243
261
*/}}
244
262
{{- define "invenio.postgresql.port" -}}
245
263
{{- if .Values.postgresql.enabled -}}
246
- {{- required "Missing .Values.postgresql.primary.service.ports.postgresql" .Values.postgresql.primary.service.ports.postgresql -}}
264
+ {{- required "Missing .Values.postgresql.primary.service.ports.postgresql" (tpl .Values.postgresql.primary.service.ports.postgresql .) -}}
247
265
{{- else -}}
248
- {{- required "Missing .Values.postgresqlExternal.port" .Values.postgresqlExternal.port -}}
266
+ {{- required "Missing .Values.postgresqlExternal.port" (tpl .Values.postgresqlExternal.port .) -}}
249
267
{{- end -}}
250
268
{{- end -}}
251
269
252
- ############################ Database name ############################
253
270
{{/*
254
271
This template renders the name of the database in PostgreSQL.
255
272
*/}}
256
- {{- define "invenio.postgresql.databaseName " -}}
273
+ {{- define "invenio.postgresql.database " -}}
257
274
{{- if .Values.postgresql.enabled -}}
258
- {{- required "Missing .Values.postgresql.auth.database" .Values.postgresql.auth.database -}}
275
+ {{- required "Missing .Values.postgresql.auth.database" (tpl .Values.postgresql.auth.database .) -}}
259
276
{{- else -}}
260
- {{- required "Missing .Values.postgresqlExternal.databaseName" .Values.postgresqlExternal.databaseName -}}
277
+ {{- required "Missing .Values.postgresqlExternal.database" (tpl .Values.postgresqlExternal.database .) -}}
261
278
{{- end -}}
262
279
{{- end -}}
263
280
264
- ####################### SQLAlchemy database URI #######################
265
281
{{/*
266
- This template renders the SQLAlchemy database URI.
282
+ Define database connection env section.
267
283
*/}}
268
- {{- define "invenio.sqlAlchemyDbUri" -}}
269
- {{- $username := include "invenio.postgresql.username" . -}}
270
- {{- $password := include "invenio.postgresql.password" . -}}
271
- {{- $hostname := include "invenio.postgresql.hostname" . -}}
272
- {{- $port := include "invenio.postgresql.port" . -}}
273
- {{- $databaseName := include "invenio.postgresql.databaseName" . -}}
274
- {{- printf "postgresql+psycopg2://%s:%s@%s:%v/%s" $username $password $hostname $port $databaseName -}}
284
+ {{- define "invenio.config.database" -}}
285
+ - name: INVENIO_DB_USER
286
+ value: {{ include "invenio.postgresql.username" . }}
287
+ - name: INVENIO_DB_HOST
288
+ value: {{ include "invenio.postgresql.hostname" . }}
289
+ - name: INVENIO_DB_PORT
290
+ value: {{ include "invenio.postgresql.port" . }}
291
+ - name: INVENIO_DB_NAME
292
+ value: {{ include "invenio.postgresql.database" . }}
293
+ - name: INVENIO_DB_PROTOCOL
294
+ value: "postgresql+psycopg2"
295
+ - name: INVENIO_DB_PASSWORD
296
+ {{- if or (and .Values.postgresql.enabled .Values.postgresql.auth.password) .Values.postgresqlExternal.password }}
297
+ value: {{ include "invenio.postgresql.password" . | quote }}
298
+ {{- else }}
299
+ valueFrom:
300
+ secretKeyRef:
301
+ name: {{ include "invenio.postgresql.secretName" .}}
302
+ key: {{ include "invenio.postgresql.secretKey" .}}
303
+ {{- end }}
304
+ - name: INVENIO_SQLALCHEMY_DATABASE_URI
305
+ value: "$(INVENIO_DB_PROTOCOL)://$(INVENIO_DB_USER):$(INVENIO_DB_PASSWORD)@$(INVENIO_DB_HOST):$(INVENIO_DB_PORT)/$(INVENIO_DB_NAME)"
275
306
{{- end -}}
276
307
277
308
{{/*
0 commit comments