From 321447fc71e69ba8aca82d032e98ece9041b698f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?G=C3=B6ran=20P=C3=B6hner?=
 <10630407+groundhog2k@users.noreply.github.com>
Date: Tue, 12 Jul 2022 17:55:57 +0200
Subject: [PATCH] Allow force_boot option during redeployment of RabbitMQ
 (#1087)

---
 charts/rabbitmq/README.md                  | 3 ++-
 charts/rabbitmq/RELEASENOTES.md            | 1 +
 charts/rabbitmq/templates/scripts.yaml     | 6 ++++++
 charts/rabbitmq/templates/statefulset.yaml | 2 +-
 charts/rabbitmq/values.yaml                | 2 ++
 5 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/charts/rabbitmq/README.md b/charts/rabbitmq/README.md
index 130c109d..12ff0ac0 100644
--- a/charts/rabbitmq/README.md
+++ b/charts/rabbitmq/README.md
@@ -1,6 +1,6 @@
 # RabbitMQ
 
-![Version: 0.5.4](https://img.shields.io/badge/Version-0.5.4-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 3.10.5](https://img.shields.io/badge/AppVersion-3.10.5-informational?style=flat-square)
+![Version: 0.5.5](https://img.shields.io/badge/Version-0.5.5-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 3.10.5](https://img.shields.io/badge/AppVersion-3.10.5-informational?style=flat-square)
 
 ## Changelog
 
@@ -153,6 +153,7 @@ Section to define custom services
 | authentication.password | string | `"guest"` | Initial password |
 | authentication.erlangCookie | string | `nil` | Erlang cookie (MANDATORY) (Alternative: Set the environment variable ERLANG_COOKIE) |
 | clustering.rebalance | bool | `false` | Enable rebalance queues with master when new replica is created |
+| clustering.forceBoot | bool | `false` | Force boot in case cluster peers are not available |
 | clustering.useLongName | bool | `true` | Use FQDN for RabbitMQ node names |
 
 ## RabbitMQ memory parameters
diff --git a/charts/rabbitmq/RELEASENOTES.md b/charts/rabbitmq/RELEASENOTES.md
index 9208a217..e2ab20a2 100644
--- a/charts/rabbitmq/RELEASENOTES.md
+++ b/charts/rabbitmq/RELEASENOTES.md
@@ -29,4 +29,5 @@
 | 0.5.2 | 3.10.2 | Upgraded to RabbitMQ 3.10.2 |
 | 0.5.3 | 3.10.4 | Upgraded to RabbitMQ 3.10.4 |
 | 0.5.4 | 3.10.5 | Upgraded to RabbitMQ 3.10.5 |
+| 0.5.5 | 3.10.5 | Added force_boot option during cluster redeployment |
 | | | |
diff --git a/charts/rabbitmq/templates/scripts.yaml b/charts/rabbitmq/templates/scripts.yaml
index 42f2984c..241eb1e9 100644
--- a/charts/rabbitmq/templates/scripts.yaml
+++ b/charts/rabbitmq/templates/scripts.yaml
@@ -34,12 +34,18 @@ data:
     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
diff --git a/charts/rabbitmq/templates/statefulset.yaml b/charts/rabbitmq/templates/statefulset.yaml
index d65e7725..bdd289e8 100644
--- a/charts/rabbitmq/templates/statefulset.yaml
+++ b/charts/rabbitmq/templates/statefulset.yaml
@@ -174,7 +174,7 @@ spec:
             {{- toYaml . | nindent 12 }}
           {{- end }}
           lifecycle:
-          {{- if and .Values.clustering.rebalance (gt (.Values.replicaCount | int) 1) }}
+          {{- if gt (.Values.replicaCount | int) 1 }}
             postStart:
               exec:
                 command:
diff --git a/charts/rabbitmq/values.yaml b/charts/rabbitmq/values.yaml
index 3916bbbd..b71a91aa 100644
--- a/charts/rabbitmq/values.yaml
+++ b/charts/rabbitmq/values.yaml
@@ -330,6 +330,8 @@ extraSecretAdvancedConfigs:
 clustering:
   ## Rebalance queues with master when new replica is created
   rebalance: false
+  ## Force boot in case cluster peers are not available
+  forceBoot: false
   ## Use FQDN for RabbitMQ node names
   useLongName: true
 
-- 
GitLab