From 78a6ec28ff5e209f2857ba291665aead49311bf9 Mon Sep 17 00:00:00 2001
From: groundhog2k <10630407+groundhog2k@users.noreply.github.com>
Date: Sun, 24 Jan 2021 12:02:53 +0100
Subject: [PATCH] Fixed issues #192, #191, #169 forRabbitMQ (#193)

---
 charts/rabbitmq/Chart.yaml                 |  4 +--
 charts/rabbitmq/README.md                  |  4 ++-
 charts/rabbitmq/templates/secrets.yaml     | 29 +++++++--------
 charts/rabbitmq/templates/statefulset.yaml | 42 ++++++++++++++--------
 charts/rabbitmq/values.yaml                | 12 +++++--
 5 files changed, 55 insertions(+), 36 deletions(-)

diff --git a/charts/rabbitmq/Chart.yaml b/charts/rabbitmq/Chart.yaml
index 1b225ad2..8019cc96 100644
--- a/charts/rabbitmq/Chart.yaml
+++ b/charts/rabbitmq/Chart.yaml
@@ -7,6 +7,6 @@ type: application
 maintainers:
   - name: groundhog2k
 
-version: 0.2.6
+version: 0.2.7
 
-appVersion: 3.8.10
+appVersion: "3.8.10"
diff --git a/charts/rabbitmq/README.md b/charts/rabbitmq/README.md
index 4e170ca4..e3dd3911 100644
--- a/charts/rabbitmq/README.md
+++ b/charts/rabbitmq/README.md
@@ -1,6 +1,6 @@
 # RabbitMQ
 
-![Version: 0.2.6](https://img.shields.io/badge/Version-0.2.6-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 3.8.10](https://img.shields.io/badge/AppVersion-3.8.10-informational?style=flat-square)
+![Version: 0.2.7](https://img.shields.io/badge/Version-0.2.7-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 3.8.10](https://img.shields.io/badge/AppVersion-3.8.10-informational?style=flat-square)
 
 A Helm chart for a RabbitMQ cluster on Kubernetes
 
@@ -56,6 +56,8 @@ $ helm uninstall my-release
 | imagePullSecrets | list | `[]` | Image pull secrets |
 | livenessProbe | object | `see values.yaml` | Liveness probe configuration |
 | readinessProbe | object | `see values.yaml` | Readiness probe configuration |
+| customLivenessProbe | object | `{}` | Custom liveness probe (overwrites default liveness probe configuration) |
+| customReadinessProbe | object | `{}` | Custom readiness probe (overwrites default readiness probe configuration) |
 | resources | object | `{}` | Resource limits and requests |
 | nodeSelector | object | `{}` | Deployment node selector |
 | podAnnotations | object | `{}` | Additional pod annotations |
diff --git a/charts/rabbitmq/templates/secrets.yaml b/charts/rabbitmq/templates/secrets.yaml
index 025cdc84..e91fabcb 100644
--- a/charts/rabbitmq/templates/secrets.yaml
+++ b/charts/rabbitmq/templates/secrets.yaml
@@ -1,3 +1,12 @@
+{{- $existingErlangCookie := "" }}
+{{- $existingUser := "" }}
+{{- $existingPassword := "" }}
+{{- $secret := (lookup "v1" "Secret" .Release.Namespace (include "rabbitmq.fullname" .) ) }}
+{{- if $secret }}
+{{- $existingErlangCookie = index $secret.data "RABBITMQ_ERLANG_COOKIE" }}
+{{- $existingUser = index $secret.data "RABBITMQ_DEFAULT_USER" }}
+{{- $existingPassword = index $secret.data "RABBITMQ_DEFAULT_PASS" }}
+{{- end -}}
 apiVersion: v1
 kind: Secret
 metadata:
@@ -5,19 +14,7 @@ metadata:
   labels:
     {{- include "rabbitmq.labels" . | nindent 4 }}
 type: Opaque
-stringData:
-  {{- if .Values.authentication.erlangCookie }}
-  RABBITMQ_ERLANG_COOKIE: {{ .Values.authentication.erlangCookie }}
-  {{- else }}
-  RABBITMQ_ERLANG_COOKIE: {{ randAlphaNum 32 | b64enc | quote }}
-  {{- end }}
-  {{- if .Values.authentication.user }}
-  RABBITMQ_DEFAULT_USER: {{ .Values.authentication.user }}
-  {{- else }}
-  RABBITMQ_DEFAULT_USER: guest
-  {{- end }}
-  {{- if .Values.authentication.password }}
-  RABBITMQ_DEFAULT_PASS: {{ .Values.authentication.password }}
-  {{- else }}
-  RABBITMQ_DEFAULT_PASS: {{ randAlphaNum 10 | b64enc | quote }}
-  {{- end }}
+data:
+  RABBITMQ_ERLANG_COOKIE: {{ (coalesce (.Values.authentication.erlangCookie | default "" | b64enc) $existingErlangCookie (randAlphaNum 32 | b64enc)) | quote }}
+  RABBITMQ_DEFAULT_USER: {{ (coalesce (.Values.authentication.user | default "" | b64enc) $existingUser ("guest" | b64enc)) | quote }}
+  RABBITMQ_DEFAULT_PASS: {{ (coalesce (.Values.authentication.password | default "" | b64enc) $existingPassword (randAlphaNum 10 | b64enc)) | quote }}
diff --git a/charts/rabbitmq/templates/statefulset.yaml b/charts/rabbitmq/templates/statefulset.yaml
index 77b40f55..53456d3c 100644
--- a/charts/rabbitmq/templates/statefulset.yaml
+++ b/charts/rabbitmq/templates/statefulset.yaml
@@ -15,10 +15,12 @@ spec:
     type: {{ .Values.updateStrategyType }}
   template:
     metadata:
-    {{- with .Values.podAnnotations }}
       annotations:
+        checksum/rabbit-config: {{ include (print $.Template.BasePath "/rabbit-config.yaml") . | sha256sum }}
+        checksum/plugins-config: {{ include (print $.Template.BasePath "/plugins-config.yaml") . | sha256sum }}
+      {{- with .Values.podAnnotations }}
         {{- toYaml . | nindent 8 }}
-    {{- end }}
+      {{- end }}
       labels:
         {{- include "rabbitmq.selectorLabels" . | nindent 8 }}
     spec:
@@ -68,6 +70,10 @@ spec:
               containerPort: 4369
             - name: dist
               containerPort: 25672
+          {{- if .Values.customLivenessProbe }}
+          livenessProbe:
+            {{- toYaml .Values.customLivenessProbe | nindent 12 }}
+          {{- else }}
           {{- if .Values.livenessProbe.enabled }}
           livenessProbe:
             exec:
@@ -75,12 +81,19 @@ spec:
                 - /bin/bash
                 - -ec
                 - rabbitmq-diagnostics -q check_running
-            initialDelaySeconds: {{ .Values.livenessProbe.initialDelaySeconds }}
-            periodSeconds: {{ .Values.livenessProbe.periodSeconds }}
-            timeoutSeconds: {{ .Values.livenessProbe.timeoutSeconds }}
-            successThreshold: {{ .Values.livenessProbe.successThreshold }}
-            failureThreshold: {{ .Values.livenessProbe.failureThreshold }}
+          {{- with .Values.livenessProbe }}
+            initialDelaySeconds: {{ .initialDelaySeconds }}
+            periodSeconds: {{ .periodSeconds }}
+            timeoutSeconds: {{ .timeoutSeconds }}
+            successThreshold: {{ .successThreshold }}
+            failureThreshold: {{ .failureThreshold }}
+          {{- end }}
+          {{- end }}
           {{- end }}
+          {{- if .Values.customReadinessProbe }}
+          readinessProbe:
+            {{- toYaml .Values.customReadinessProbe | nindent 12 }}
+          {{- else }}
           {{- if .Values.readinessProbe.enabled }}
           readinessProbe:
             exec:
@@ -88,11 +101,14 @@ spec:
                 - /bin/bash
                 - -ec
                 - rabbitmq-diagnostics -q check_running
-            initialDelaySeconds: {{ .Values.readinessProbe.initialDelaySeconds }}
-            periodSeconds: {{ .Values.readinessProbe.periodSeconds }}
-            timeoutSeconds: {{ .Values.readinessProbe.timeoutSeconds }}
-            successThreshold: {{ .Values.readinessProbe.successThreshold }}
-            failureThreshold: {{ .Values.readinessProbe.failureThreshold }}
+          {{- with .Values.readinessProbe }}
+            initialDelaySeconds: {{ .initialDelaySeconds }}
+            periodSeconds: {{ .periodSeconds }}
+            timeoutSeconds: {{ .timeoutSeconds }}
+            successThreshold: {{ .successThreshold }}
+            failureThreshold: {{ .failureThreshold }}
+          {{- end }}
+          {{- end }}
           {{- end }}
           {{- with .Values.resources }}
           resources:
@@ -192,8 +208,6 @@ spec:
   volumeClaimTemplates:
     - metadata:
         name: rabbitmq-volume
-        labels:
-          {{- include "rabbitmq.labels" . | nindent 10 }}
       spec:
         {{- with .Values.storage.accessModes }}
         accessModes:
diff --git a/charts/rabbitmq/values.yaml b/charts/rabbitmq/values.yaml
index 5be3c239..95041210 100644
--- a/charts/rabbitmq/values.yaml
+++ b/charts/rabbitmq/values.yaml
@@ -69,8 +69,8 @@ ingress:
   ## Hosts
   hosts:
     - host:
-        paths:
-          - /
+      paths:
+        - /
 #  tls:
 #    - hosts:
 #      - rabbitmq.local
@@ -90,6 +90,9 @@ nodeSelector: {}
 tolerations: []
 affinity: {}
 
+## Custom liveness probe (overwrites default liveness probe)
+customLivenessProbe: {}
+
 ## Default liveness probe
 livenessProbe:
   enabled: true
@@ -99,7 +102,10 @@ livenessProbe:
   failureThreshold: 5
   successThreshold: 1
 
-## Default startup probe
+## Custom readiness probe (overwrites default readiness probe)
+customReadinessProbe: {}
+
+## Default readiness probe
 readinessProbe:
   enabled: true
   initialDelaySeconds: 60
-- 
GitLab