From 7b4fabb06c431f164c27e6b2af32f8548f3ced7a Mon Sep 17 00:00:00 2001 From: portdirect Date: Mon, 5 Mar 2018 09:18:18 -0500 Subject: [PATCH] RabbitMQ: persist stateful data to volume This PS persists stateful data to volumes, allowing the cluster to restart. Change-Id: Ic881230cf2434d5c381542e57dc30df92cd4e158 Closes-Bug: #1753500 --- rabbitmq/templates/statefulset.yaml | 37 +++++++++++++++++++++++++---- rabbitmq/values.yaml | 6 +++++ 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/rabbitmq/templates/statefulset.yaml b/rabbitmq/templates/statefulset.yaml index c3e77e824e..c18cf41b42 100644 --- a/rabbitmq/templates/statefulset.yaml +++ b/rabbitmq/templates/statefulset.yaml @@ -74,7 +74,23 @@ spec: nodeSelector: {{ .Values.labels.server.node_selector_key }}: {{ .Values.labels.server.node_selector_value }} initContainers: -{{ tuple $envAll $dependencies list | include "helm-toolkit.snippets.kubernetes_entrypoint_init_container" | indent 9 }} +{{ tuple $envAll $dependencies list | include "helm-toolkit.snippets.kubernetes_entrypoint_init_container" | indent 8 }} +{{- if .Values.volume.chown_on_start }} + - name: rabbitmq-perms + image: {{ .Values.images.tags.rabbitmq }} + imagePullPolicy: {{ .Values.images.pull_policy }} + securityContext: + runAsUser: 0 +{{ tuple $envAll $envAll.Values.pod.resources.server | include "helm-toolkit.snippets.kubernetes_resources" | indent 10 }} + command: + - chown + - -R + - "rabbitmq:" + - /var/lib/rabbitmq + volumeMounts: + - name: rabbitmq-data + mountPath: /var/lib/rabbitmq +{{- end }} containers: - name: rabbitmq image: {{ .Values.images.tags.rabbitmq }} @@ -114,7 +130,7 @@ spec: command: - /tmp/rabbitmq-liveness.sh volumeMounts: - - name: rabbitmq-emptydir + - name: rabbitmq-data mountPath: /var/lib/rabbitmq - name: rabbitmq-bin mountPath: /tmp @@ -127,8 +143,6 @@ spec: subPath: rabbitmq.conf readOnly: true volumes: - - name: rabbitmq-emptydir - emptyDir: {} - name: rabbitmq-bin configMap: name: {{ printf "%s-%s" $envAll.Release.Name "rabbitmq-bin" | quote }} @@ -137,4 +151,19 @@ spec: configMap: name: {{ printf "%s-%s" $envAll.Release.Name "rabbitmq-etc" | quote }} defaultMode: 0444 + {{- if not .Values.volume.enabled }} + - name: rabbitmq-data + emptyDir: {} + {{- end }} +{{- if .Values.volume.enabled }} + volumeClaimTemplates: + - metadata: + name: rabbitmq-data + spec: + accessModes: [ "ReadWriteOnce" ] + resources: + requests: + storage: {{ .Values.volume.size }} + storageClassName: {{ .Values.volume.class_name }} +{{- end }} {{ end }} diff --git a/rabbitmq/values.yaml b/rabbitmq/values.yaml index 4a52d76238..cbfd90ada4 100644 --- a/rabbitmq/values.yaml +++ b/rabbitmq/values.yaml @@ -184,6 +184,12 @@ endpoints: metrics: default: 9095 +volume: + chown_on_start: true + enabled: true + class_name: general + size: 1Gi + manifests: configmap_bin: true configmap_etc: true