Skip to content

Commit cf9e856

Browse files
committed
config: enhance RabbitMQ connection configuration
1 parent 503729f commit cf9e856

File tree

6 files changed

+86
-57
lines changed

6 files changed

+86
-57
lines changed

charts/invenio/templates/_helpers.tpl

+58-40
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ app.kubernetes.io/managed-by: {{ .Release.Service }}
8383
{{- end }}
8484
{{- end -}}
8585

86-
####################### RabbitMQ password secret #######################
86+
####################### RabbitMQ connection configuration #######################
8787
{{/*
8888
This template renders the name of the secret that stores the password for RabbitMQ.
8989
*/}}
@@ -95,19 +95,17 @@ app.kubernetes.io/managed-by: {{ .Release.Service }}
9595
{{- end }}
9696
{{- end -}}
9797

98-
########################## RabbitMQ username ##########################
9998
{{/*
10099
This template renders the username for accessing RabbitMQ.
101100
*/}}
102101
{{- define "invenio.rabbitmq.username" -}}
103102
{{- if .Values.rabbitmq.enabled }}
104103
{{- required "Missing .Values.rabbitmq.auth.username" .Values.rabbitmq.auth.username -}}
105104
{{- else }}
106-
{{- required "Missing .Values.rabbitmqExternal.username" .Values.rabbitmqExternal.username -}}
105+
{{- required "Missing .Values.rabbitmqExternal.username" (tpl .Values.rabbitmqExternal.username .) -}}
107106
{{- end }}
108107
{{- end -}}
109108

110-
########################## RabbitMQ password ##########################
111109
{{/*
112110
This template renders the password for accessing RabbitMQ.
113111
*/}}
@@ -119,43 +117,61 @@ app.kubernetes.io/managed-by: {{ .Release.Service }}
119117
{{- end }}
120118
{{- end -}}
121119

122-
########################## RabbitMQ AMQP port ##########################
120+
{{/*
121+
Get the database password secret name
122+
*/}}
123+
{{- define "invenio.rabbitmq.secretName" -}}
124+
{{- if .Values.rabbitmq.enabled -}}
125+
{{- required "Missing .Values.rabbitmq.auth.existingPasswordSecret" (tpl .Values.rabbitmq.auth.existingPasswordSecret .) -}}
126+
{{- else -}}
127+
{{- required "Missing .Values.rabbitmqExternal.existingSecret" (tpl .Values.rabbitmqExternal.existingSecret .) -}}
128+
{{- end -}}
129+
{{- end -}}
130+
131+
{{/*
132+
Get the database password secret key
133+
*/}}
134+
{{- define "invenio.rabbitmq.secretKey" -}}
135+
{{- if .Values.rabbitmq.enabled -}}
136+
{{- required "Missing .Values.rabbitmq.auth.existingSecretPasswordKey" .Values.rabbitmq.auth.existingSecretPasswordKey -}}
137+
{{- else -}}
138+
{{- required "Missing .Values.rabbitmqExternal.existingSecretPasswordKey" .Values.rabbitmqExternal.existingSecretPasswordKey -}}
139+
{{- end -}}
140+
{{- end -}}
141+
123142
{{/*
124143
This template renders the AMQP port number for RabbitMQ.
125144
*/}}
126145
{{- define "invenio.rabbitmq.amqpPort" -}}
127146
{{- if .Values.rabbitmq.enabled }}
128-
{{- required "Missing .Values.rabbitmq.service.ports.amqp" .Values.rabbitmq.service.ports.amqp -}}
147+
{{- required "Missing .Values.rabbitmq.service.ports.amqp" .Values.rabbitmq.service.ports.amqp | quote -}}
129148
{{- else }}
130-
{{- required "Missing .Values.rabbitmqExternal.amqpPort" .Values.rabbitmqExternal.amqpPort -}}
149+
{{- required "Missing .Values.rabbitmqExternal.amqpPort" (tpl .Values.rabbitmqExternal.amqpPort .) | quote -}}
131150
{{- end }}
132151
{{- end -}}
133152

134-
####################### RabbitMQ management port #######################
135153
{{/*
136154
This template renders the management port number for RabbitMQ.
137155
*/}}
138156
{{- define "invenio.rabbitmq.managementPort" -}}
139157
{{- if .Values.rabbitmq.enabled }}
140-
{{- required "Missing .Values.rabbitmq.service.ports.manager" .Values.rabbitmq.service.ports.manager -}}
158+
{{- required "Missing .Values.rabbitmq.service.ports.manager" .Values.rabbitmq.service.ports.manager | quote -}}
141159
{{- else }}
142-
{{- required "Missing .Values.rabbitmqExternal.managementPort" .Values.rabbitmqExternal.managementPort -}}
160+
{{- required "Missing .Values.rabbitmqExternal.managementPort" (tpl .Values.rabbitmqExternal.managementPort .) | quote -}}
143161
{{- end }}
144162
{{- end -}}
145163

146-
########################## RabbitMQ hostname ##########################
147164
{{/*
148165
This template renders the hostname for RabbitMQ.
149166
*/}}
150167
{{- define "invenio.rabbitmq.hostname" -}}
151168
{{- if .Values.rabbitmq.enabled }}
152169
{{- include "common.names.fullname" .Subcharts.rabbitmq -}}
153170
{{- else }}
154-
{{- required "Missing .Values.rabbitmqExternal.hostname" .Values.rabbitmqExternal.hostname }}
171+
{{- required "Missing .Values.rabbitmqExternal.hostname" (tpl .Values.rabbitmqExternal.hostname .) }}
155172
{{- end }}
156173
{{- end -}}
157174

158-
########################## RabbitMQ protocol ##########################
159175
{{/*
160176
This template renders the protocol for RabbitMQ.
161177
*/}}
@@ -167,44 +183,46 @@ app.kubernetes.io/managed-by: {{ .Release.Service }}
167183
{{- end }}
168184
{{- end -}}
169185

170-
########################## RabbitMQ vhost ##########################
171186
{{/*
172187
This template renders the vhost for RabbitMQ.
173188
*/}}
174189
{{- define "invenio.rabbitmq.vhost" -}}
175190
{{- if .Values.rabbitmq.enabled }}
176191
{{- "" }}
177192
{{- else }}
178-
{{- required "Missing .Values.rabbitmqExternal.vhost" .Values.rabbitmqExternal.vhost }}
193+
{{- required "Missing .Values.rabbitmqExternal.vhost" (tpl .Values.rabbitmqExternal.vhost .) }}
179194
{{- end }}
180195
{{- end -}}
181196

182-
########################## Celery broker URI ##########################
183-
{{/*
184-
This template renders the URI for connecting to RabbitMQ.
185-
*/}}
186-
{{- define "invenio.rabbitmq.uri" -}}
187-
{{- $username := (include "invenio.rabbitmq.username" .) -}}
188-
{{- $password := (include "invenio.rabbitmq.password" .) -}}
189-
{{- $port := (include "invenio.rabbitmq.amqpPort" .) -}}
190-
{{- $hostname := (include "invenio.rabbitmq.hostname" .) -}}
191-
{{- $protocol := (include "invenio.rabbitmq.protocol" .) -}}
192-
{{- $vhost := (include "invenio.rabbitmq.vhost" .) -}}
193-
{{- printf "%s://%s:%s@%s:%v/%s" $protocol $username $password $hostname $port $vhost}}
194-
{{- end -}}
195-
196-
########################### RabbitMQ API URI ###########################
197197
{{/*
198-
This template renders the URI for RabbitMQ's API endpoint.
199-
*/}}
200-
{{- define "invenio.rabbitmq.apiUri" -}}
201-
{{- $username := (include "invenio.rabbitmq.username" .) -}}
202-
{{- $password := (include "invenio.rabbitmq.password" .) -}}
203-
{{- $port := (include "invenio.rabbitmq.managementPort" .) -}}
204-
{{- $hostname := (include "invenio.rabbitmq.hostname" .) -}}
205-
{{- printf "http://%s:%s@%s:%v/api/" $username $password $hostname $port }}
198+
RabbitMQ connection env section.
199+
*/}}
200+
{{- define "invenio.config.queue" -}}
201+
{{- $uri := "$(INVENIO_AMQP_BROKER_PROTOCOL)://$(INVENIO_AMQP_BROKER_USER):$(INVENIO_AMQP_BROKER_PASSWORD)@$(INVENIO_AMQP_BROKER_HOST):$(INVENIO_AMQP_BROKER_PORT)/$(INVENIO_AMQP_BROKER_VHOST)" -}}
202+
- name: INVENIO_AMQP_BROKER_USER
203+
value: {{ include "invenio.rabbitmq.username" . }}
204+
- name: INVENIO_AMQP_BROKER_HOST
205+
value: {{ include "invenio.rabbitmq.hostname" . }}
206+
- name: INVENIO_AMQP_BROKER_PORT
207+
value: {{ include "invenio.rabbitmq.amqpPort" . }}
208+
- name: INVENIO_AMQP_BROKER_VHOST
209+
value: {{ include "invenio.rabbitmq.vhost" . }}
210+
- name: INVENIO_AMQP_BROKER_PROTOCOL
211+
value: {{ include "invenio.rabbitmq.protocol" . }}
212+
- name: INVENIO_AMQP_BROKER_PASSWORD
213+
{{- if or (and .Values.rabbitmq.enabled .Values.rabbitmq.auth.password) .Values.rabbitmqExternal.password }}
214+
value: {{ include "invenio.rabbitmq.password" . | quote }}
215+
{{- else }}
216+
valueFrom:
217+
secretKeyRef:
218+
name: {{ include "invenio.rabbitmq.secretName" .}}
219+
key: {{ include "invenio.rabbitmq.secretKey" .}}
220+
{{- end }}
221+
- name: INVENIO_BROKER_URL
222+
value: {{ $uri}}
223+
- name: INVENIO_CELERY_BROKER_URL
224+
value: {{ $uri}}
206225
{{- end -}}
207-
208226
######################### OpenSearch hostname #########################
209227
{{/*
210228
This template renders the hostname of the OpenSearch instance.
@@ -297,7 +315,7 @@ app.kubernetes.io/managed-by: {{ .Release.Service }}
297315
{{- end -}}
298316

299317
{{/*
300-
Define database connection env section.
318+
Define database connection env section.
301319
*/}}
302320
{{- define "invenio.config.database" -}}
303321
- name: INVENIO_DB_USER

charts/invenio/templates/install-init-job.yaml

+1-4
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,7 @@ spec:
3838
env:
3939
- name: TZ
4040
value: {{ required "Missing .Values.global.timezone" .Values.global.timezone }}
41-
- name: INVENIO_BROKER_URL
42-
value: {{ include "invenio.rabbitmq.uri" . }}
43-
- name: INVENIO_CELERY_BROKER_URL
44-
value: {{ include "invenio.rabbitmq.uri" . }}
41+
{{- include "invenio.config.queue" . | nindent 8 }}
4542
{{- include "invenio.config.database" . | nindent 8 }}
4643
volumeMounts:
4744
{{- range $key, $value := .Values.invenio.vocabularies }}

charts/invenio/templates/web-deployment.yaml

+1-4
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,7 @@ spec:
3636
env:
3737
- name: TZ
3838
value: {{ required "Missing .Values.global.timezone" .Values.global.timezone }}
39-
- name: INVENIO_BROKER_URL
40-
value: {{ include "invenio.rabbitmq.uri" . }}
41-
- name: INVENIO_CELERY_BROKER_URL
42-
value: {{ include "invenio.rabbitmq.uri" . }}
39+
{{- include "invenio.config.queue" . | nindent 8 }}
4340
{{- include "invenio.config.database" . | nindent 8 }}
4441
{{- with .Values.web.extraEnvVars }}
4542
{{- toYaml . | nindent 8 }}

charts/invenio/templates/worker-beat-deployment.yaml

+1-4
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,7 @@ spec:
4848
env:
4949
- name: TZ
5050
value: {{ required "Missing .Values.global.timezone" .Values.global.timezone }}
51-
- name: INVENIO_BROKER_URL
52-
value: {{ include "invenio.rabbitmq.uri" . }}
53-
- name: INVENIO_CELERY_BROKER_URL
54-
value: {{ include "invenio.rabbitmq.uri" . }}
51+
{{- include "invenio.config.queue" . | nindent 8 }}
5552
{{- include "invenio.config.database" . | nindent 8}}
5653
{{- with .Values.workerBeat.extraEnvVars }}
5754
{{- toYaml . | nindent 8 }}

charts/invenio/templates/worker-deployment.yaml

+1-4
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,7 @@ spec:
3939
env:
4040
- name: TZ
4141
value: {{ required "Missing .Values.global.timezone" .Values.global.timezone }}
42-
- name: INVENIO_BROKER_URL
43-
value: {{ include "invenio.rabbitmq.uri" . }}
44-
- name: INVENIO_CELERY_BROKER_URL
45-
value: {{ include "invenio.rabbitmq.uri" . }}
42+
{{- include "invenio.config.queue" . | nindent 10 }}
4643
{{- include "invenio.config.database" . | nindent 10 }}
4744
{{- with .Values.worker.extraEnvVars }}
4845
{{- toYaml . | nindent 10 }}

charts/invenio/values.yaml

+24-1
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,8 @@ redis:
333333
cpu: 500m
334334
memory: 500Mi
335335

336+
## RabbitMQ chart configuration
337+
## ref: https://github.com/bitnami/charts/blob/main/bitnami/rabbitmq/values.yaml
336338
rabbitmq:
337339
enabled: true
338340
auth:
@@ -345,7 +347,28 @@ rabbitmq:
345347
cpu: "1"
346348
memory: 2Gi
347349

348-
rabbitmqExternal: {}
350+
## External RabbitMQ configuration
351+
## All of these values are only used when rabbitmq.enabled is set to false
352+
## @param rabbitmqExternal.username RabbitMQ user
353+
## @param rabbitmqExternal.password Password
354+
## @param rabbitmqExternal.amqpPort
355+
## @param rabbitmqExternal.managementPort
356+
## @param rabbitmqExternal.hostname
357+
## @param rabbitmqExternal.protocol
358+
## @param rabbitmqExternal.vhost
359+
## @param rabbitmqExternal.existingSecret Name of an existing secret resource containing the credentials
360+
## @param rabbitmqExternal.existingSecretPasswordKey Name of an existing secret key containing the credentials
361+
##
362+
rabbitmqExternal:
363+
username: invenio
364+
password: ""
365+
amqpPort: 5671
366+
managementPort: 15672
367+
hostname: ""
368+
protocol: ""
369+
vhost: ""
370+
existingSecret: ""
371+
existingSecretPasswordKey: "amqp-password"
349372

350373
flower:
351374
enabled: true

0 commit comments

Comments
 (0)