diff --git a/components/ua/message-broker/rmq-message-broker-chart/configure-rmq-cookie-permissions.sh b/components/ua/message-broker/rmq-message-broker-chart/configure-rmq-cookie-permissions.sh new file mode 100644 index 00000000..a5455c61 --- /dev/null +++ b/components/ua/message-broker/rmq-message-broker-chart/configure-rmq-cookie-permissions.sh @@ -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." \ No newline at end of file diff --git a/components/ua/message-broker/rmq-message-broker-chart/templates/configure-rmq-cookie-permissions-config.yaml b/components/ua/message-broker/rmq-message-broker-chart/templates/configure-rmq-cookie-permissions-config.yaml new file mode 100644 index 00000000..c0329f6a --- /dev/null +++ b/components/ua/message-broker/rmq-message-broker-chart/templates/configure-rmq-cookie-permissions-config.yaml @@ -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 diff --git a/components/ua/message-broker/rmq-message-broker-chart/templates/uex-init-job-config.yaml b/components/ua/message-broker/rmq-message-broker-chart/templates/uex-init-job-config.yaml new file mode 100644 index 00000000..dc624131 --- /dev/null +++ b/components/ua/message-broker/rmq-message-broker-chart/templates/uex-init-job-config.yaml @@ -0,0 +1,38 @@ +apiVersion: v1 +data: + uex-init-job.sh: | + #!/bin/bash + set -e + MAX_RETRIES="${MAX_RETRIES:-10}" + SLEEP_SECONDS="${SLEEP_SECONDS:-10}" + RABBITMQ_STATUS=false + NODE="rabbit@rmq-message-broker-server-0.rmq-message-broker-nodes.apps" + + echo "Checking RabbitMQ node status for node : $NODE" + + for ((i=1; i<=MAX_RETRIES; i++)); do + if rabbitmqctl -n "$NODE" -l status > /dev/null 2>&1; then + echo "RabbitMQ is ready." + RABBITMQ_STATUS=true + break + fi + + # Sleep on the last attempt + if (( i < MAX_RETRIES )); then + echo "[$i/$MAX_RETRIES] RabbitMQ not ready. Retrying in ${SLEEP_SECONDS}s..." + sleep "$SLEEP_SECONDS" + else + echo "[$i/$MAX_RETRIES] RabbitMQ not ready. No more attempts, giving up." + fi + done + + if ! $RABBITMQ_STATUS; then + echo "RabbitMQ never became ready after $((MAX_RETRIES * SLEEP_SECONDS)) seconds." + exit 1 + fi + + echo "Enabling message tracing..." + rabbitmqctl -n "$NODE" -l trace_on -p uex +kind: ConfigMap +metadata: + name: uex-init-job-config diff --git a/components/ua/message-broker/rmq-message-broker-chart/templates/uex-init-job.yaml b/components/ua/message-broker/rmq-message-broker-chart/templates/uex-init-job.yaml new file mode 100644 index 00000000..15a87a4b --- /dev/null +++ b/components/ua/message-broker/rmq-message-broker-chart/templates/uex-init-job.yaml @@ -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: {} \ No newline at end of file diff --git a/components/ua/message-broker/rmq-message-broker-chart/uex-init-job.sh b/components/ua/message-broker/rmq-message-broker-chart/uex-init-job.sh new file mode 100644 index 00000000..5e9c7964 --- /dev/null +++ b/components/ua/message-broker/rmq-message-broker-chart/uex-init-job.sh @@ -0,0 +1,32 @@ +#!/bin/bash +set -e +MAX_RETRIES="${MAX_RETRIES:-10}" +SLEEP_SECONDS="${SLEEP_SECONDS:-10}" +RABBITMQ_STATUS=false +NODE="rabbit@rmq-message-broker-server-0.rmq-message-broker-nodes.apps" + +echo "Checking RabbitMQ node status for node : $NODE" + +for ((i=1; i<=MAX_RETRIES; i++)); do + if rabbitmqctl -n "$NODE" -l status > /dev/null 2>&1; then + echo "RabbitMQ is ready." + RABBITMQ_STATUS=true + break + fi + + # Sleep on the last attempt + if (( i < MAX_RETRIES )); then + echo "[$i/$MAX_RETRIES] RabbitMQ not ready. Retrying in ${SLEEP_SECONDS}s..." + sleep "$SLEEP_SECONDS" + else + echo "[$i/$MAX_RETRIES] RabbitMQ not ready. No more attempts, giving up." + fi +done + +if ! $RABBITMQ_STATUS; then + echo "RabbitMQ never became ready after $((MAX_RETRIES * SLEEP_SECONDS)) seconds." + exit 1 +fi + +echo "Enabling message tracing..." +rabbitmqctl -n "$NODE" -l trace_on -p uex diff --git a/components/ua/message-broker/rmq-message-broker-chart/values.yaml b/components/ua/message-broker/rmq-message-broker-chart/values.yaml index 43e4ca7a..86c5d19b 100644 --- a/components/ua/message-broker/rmq-message-broker-chart/values.yaml +++ b/components/ua/message-broker/rmq-message-broker-chart/values.yaml @@ -7,4 +7,19 @@ namespace: "apps" admin_secret: "uex-admin-secret" # ensures cluster operator doesnt use latest images -image: "rabbitmq:4-management" \ No newline at end of file +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 \ No newline at end of file