Skip to content

Commit 13983dd

Browse files
ahsanemonmayrbenjamin92
authored andcommitted
Merged PR 13107: RabbitMQ - update version, add option to use custom config files and modify memory high watermark
- Update rabbitMQ image from 3.9.20 to 3.9.24 - Add option to use custom config files - Add option to modify memory high watermark This PR has fix to the issue of setting proper memory high watermark value caused by [issue](docker-library/rabbitmq#424) Related work items: #34019, #34064, #34065
2 parents c95b218 + e011859 commit 13983dd

4 files changed

Lines changed: 180 additions & 9 deletions

File tree

templates/_helpers.tpl

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,3 +201,64 @@ Return the proper cognigyLiveAgent Credentials Secret Name
201201
{{- printf "%s" (tpl $liveAgentCredentialsSecretName $) -}}
202202
{{- end -}}
203203

204+
{{/*
205+
Validate values of rabbitmq - Memory high watermark
206+
*/}}
207+
{{- define "rabbitmq.validateValues.memoryHighWatermark" -}}
208+
{{- if and (not (eq .Values.statefulRabbitMq.memoryHighWatermark.type "absolute")) (not (eq .Values.statefulRabbitMq.memoryHighWatermark.type "relative")) }}
209+
rabbitmq: statefulRabbitMq.memoryHighWatermark.type
210+
Invalid Memory high watermark type. Valid values are "absolute" and
211+
"relative". Please set a valid mode statefulRabbitMq.memoryHighWatermark.type="xxxx"
212+
{{- else if and .Values.statefulRabbitMq.memoryHighWatermark.enabled (not .Values.statefulRabbitMq.resources.limits.memory) (eq .Values.statefulRabbitMq.memoryHighWatermark.type "relative") }}
213+
rabbitmq: statefulRabbitMq.memoryHighWatermark
214+
You enabled configuring memory high watermark using a relative limit. However,
215+
no memory limits were defined at POD level. Define your POD limits as shown below:
216+
217+
statefulRabbitMq.memoryHighWatermark.enabled=true
218+
statefulRabbitMq.memoryHighWatermark.type="relative"
219+
statefulRabbitMq.memoryHighWatermark.value="0.4"
220+
statefulRabbitMq.resources.limits.memory="2Gi"
221+
222+
Altenatively, user an absolute value for the memory memory high watermark :
223+
224+
statefulRabbitMq.memoryHighWatermark.enabled=true
225+
statefulRabbitMq.memoryHighWatermark.type="absolute"
226+
statefulRabbitMq.memoryHighWatermark.value="512MB"
227+
{{- end -}}
228+
{{- end -}}
229+
230+
{{/*
231+
Return the number of bytes given a value
232+
following a base 2 or base 10 number system.
233+
Usage:
234+
{{ include "rabbitmq.toBytes" .Values.path.to.the.Value }}
235+
*/}}
236+
{{- define "rabbitmq.toBytes" -}}
237+
{{- $value := int (regexReplaceAll "([0-9]+).*" . "${1}") }}
238+
{{- $unit := regexReplaceAll "[0-9]+(.*)" . "${1}" }}
239+
{{- if eq $unit "Ki" }}
240+
{{- mul $value 1024 }}
241+
{{- else if eq $unit "Mi" }}
242+
{{- mul $value 1024 1024 }}
243+
{{- else if eq $unit "Gi" }}
244+
{{- mul $value 1024 1024 1024 }}
245+
{{- else if eq $unit "Ti" }}
246+
{{- mul $value 1024 1024 1024 1024 }}
247+
{{- else if eq $unit "Pi" }}
248+
{{- mul $value 1024 1024 1024 1024 1024 }}
249+
{{- else if eq $unit "Ei" }}
250+
{{- mul $value 1024 1024 1024 1024 1024 1024 }}
251+
{{- else if eq $unit "K" }}
252+
{{- mul $value 1000 }}
253+
{{- else if eq $unit "M" }}
254+
{{- mul $value 1000 1000 }}
255+
{{- else if eq $unit "G" }}
256+
{{- mul $value 1000 1000 1000 }}
257+
{{- else if eq $unit "T" }}
258+
{{- mul $value 1000 1000 1000 1000 }}
259+
{{- else if eq $unit "P" }}
260+
{{- mul $value 1000 1000 1000 1000 1000 }}
261+
{{- else if eq $unit "E" }}
262+
{{- mul $value 1000 1000 1000 1000 1000 1000 }}
263+
{{- end }}
264+
{{- end -}}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
apiVersion: v1
3+
kind: Secret
4+
metadata:
5+
name: cognigy-rabbitmq-config
6+
namespace: {{ $.Release.Namespace | quote }}
7+
annotations:
8+
"helm.sh/resource-policy": "keep"
9+
type: Opaque
10+
data:
11+
rabbitmq.conf: |-
12+
{{- include "common.tplvalues.render" (dict "value" .Values.statefulRabbitMq.configuration "context" $) | b64enc | nindent 4 }}
13+
{{- if .Values.statefulRabbitMq.advancedConfiguration }}
14+
advanced.config: |-
15+
{{- include "common.tplvalues.render" (dict "value" .Values.statefulRabbitMq.advancedConfiguration "context" $) | b64enc | nindent 4 }}
16+
{{- end }}

templates/stateful-deployments/rabbitmq.yaml

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ spec:
1414
metadata:
1515
labels:
1616
app: rabbitmq
17+
annotations:
18+
checksum/cognigy-rabbitmq-config: {{ include (print $.Template.BasePath "/common-secrets/cognigy-rabbitmq-config.yaml") $ | sha256sum }}
1719
spec:
1820
{{- if .affinity }}
1921
affinity: {{- include "common.tplvalues.render" (dict "value" .affinity "context" $) | nindent 8 }}
@@ -43,9 +45,35 @@ spec:
4345
secretKeyRef:
4446
name: cognigy-rabbitmq
4547
key: rabbitmq-password
46-
{{- if .extraEnvVars }}
47-
{{- include "common.tplvalues.render" (dict "value" .extraEnvVars "context" $) | nindent 12 }}
48+
{{- if .advancedConfiguration }}
49+
## Overrides advanced config file location
50+
- name: RABBITMQ_ADVANCED_CONFIG_FILE
51+
value: /etc/rabbitmq/conf.d/advanced.config
52+
{{- end }}
53+
{{- if .extraEnvVars }}
54+
{{- include "common.tplvalues.render" (dict "value" .extraEnvVars "context" $) | nindent 12 }}
55+
{{- end }}
56+
volumeMounts:
57+
- name: configuration
58+
mountPath: /etc/rabbitmq/conf.d/rabbitmq.conf
59+
subPath: rabbitmq.conf
60+
{{- if .advancedConfiguration }}
61+
- name: configuration
62+
mountPath: /etc/rabbitmq/conf.d/advanced.config
63+
subPath: advanced.config
64+
{{- end }}
65+
volumes:
66+
- name: configuration
67+
secret:
68+
secretName: cognigy-rabbitmq-config
69+
items:
70+
- key: rabbitmq.conf
71+
path: rabbitmq.conf
72+
{{- if .advancedConfiguration }}
73+
- key: advanced.config
74+
path: advanced.config
4875
{{- end }}
76+
defaultMode: 0644
4977
{{- include "image.pullSecrets" $ | nindent 6 }}
5078
securityContext:
5179
{{- toYaml .securityContext | nindent 8 }}

values.yaml

Lines changed: 73 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1450,7 +1450,7 @@ amazonCredentials:
14501450
## Stateful Backend Components
14511451
##
14521452
statefulRabbitMq:
1453-
image: cognigy.azurecr.io/rabbitmq:3.9.20_cognigy-4.X
1453+
image: cognigy.azurecr.io/rabbitmq:3.9.24_cognigy-4.X
14541454
replicaCount: 1
14551455
resources:
14561456
limits:
@@ -1460,6 +1460,71 @@ statefulRabbitMq:
14601460
memory: 1Gi
14611461
cpu: "1"
14621462
extraEnvVars: []
1463+
## The memory threshold under which RabbitMQ will stop reading from client network sockets, in order to avoid being killed by the OS
1464+
## ref: https://www.rabbitmq.com/alarms.html
1465+
## ref: https://www.rabbitmq.com/memory.html#threshold
1466+
##
1467+
memoryHighWatermark:
1468+
## Enable configuring Memory high watermark on RabbitMQ
1469+
##
1470+
enabled: true
1471+
## Memory high watermark type. Either `absolute` or `relative`
1472+
##
1473+
type: "relative"
1474+
## Memory high watermark value.
1475+
## The default value of 0.4 stands for 40% of available RAM
1476+
## Note: the memory relative limit is applied to the statefulRabbitMq.resource.limits.memory to calculate the memory threshold
1477+
## You can also use an absolute value, e.g.: 256MB
1478+
##
1479+
value: 0.4
1480+
## RabbitMQ Configuration file content: required cluster configuration
1481+
## ref: https://www.rabbitmq.com/configure.html#configuration-files
1482+
## Do not override unless you know what you are doing.
1483+
## To add more configuration, use `extraConfiguration` of `advancedConfiguration` instead
1484+
##
1485+
configuration: |-
1486+
{{ tpl .Values.statefulRabbitMq.extraConfiguration . }}
1487+
## allow access to the guest user from anywhere on the network
1488+
## https://www.rabbitmq.com/access-control.html#loopback-users
1489+
## https://www.rabbitmq.com/production-checklist.html#users
1490+
loopback_users.guest = false
1491+
1492+
## Send all logs to stdout/TTY. Necessary to see logs when running in a container
1493+
log.console = true
1494+
1495+
{{- if .Values.statefulRabbitMq.memoryHighWatermark.enabled }}
1496+
## Memory Threshold
1497+
##
1498+
total_memory_available_override_value = {{ include "rabbitmq.toBytes" .Values.statefulRabbitMq.resources.limits.memory }}
1499+
vm_memory_high_watermark.{{ .Values.statefulRabbitMq.memoryHighWatermark.type }} = {{ .Values.statefulRabbitMq.memoryHighWatermark.value }}
1500+
{{- end }}
1501+
## Optionally specify Configuration file content: extra configuration to be appended to RabbitMQ configuration
1502+
## Use this instead of `configuration` to add more configuration
1503+
## Example configuration:
1504+
## extraConfiguration: |-
1505+
## listeners.tcp.default = 5672
1506+
##
1507+
extraConfiguration: |-
1508+
#default_vhost = {{ .Release.Namespace }}-vhost
1509+
#disk_free_limit.absolute = 50MB
1510+
1511+
## Optionally specify Configuration file content: advanced configuration
1512+
## Use this as additional configuration in classic config format (Erlang term configuration format)
1513+
## ref: https://www.rabbitmq.com/configure.html#advanced-config-file
1514+
## Example configuration:
1515+
## advancedConfiguration: |-
1516+
## [
1517+
## {rabbit, [
1518+
## {tcp_listeners, [5672]}
1519+
## ]
1520+
## }
1521+
## ].
1522+
advancedConfiguration: |-
1523+
1524+
## RabbitMQ pods' Security Context
1525+
## ref: https://kubernetes.io/docs/tasks/configure-pod-container/security-context/#set-the-security-context-for-a-pod
1526+
## Note: The following values of RabbitMQ pod's Security Context runAsUser and runAsGroup are required to run the pod as non-root user.
1527+
##
14631528
securityContext:
14641529
runAsUser: 1337
14651530
runAsGroup: 1337
@@ -1476,9 +1541,10 @@ statefulRabbitMq:
14761541
##
14771542
tolerations: []
14781543

1479-
# If redis is not required to deploy then you can set the "statefulRedis.enabled" flag to false. By default it is always enabled.
1480-
# statefulRedis:
1481-
# enabled: false
1544+
1545+
## If redis is not required to deploy then you can set the "statefulRedis.enabled" flag to false. By default it is always enabled.
1546+
## statefulRedis:
1547+
## enabled: false
14821548

14831549
statefulRedis:
14841550
enabled: true
@@ -1506,9 +1572,9 @@ statefulRedis:
15061572
##
15071573
tolerations: []
15081574

1509-
# If redis-persistent is not required to deploy then you can set the "statefulRedis.enabled" flag to false. By default it is always enabled.
1510-
# statefulRedisPersistent:
1511-
# enabled: false
1575+
## If redis-persistent is not required to deploy then you can set the "statefulRedis.enabled" flag to false. By default it is always enabled.
1576+
## statefulRedisPersistent:
1577+
## enabled: false
15121578

15131579
statefulRedisPersistent:
15141580
enabled: true

0 commit comments

Comments
 (0)