Your commit message

This commit is contained in:
zeaslity
2024-11-27 10:33:20 +08:00
commit 080c7bb97f
911 changed files with 168439 additions and 0 deletions

View File

@@ -0,0 +1,197 @@
{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "rabbitmq.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}
{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "rabbitmq.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default .Chart.Name .Values.nameOverride }}
{{- if contains $name .Release.Name }}
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}
{{- end }}
{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "rabbitmq.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}
{{/*
Common labels
*/}}
{{- define "rabbitmq.labels" -}}
helm.sh/chart: {{ include "rabbitmq.chart" . }}
{{ include "rabbitmq.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}
{{/*
Selector labels
*/}}
{{- define "rabbitmq.selectorLabels" -}}
app.kubernetes.io/name: {{ include "rabbitmq.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}
{{/*
Create the name of the service account to use
*/}}
{{- define "rabbitmq.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "rabbitmq.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
{{/*
Return the number of bytes given a value
following a base 2 o base 10 number system.
Usage:
{{ include "rabbitmq.toBytes" .Values.path.to.the.Value }}
*/}}
{{- define "rabbitmq.toBytes" -}}
{{- $value := int (regexReplaceAll "([0-9]+).*" . "${1}") }}
{{- $unit := regexReplaceAll "[0-9]+(.*)" . "${1}" }}
{{- if eq $unit "Ki" }}
{{- mul $value 1024 }}
{{- else if eq $unit "Mi" }}
{{- mul $value 1024 1024 }}
{{- else if eq $unit "Gi" }}
{{- mul $value 1024 1024 1024 }}
{{- else if eq $unit "Ti" }}
{{- mul $value 1024 1024 1024 1024 }}
{{- else if eq $unit "Pi" }}
{{- mul $value 1024 1024 1024 1024 1024 }}
{{- else if eq $unit "Ei" }}
{{- mul $value 1024 1024 1024 1024 1024 1024 }}
{{- else if eq $unit "K" }}
{{- mul $value 1000 }}
{{- else if eq $unit "M" }}
{{- mul $value 1000 1000 }}
{{- else if eq $unit "G" }}
{{- mul $value 1000 1000 1000 }}
{{- else if eq $unit "T" }}
{{- mul $value 1000 1000 1000 1000 }}
{{- else if eq $unit "P" }}
{{- mul $value 1000 1000 1000 1000 1000 }}
{{- else if eq $unit "E" }}
{{- mul $value 1000 1000 1000 1000 1000 1000 }}
{{- end }}
{{- end -}}
{{/*
Management UI plugin options (when plugin is enabled)
*/}}
{{- define "rabbitmq.managementPluginOptions" -}}
{{- if .Values.managementPlugin.enabled }}
## Management UI plugin options
management.tcp.port = {{ .Values.managementPlugin.tcp.port }}
{{- end }}
{{- end -}}
{{/*
K8 peer discovery cluster plugin options (when plugin is enabled)
*/}}
{{- define "rabbitmq.k8sPeerDiscoveryPluginOptions" -}}
{{- if .Values.k8sPeerDiscoveryPlugin.enabled }}
## Clustering with K8s peer discovery plugin
cluster_formation.peer_discovery_backend = rabbit_peer_discovery_k8s
cluster_formation.k8s.host = kubernetes.default.svc.{{ .Values.clusterDomain }}
cluster_formation.k8s.address_type = {{ .Values.k8sPeerDiscoveryPlugin.addressType }}
cluster_formation.k8s.service_name = {{ template "rabbitmq.fullname" . }}-internal
cluster_formation.k8s.hostname_suffix = .{{ template "rabbitmq.fullname" . }}-internal.{{ .Release.Namespace }}.svc.{{ .Values.clusterDomain }}
{{- end }}
{{- end -}}
{{/*
Prometheus plugin options (when plugin is enabled)
*/}}
{{- define "rabbitmq.prometheusPluginOptions" -}}
{{- if .Values.prometheusPlugin.enabled }}
## Prometheus plugin options
prometheus.tcp.port = {{ .Values.prometheusPlugin.tcp.port }}
{{- end }}
{{- end -}}
{{/*
Main RabbitMQ options
*/}}
{{- define "rabbitmq.options" -}}
## Initial login user
default_user = {{ (.Values.authentication).user | default "guest" }}
default_pass = {{ (.Values.authentication).password | default "guest" }}
loopback_users.guest = false
## RabbitMQ options
listeners.tcp.default = {{ .Values.options.tcp.port }}
{{- with .Values.options.ssl }}
{{- if .enabled }}
## SSL options
listeners.ssl.default = {{ .port }}
{{- if .verify }}
ssl_options.verify = verify_peer
{{- else }}
ssl_options.verify = verify_none
{{- end }}
ssl_options.fail_if_no_peer_cert = {{ .failIfNoPeerCert }}
{{- if .depth }}
ssl_options.depth = {{ .depth }}
{{- end }}
{{- end }}
{{- end }}
{{- with .Values.certificates }}
{{- if .enabled }}
{{- if .cacert }}
ssl_options.cacertfile = /ssl/cacert
{{- end }}
{{- if .cert }}
ssl_options.certfile = /ssl/cert
{{- end }}
{{- if .key }}
ssl_options.keyfile = /ssl/key
{{- end }}
{{- if .password }}
ssl_options.password = {{ .password }}
{{- end }}
{{- end }}
{{- end }}
## Memory options
{{- if ((.Values.options).memory).calculationStrategy }}
vm_memory_calculation_strategy = {{ .Values.options.memory.calculationStrategy }}
{{- end}}
{{- if ((.Values.options).memory).totalAvailableOverrideValue }}
total_memory_available_override_value = {{ .Values.options.memory.totalAvailableOverrideValue }}
{{- else }}
{{- $memLimit := ((.Values.resources).limits).memory -}}
{{- if $memLimit }}
total_memory_available_override_value = {{ include "rabbitmq.toBytes" $memLimit }}
{{- end }}
{{- end }}
{{- with .Values.options.memoryHighWatermark }}
{{- if .enabled }}
## Memory Threshold
vm_memory_high_watermark.{{ .type }} = {{ .value }}
{{- if .pagingRatio }}
vm_memory_high_watermark_paging_ratio = {{ .pagingRatio }}
{{- end }}
{{- end }}
{{- end }}
{{- end -}}

View File

@@ -0,0 +1,28 @@
{{- if .Values.certificates.enabled }}
apiVersion: v1
kind: Secret
metadata:
name: {{ include "rabbitmq.fullname" . }}-certs
labels:
{{- include "rabbitmq.labels" . | nindent 4 }}
type: Opaque
data:
{{- with .Values.certificates -}}
{{- if .cacert }}
cacert: |
{{ .cacert | b64enc }}
{{- end }}
{{- if .cert }}
cert: |
{{ .cert | b64enc }}
{{- end }}
{{- if .key }}
key: |
{{ .key | b64enc }}
{{- end }}
{{- range $cert := .extraCerts }}
{{ $cert.name }}: |
{{ $cert.cert | b64enc }}
{{- end }}
{{- end }}
{{- end }}

View File

@@ -0,0 +1,34 @@
{{- $fullname := include "rabbitmq.fullname" . }}
{{- $labels := include "rabbitmq.labels" . }}
{{- $selectorLabels := include "rabbitmq.selectorLabels" . }}
{{- range $service := .Values.extraServices }}
apiVersion: v1
kind: Service
metadata:
name: {{ $fullname }}-{{ $service.name }}
labels:
{{- $labels | nindent 4 }}
{{- with $service.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
type: {{ $service.type }}
ports:
- port: {{ $service.port }}
targetPort: {{ $service.name }}
protocol: {{ $service.protocol }}
name: {{ $service.name }}
{{- if and ( or (eq $service.type "LoadBalancer") (eq $service.type "NodePort") ) ($service.nodePort) }}
nodePort: {{ $service.nodePort }}
{{- end }}
{{- if and (eq $service.type "LoadBalancer") ($service.loadBalancerIP) }}
loadBalancerIP: {{ $service.loadBalancerIP }}
{{- end }}
{{- if $service.clusterIP }}
clusterIP: {{ $service.clusterIP }}
{{- end }}
selector:
{{- $selectorLabels | nindent 4 }}
---
{{- end }}

View File

@@ -0,0 +1,55 @@
{{- if .Values.ingress.enabled }}
{{- $fullName := include "rabbitmq.fullname" . -}}
{{- $svcPort := .Values.service.mgmt.port -}}
{{- $apiVersion := .Capabilities.APIVersions -}}
{{- if $apiVersion.Has "networking.k8s.io/v1" }}
apiVersion: networking.k8s.io/v1
{{- else }}
{{- if $apiVersion.Has "networking.k8s.io/v1beta1" }}
apiVersion: networking.k8s.io/v1beta1
{{- else }}
apiVersion: extensions/v1beta1
{{- end }}
{{- end }}
kind: Ingress
metadata:
name: {{ $fullName }}
labels:
{{- include "rabbitmq.labels" . | nindent 4 }}
{{- with .Values.ingress.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
{{- if .Values.ingress.tls }}
tls:
{{- range .Values.ingress.tls }}
- hosts:
{{- range .hosts }}
- {{ . | quote }}
{{- end }}
secretName: {{ .secretName }}
{{- end }}
{{- end }}
rules:
{{- range .Values.ingress.hosts }}
- host: {{ .host | quote }}
http:
paths:
{{- range .paths }}
- path: {{ . }}
{{- if $apiVersion.Has "networking.k8s.io/v1" }}
pathType: ImplementationSpecific
backend:
service:
name: {{ $fullName }}
port:
number: {{ $svcPort }}
{{- else }}
backend:
serviceName: {{ $fullName }}
servicePort: {{ $svcPort }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}

View File

@@ -0,0 +1,22 @@
{{- if and (.Values.podDisruptionBudget) (or .Values.podDisruptionBudget.minAvailable .Values.podDisruptionBudget.maxUnavailable) }}
{{- if semverCompare ">=1.21" .Capabilities.KubeVersion.Version }}
apiVersion: policy/v1
{{- else }}
apiVersion: policy/v1beta1
{{- end }}
kind: PodDisruptionBudget
metadata:
name: {{ include "rabbitmq.fullname" . }}
labels:
{{- include "rabbitmq.labels" . | nindent 4 }}
spec:
{{- if .Values.podDisruptionBudget.minAvailable }}
minAvailable: {{ .Values.podDisruptionBudget.minAvailable }}
{{- end }}
{{- if .Values.podDisruptionBudget.maxUnavailable }}
maxUnavailable: {{ .Values.podDisruptionBudget.maxUnavailable }}
{{- end }}
selector:
matchLabels:
{{- include "rabbitmq.selectorLabels" . | nindent 6 }}
{{- end }}

View File

@@ -0,0 +1,22 @@
{{ $plugins := compact (list "") }}
{{- if .Values.k8sPeerDiscoveryPlugin.enabled }}
{{ $plugins = append $plugins "rabbitmq_peer_discovery_k8s" }}
{{- end }}
{{- if .Values.managementPlugin.enabled }}
{{ $plugins = append $plugins "rabbitmq_management" }}
{{- end }}
{{- if .Values.prometheusPlugin.enabled }}
{{ $plugins = append $plugins "rabbitmq_prometheus"}}
{{- end }}
{{- if .Values.plugins }}
{{ $plugins = concat $plugins .Values.plugins }}
{{- end }}
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "rabbitmq.fullname" . }}-plugins
labels:
{{- include "rabbitmq.labels" . | nindent 4 }}
data:
enabled_plugins: |
[{{- join "," $plugins }}].

View File

@@ -0,0 +1,20 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ template "rabbitmq.fullname" . }}-config
labels:
{{- include "rabbitmq.labels" . | nindent 4 }}
data:
rabbitmq.conf: |+
{{- include "rabbitmq.options" . | nindent 4 }}
{{- include "rabbitmq.managementPluginOptions" . | nindent 4 }}
{{- include "rabbitmq.k8sPeerDiscoveryPluginOptions" . | nindent 4 }}
{{- include "rabbitmq.prometheusPluginOptions" . | nindent 4 }}
{{- if .Values.customConfig }}
## Custom configuration
{{ .Values.customConfig | nindent 4 }}
{{- end }}
{{- if .Values.customAdvancedConfig }}
advanced.config: |+
{{ .Values.customAdvancedConfig | nindent 4 }}
{{- end }}

View File

@@ -0,0 +1,14 @@
{{- if .Values.rbac.create }}
kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: {{ template "rabbitmq.fullname" . }}-endpoint-reader
labels: {{- include "rabbitmq.labels" . | nindent 4 }}
rules:
- apiGroups: [""]
resources: ["endpoints"]
verbs: ["get"]
# - apiGroups: [""]
# resources: ["events"]
# verbs: ["create"]
{{- end }}

View File

@@ -0,0 +1,14 @@
{{- if and .Values.serviceAccount.create .Values.rbac.create }}
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: {{ template "rabbitmq.fullname" . }}-endpoint-reader
labels: {{- include "rabbitmq.labels" . | nindent 4 }}
subjects:
- kind: ServiceAccount
name: {{ template "rabbitmq.serviceAccountName" . }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: {{ template "rabbitmq.fullname" . }}-endpoint-reader
{{- end }}

View File

@@ -0,0 +1,80 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "rabbitmq.fullname" . }}-scripts
labels:
{{- include "rabbitmq.labels" . | nindent 4 }}
data:
init.sh: |
#!/bin/sh
echo "Initializing RabbitMQ instance..."
echo "Copy configuration"
cp /temp/rabbitmq/* /etc/rabbitmq
if [ -d /extraconfigs ]; then
echo "Add extra configs to rabbitmq config"
cat /extraconfigs/* >>/etc/rabbitmq/rabbitmq.conf
fi
if [ -d /extraadvancedconfigs ]; then
echo "Add extra advanced configs to rabbitmq advanced config"
cat /extraadvancedconfigs/* >>/etc/rabbitmq/advanced.conf
fi
if [ -d /temp/plugins ]; then
echo "Copy plugin configuration"
cp /temp/plugins/* /etc/rabbitmq
else
echo "No plugins configured."
fi
mkdir -p /etc/rabbitmq/conf.d
if [ ! -f /var/lib/rabbitmq/.erlang.cookie ]; then
echo "Copy erlang cookie"
echo $ERLANG_COOKIE >/var/lib/rabbitmq/.erlang.cookie
else
echo "Erlang cookie already exists."
fi
chmod 600 /var/lib/rabbitmq/.erlang.cookie
echo "Finished."
startup.sh: |
{{- if .Values.clustering.forceBoot }}
echo "Forcing boot of cluster instance" >/proc/1/fd/1
rabbitmqctl force_boot
{{- end }}
{{- if .Values.clustering.rebalance }}
until rabbitmqctl cluster_status >/dev/null; do
echo "PostStart: Waiting for cluster readiness..." >/proc/1/fd/1
sleep 5
done
echo "PostStart: Rebalancing all queues.." >/proc/1/fd/1
rabbitmq-queues rebalance "all" >/proc/1/fd/1
{{- end }}
shutdown.sh: |
{{- if and (.Values.terminationGracePeriodSeconds) (gt (int .Values.terminationGracePeriodSeconds) 10) }}
if rabbitmqctl cluster_status; then
echo "PreStop: Will wait up to {{ sub .Values.terminationGracePeriodSeconds 10 }} seconds for node to make sure cluster is healthy after node shutdown" >/proc/1/fd/1
timeout {{ sub .Values.terminationGracePeriodSeconds 10 }} /scripts/safeshutdown.sh
fi
{{- end }}
echo "PreStop: Stopping RabbitMQ" >/proc/1/fd/1
rabbitmqctl stop_app
echo "PreStop: RabbitMQ stopped" >/proc/1/fd/1
sleep 5
safeshutdown.sh: |
while true; do
waiting="false"
if ! rabbitmq-diagnostics -q check_if_node_is_mirror_sync_critical >/proc/1/fd/1; then
echo "PreStop: check_if_node_is_mirror_sync_critical returns error. Continuing to wait" >/proc/1/fd/1
waiting="true"
else
echo "PreStop: check_if_node_is_mirror_sync_critical returns o.k." >/proc/1/fd/1
fi
if ! rabbitmq-diagnostics -q check_if_node_is_quorum_critical >/proc/1/fd/1; then
echo "PreStop: check_if_node_is_quorum_critical returns error. Continuing to wait" >/proc/1/fd/1
waiting="true"
else
echo "PreStop: check_if_node_is_quorum_critical returns o.k." >/proc/1/fd/1
fi
if [ $waiting = "true" ]; then
sleep 1
else
break
fi
done

View File

@@ -0,0 +1,24 @@
apiVersion: v1
kind: Service
metadata:
name: {{ include "rabbitmq.fullname" . }}-internal
labels:
{{- include "rabbitmq.labels" . | nindent 4 }}
spec:
clusterIP: None
publishNotReadyAddresses: true
ports:
- port: {{ .Values.service.amqp.port }}
targetPort: amqp
name: amqp
- port: {{ .Values.service.mgmt.port }}
targetPort: mgmt
name: mgmt
- port: 4369
targetPort: epmd
name: epmd
- port: 25672
targetPort: dist
name: dist
selector:
{{- include "rabbitmq.selectorLabels" . | nindent 4 }}

View File

@@ -0,0 +1,51 @@
apiVersion: v1
kind: Service
metadata:
name: {{ include "rabbitmq.fullname" . }}
labels:
{{- include "rabbitmq.labels" . | nindent 4 }}
{{- with .Values.service.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
ports:
- port: {{ .Values.service.amqp.port }}
targetPort: amqp
name: amqp
{{- if and ( or (eq .Values.service.type "LoadBalancer") (eq .Values.service.type "NodePort") ) (.Values.service.amqp.nodePort) }}
nodePort: {{ .Values.service.amqp.nodePort }}
{{- end }}
{{- if .Values.options.ssl.enabled }}
- port: {{ .Values.service.amqps.port }}
targetPort: amqps
name: amqps
{{- if and ( or (eq .Values.service.type "LoadBalancer") (eq .Values.service.type "NodePort") ) (.Values.service.amqps.nodePort) }}
nodePort: {{ .Values.service.amqps.nodePort }}
{{- end }}
{{- end }}
{{- if .Values.managementPlugin.enabled }}
- port: {{ .Values.service.mgmt.port }}
targetPort: mgmt
name: mgmt
{{- if and ( or (eq .Values.service.type "LoadBalancer") (eq .Values.service.type "NodePort") ) (.Values.service.mgmt.nodePort) }}
nodePort: {{ .Values.service.mgmt.nodePort }}
{{- end }}
{{- end }}
{{- if .Values.prometheusPlugin.enabled }}
- port: {{ .Values.service.prometheus.port }}
targetPort: prometheus
name: prometheus
{{- if and ( or (eq .Values.service.type "LoadBalancer") (eq .Values.service.type "NodePort") ) (.Values.service.prometheus.nodePort) }}
nodePort: {{ .Values.service.prometheus.nodePort }}
{{- end }}
{{- end }}
{{- if and (eq .Values.service.type "LoadBalancer") (.Values.service.loadBalancerIP) }}
loadBalancerIP: {{ .Values.service.loadBalancerIP }}
{{- end }}
{{- if .Values.service.clusterIP }}
clusterIP: {{ .Values.service.clusterIP }}
{{- end }}
selector:
{{- include "rabbitmq.selectorLabels" . | nindent 4 }}
type: {{ .Values.service.type }}

View File

@@ -0,0 +1,14 @@
{{- if .Values.serviceAccount.create }}
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ include "rabbitmq.serviceAccountName" . }}
labels:
{{- include "rabbitmq.labels" . | nindent 4 }}
{{- with .Values.serviceAccount.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
secrets:
- name: {{ include "rabbitmq.fullname" . }}
{{- end }}

View File

@@ -0,0 +1,34 @@
{{- if .Values.serviceMonitor.enabled }}
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: {{ include "rabbitmq.fullname" . }}
labels:
{{- include "rabbitmq.labels" . | nindent 4 }}
{{- with .Values.serviceMonitor.additionalLabels }}
{{- toYaml . | nindent 4 }}
{{- end }}
{{- with .Values.serviceMonitor.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
endpoints:
- port: "prometheus"
path: "/metrics"
{{- if .Values.serviceMonitor.interval }}
interval: {{ .Values.serviceMonitor.interval }}
{{- end }}
{{- if .Values.serviceMonitor.scrapeTimeout }}
scrapeTimeout: {{ .Values.serviceMonitor.scrapeTimeout }}
{{- end }}
{{- with .Values.serviceMonitor.extraEndpointParameters }}
{{- toYaml . | nindent 6 }}
{{- end }}
{{- with .Values.serviceMonitor.extraParameters }}
{{- toYaml . | nindent 2 }}
{{- end }}
selector:
matchLabels:
{{- include "rabbitmq.selectorLabels" . | nindent 6 }}
{{- end }}

View File

@@ -0,0 +1,316 @@
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: {{ include "rabbitmq.fullname" . }}
labels:
{{- include "rabbitmq.labels" . | nindent 4 }}
spec:
selector:
matchLabels:
{{- include "rabbitmq.selectorLabels" . | nindent 6 }}
serviceName: {{ include "rabbitmq.fullname" . }}-internal
podManagementPolicy: {{ .Values.podManagementPolicy }}
replicas: {{ .Values.replicaCount }}
{{- if .Values.revisionHistoryLimit }}
revisionHistoryLimit: {{ .Values.revisionHistoryLimit }}
{{- end }}
updateStrategy:
type: {{ .Values.updateStrategyType }}
template:
metadata:
annotations:
checksum/rabbit-config: {{ include (print $.Template.BasePath "/rabbit-config.yaml") . | sha256sum }}
checksum/plugins-config: {{ include (print $.Template.BasePath "/plugins-config.yaml") . | sha256sum }}
checksum/scripts: {{ include (print $.Template.BasePath "/scripts.yaml") . | sha256sum }}
checksum/certs: {{ include (print $.Template.BasePath "/certs.yaml") . | sha256sum }}
{{- with .Values.podAnnotations }}
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "rabbitmq.selectorLabels" . | nindent 8 }}
spec:
serviceAccountName: {{ include "rabbitmq.serviceAccountName" . }}
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.podSecurityContext }}
securityContext:
{{- toYaml . | nindent 8 }}
{{- end }}
initContainers:
- name: {{ .Chart.Name }}-init
{{- with .Values.securityContext }}
securityContext:
{{- toYaml . | nindent 12 }}
{{- end }}
image: "{{ .Values.initImage.registry }}/{{ .Values.initImage.repository }}:{{ .Values.initImage.tag }}"
imagePullPolicy: {{ .Values.initImage.pullPolicy }}
env:
{{- if .Values.authentication.erlangCookie }}
- name: ERLANG_COOKIE
value: {{ .Values.authentication.erlangCookie }}
{{- end }}
volumeMounts:
- name: config
mountPath: /etc/rabbitmq
{{- if .Values.extraSecretConfigs }}
- mountPath: /extraconfigs
name: extraconfigs-volume
{{- end }}
{{- if .Values.extraSecretAdvancedConfigs }}
- mountPath: /extraadvancedconfigs
name: extraadvancedconfigs-volume
{{- end }}
- name: rabbitconfig
mountPath: /temp/rabbitmq
- name: rabbitmq-volume
mountPath: /var/lib/rabbitmq
- name: scripts
mountPath: /scripts
- name: plugins
mountPath: /temp/plugins
command: [ "/scripts/init.sh" ]
{{- with .Values.extraInitContainers }}
{{- toYaml . | nindent 8 }}
{{- end }}
{{- if .Values.terminationGracePeriodSeconds }}
terminationGracePeriodSeconds: {{ .Values.terminationGracePeriodSeconds }}
{{- end }}
containers:
- name: {{ .Chart.Name }}
{{- with .Values.securityContext }}
securityContext:
{{- toYaml . | nindent 12 }}
{{- end }}
image: "{{ .Values.image.registry }}/{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports:
- name: amqp
containerPort: {{ .Values.options.tcp.port }}
{{- if .Values.options.ssl.enabled }}
- name: amqps
containerPort: {{ .Values.options.ssl.port }}
{{- end }}
{{- if .Values.managementPlugin.enabled }}
- name: mgmt
containerPort: {{ .Values.managementPlugin.tcp.port }}
{{- end }}
{{- if .Values.prometheusPlugin.enabled }}
- name: prometheus
containerPort: {{ .Values.prometheusPlugin.tcp.port }}
{{- end }}
- name: epmd
containerPort: 4369
- name: dist
containerPort: 25672
{{- range $service := .Values.extraServices }}
- name: {{ $service.name }}
containerPort: {{ $service.containerPort}}
protocol: {{ $service.protocol }}
{{- end }}
{{- if .Values.customStartupProbe }}
startupProbe:
{{- toYaml .Values.customStartupProbe | nindent 12 }}
{{- else }}
{{- if .Values.startupProbe.enabled }}
startupProbe:
exec:
command:
- /bin/bash
- -ec
- rabbitmq-diagnostics -q check_running
{{- with .Values.startupProbe }}
initialDelaySeconds: {{ .initialDelaySeconds }}
timeoutSeconds: {{ .timeoutSeconds }}
failureThreshold: {{ .failureThreshold }}
successThreshold: {{ .successThreshold }}
periodSeconds: {{ .periodSeconds }}
{{- end }}
{{- end }}
{{- end }}
{{- if .Values.customLivenessProbe }}
livenessProbe:
{{- toYaml .Values.customLivenessProbe | nindent 12 }}
{{- else }}
{{- if .Values.livenessProbe.enabled }}
livenessProbe:
exec:
command:
- /bin/bash
- -ec
- rabbitmq-diagnostics -q check_running
{{- with .Values.livenessProbe }}
initialDelaySeconds: {{ .initialDelaySeconds }}
timeoutSeconds: {{ .timeoutSeconds }}
periodSeconds: {{ .periodSeconds }}
failureThreshold: {{ .failureThreshold }}
successThreshold: {{ .successThreshold }}
{{- end }}
{{- end }}
{{- end }}
{{- if .Values.customReadinessProbe }}
readinessProbe:
{{- toYaml .Values.customReadinessProbe | nindent 12 }}
{{- else }}
{{- if .Values.readinessProbe.enabled }}
readinessProbe:
exec:
command:
- /bin/bash
- -ec
- rabbitmq-diagnostics -q check_running
{{- with .Values.readinessProbe }}
initialDelaySeconds: {{ .initialDelaySeconds }}
timeoutSeconds: {{ .timeoutSeconds }}
periodSeconds: {{ .periodSeconds }}
failureThreshold: {{ .failureThreshold }}
successThreshold: {{ .successThreshold }}
{{- end }}
{{- end }}
{{- end }}
{{- with .Values.resources }}
resources:
{{- toYaml . | nindent 12 }}
{{- end }}
lifecycle:
{{- if gt (.Values.replicaCount | int) 1 }}
postStart:
exec:
command:
- /bin/bash
- -ec
- /scripts/startup.sh
{{- end }}
preStop:
exec:
command:
- bash
- -ec
- /scripts/shutdown.sh
env:
- name: RABBITMQ_USE_LONGNAME
value: {{ .Values.clustering.useLongName | quote }}
- name: NODE_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
{{- if .Values.clustering.useLongName }}
- name: RABBITMQ_NODENAME
value: rabbit@$(NODE_NAME).{{ include "rabbitmq.fullname" . }}-internal.{{ .Release.Namespace }}.svc.{{ .Values.clusterDomain }}
{{- else }}
- name: RABBITMQ_NODENAME
value: rabbit@$(NODE_NAME)
{{- end }}
{{- with .Values.env }}
{{- toYaml . | nindent 12 }}
{{- end }}
envFrom:
{{- range .Values.extraEnvSecrets }}
- secretRef:
name: {{ . }}
{{- end }}
{{- if .Values.args }}
args:
{{- range .Values.args }}
- {{ . }}
{{- end }}
{{- end }}
volumeMounts:
- name: logs
mountPath: /var/log/rabbitmq
- name: tmp
mountPath: /tmp
- name: rabbitmq-volume
mountPath: /var/lib/rabbitmq
- name: config
mountPath: /etc/rabbitmq
- name: scripts
mountPath: /scripts
{{- if .Values.certificates.enabled }}
- name: certs
mountPath: /ssl
{{- end }}
{{- range $secret := .Values.extraSecrets }}
- name: {{ $secret.name }}
mountPath: {{ $secret.mountPath }}
{{- end }}
{{- with .Values.extraContainers }}
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
volumes:
- name: tmp
emptyDir: {}
- name: logs
emptyDir: {}
- name: config
emptyDir: {}
- name: rabbitconfig
configMap:
name: {{ include "rabbitmq.fullname" . }}-config
{{- if .Values.extraSecretConfigs }}
- name: extraconfigs-volume
secret:
secretName: {{ .Values.extraSecretConfigs }}
{{- end }}
{{- if .Values.extraSecretAdvancedConfigs }}
- name: extraadvancedconfigs-volume
secret:
secretName: {{ .Values.extraSecretAdvancedConfigs }}
{{- end }}
- name: scripts
configMap:
name: {{ include "rabbitmq.fullname" . }}-scripts
defaultMode: 0555
- name: plugins
configMap:
name: {{ include "rabbitmq.fullname" . }}-plugins
{{- if .Values.certificates.enabled }}
- name: certs
secret:
secretName: {{ include "rabbitmq.fullname" . }}-certs
defaultMode: 0440
{{- end }}
{{- range $secret := .Values.extraSecrets }}
- name: {{ $secret.name }}
secret:
secretName: {{ $secret.name }}
defaultMode: 0440
{{- end }}
{{- if .Values.storage.persistentVolumeClaimName }}
- name: rabbitmq-volume
persistentVolumeClaim:
claimName: {{ .Values.storage.persistentVolumeClaimName }}
{{- else }}
{{- if not .Values.storage.requestedSize }}
- name: rabbitmq-volume
emptyDir: {}
{{- else }}
volumeClaimTemplates:
- metadata:
name: rabbitmq-volume
spec:
{{- with .Values.storage.accessModes }}
accessModes:
{{- toYaml . | nindent 10 }}
{{- end }}
{{- if .Values.storage.className }}
storageClassName: {{ .Values.storage.className }}
{{- end }}
resources:
requests:
storage: {{ .Values.storage.requestedSize }}
{{- end }}
{{- end }}