Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env sh

set -eu

SOURCE="/secret/.erlang.cookie"
TARGET="/var/lib/rabbitmq/.erlang.cookie"

echo "Copying Erlang cookie..."

if [ ! -f "$SOURCE" ]; then
echo "Error: $SOURCE does not exist"
exit 1
fi

cp "$SOURCE" "$TARGET"
chown 999:999 "$TARGET"
chmod 400 "$TARGET"

echo "Erlang cookie installed successfully."
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
apiVersion: v1
data:
configure-rmq-cookie-permissions.sh: |-
#!/usr/bin/env sh

set -eu

SOURCE="/secret/.erlang.cookie"
TARGET="/var/lib/rabbitmq/.erlang.cookie"

echo "Copying Erlang cookie..."

if [ ! -f "$SOURCE" ]; then
echo "Error: $SOURCE does not exist"
exit 1
fi

cp "$SOURCE" "$TARGET"
chown 999:999 "$TARGET"
chmod 400 "$TARGET"

echo "Erlang cookie installed successfully."
kind: ConfigMap
metadata:
creationTimestamp: null
name: configure-rmq-cookie-permissions-config
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
apiVersion: v1
data:
uex-init-job.sh: "#!/bin/bash\nset -e\necho \"Checking RabbitMQ node status for
node : rabbit@rmq-message-broker-server-0.rmq-message-broker-nodes.apps\"\n\nMAX_RETRIES=\"${MAX_RETRIES:-10}\"\nSLEEP_SECONDS=\"${SLEEP_SECONDS:-10}\"\nRABBITMQ_STATUS=false\n\nfor
Comment on lines +3 to +4
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't look right, is node: an element rather than part of the previous line? If you use dos2unix to remove the windows style CRLFs on the source file first, kubectl should create a multiline configMap correctly like the one above this, it's much easier to check and understand then (but check the script updates below first)!

i in $(seq 1 \"$MAX_RETRIES\"); do\n if rabbitmqctl -n rabbit@rmq-message-broker-server-0.rmq-message-broker-nodes.apps
-l status > /dev/null 2>&1; then\n echo \"RabbitMQ is ready.\"\n RABBITMQ_STATUS=true\n
\ break\n fi\n\n echo \"[$i/$MAX_RETRIES] RabbitMQ not ready. Retrying in
${SLEEP_SECONDS}s...\" \n\n # Don't sleep on the last attempt\n if [ \"$i\"
-lt \"$MAX_RETRIES\" ]; then\n sleep \"$SLEEP_SECONDS\"\n fi\ndone\n\nif [
\"$RABBITMQ_STATUS\" != true ]; then\n echo \"RabbitMQ never became ready after
$((MAX_RETRIES * SLEEP_SECONDS)) seconds.\" \n exit 1\nfi\n\necho \"Enabling
message tracing...\"\nrabbitmqctl -n rabbit@rmq-message-broker-server-0.rmq-message-broker-nodes.apps
-l trace_on -p uex"
kind: ConfigMap
metadata:
creationTimestamp: null
name: uex-init-job-config
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
apiVersion: batch/v1
kind: Job
metadata:
name: uex-init-job
namespace: apps
spec:
backoffLimit: 3
# ttlSecondsAfterFinished: 600 # seconds
template:
metadata:
labels:
app: uex-init-job
spec:
containers:
- name: uex-init-job
image: {{ $.Values.image }}
imagePullPolicy: IfNotPresent
env:
- name: MAX_RETRIES
value: "10"
- name: SLEEP_SECONDS
value: "5"
volumeMounts:
- name: scripts
mountPath: {{ $.Values.configMap.uex_init_job_config.scriptMountPath }}
subPath: {{ $.Values.configMap.uex_init_job_config.scriptKey }}
- name: rabbitmq-data
mountPath: /var/lib/rabbitmq
command: ["bash", {{ $.Values.configMap.uex_init_job_config.scriptMountPath }}]
restartPolicy: OnFailure

initContainers:
- name: setup-erlang-cookie
image: {{ $.Values.image }}
command:
- bash
- {{ $.Values.configMap.configure_rmq_cookie_permissions_config.scriptMountPath}}
volumeMounts:
- name: erlang-cookie
mountPath: /secret
- name: configure-cookie-script
mountPath: {{ $.Values.configMap.configure_rmq_cookie_permissions_config.scriptMountPath}}
subPath: {{ $.Values.configMap.configure_rmq_cookie_permissions_config.scriptKey}}
- name: rabbitmq-data
mountPath: /var/lib/rabbitmq
volumes:
- name: scripts
configMap:
name: {{ $.Values.configMap.uex_init_job_config.name }}
items:
- key: {{ $.Values.configMap.uex_init_job_config.scriptKey }}
path: {{ $.Values.configMap.uex_init_job_config.scriptKey }}
- name: configure-cookie-script
configMap:
name: {{ $.Values.configMap.configure_rmq_cookie_permissions_config.name }}
items:
- key: {{ $.Values.configMap.configure_rmq_cookie_permissions_config.scriptKey}}
path: {{ $.Values.configMap.configure_rmq_cookie_permissions_config.scriptKey}}
- name: erlang-cookie
secret:
secretName: {{ $.Values.erlang_cookie_secret }}
- name: rabbitmq-data
emptyDir: {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash
set -e
echo "Checking RabbitMQ node status for node : rabbit@rmq-message-broker-server-0.rmq-message-broker-nodes.apps"

MAX_RETRIES="${MAX_RETRIES:-10}"
SLEEP_SECONDS="${SLEEP_SECONDS:-10}"
RABBITMQ_STATUS=false

for i in $(seq 1 "$MAX_RETRIES"); do
if rabbitmqctl -n rabbit@rmq-message-broker-server-0.rmq-message-broker-nodes.apps -l status > /dev/null 2>&1; then
echo "RabbitMQ is ready."
RABBITMQ_STATUS=true
break
fi

echo "[$i/$MAX_RETRIES] RabbitMQ not ready. Retrying in ${SLEEP_SECONDS}s..."

# Don't sleep on the last attempt
if [ "$i" -lt "$MAX_RETRIES" ]; then
sleep "$SLEEP_SECONDS"
fi
Comment on lines +16 to +21
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably not say it's retying in x if it isn't? Also maybe compare numerical vals directly. Try

Suggested change
echo "[$i/$MAX_RETRIES] RabbitMQ not ready. Retrying in ${SLEEP_SECONDS}s..."
# Don't sleep on the last attempt
if [ "$i" -lt "$MAX_RETRIES" ]; then
sleep "$SLEEP_SECONDS"
fi
echo -n "[$i/$MAX_RETRIES] RabbitMQ not ready."
# Sleep on the last attempt
if (( i < MAX_RETRIES )); then
echo " Retrying in ${SLEEP_SECONDS}s..."
sleep "$SLEEP_SECONDS"
else
echo "No more attempts, giving up."
fi

done

if [ "$RABBITMQ_STATUS" != true ]; then
echo "RabbitMQ never became ready after $((MAX_RETRIES * SLEEP_SECONDS)) seconds."
exit 1
fi

echo "Enabling message tracing..."
rabbitmqctl -n rabbit@rmq-message-broker-server-0.rmq-message-broker-nodes.apps -l trace_on -p uex
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,19 @@ namespace: "apps"
admin_secret: "uex-admin-secret"

# ensures cluster operator doesnt use latest images
image: "rabbitmq:4-management"
image: "rabbitmq:4-management"

erlang_cookie_secret: "rmq-message-broker-erlang-cookie"

#UEX specfic kv
configMap:
# Configure cookies
configure_rmq_cookie_permissions_config:
name: configure-rmq-cookie-permissions-config
scriptKey: configure-rmq-cookie-permissions.sh
scriptMountPath: configure-rmq-cookie-permissions.sh
# enable firehose
uex_init_job_config:
name: uex-init-job-config
scriptKey: uex-init-job.sh
scriptMountPath: /uex-init-job.sh