Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BC-8618 update to rabbitmq 4.0.x and auto-enable feature flags #1071

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion ansible/collections/requirements.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---
collections:
- name: kubernetes.core
version: 2.4.0
version: 5.0.0
2 changes: 1 addition & 1 deletion ansible/roles/dof_rabbitmq/defaults/main.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
RABBITMQ_IMAGE_NAME: docker.io/rabbitmq
RABBITMQ_IMAGE_TAG: 3.13.7-management
RABBITMQ_IMAGE_TAG: 4.0.5-management-alpine
RABBITMQ_PER_OBJECT_METRICS: "true"
28 changes: 28 additions & 0 deletions ansible/roles/dof_rabbitmq/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,31 @@
when: RABBITMQ_SERVICE_MONITOR is undefined or RABBITMQ_SERVICE_MONITOR is defined and not RABBITMQ_SERVICE_MONITOR
tags:
- prometheus


- name: Enable Feature Flags ConfigMap
kubernetes.core.k8s:
kubeconfig: ~/.kube/config
namespace: "{{ NAMESPACE }}"
template: enable-feature-flags-job-configmap.yaml.j2
tags:
- configmap

- name: Delete existing feature flags job if it exists
kubernetes.core.k8s:
kubeconfig: ~/.kube/config
namespace: "{{ NAMESPACE }}"
api_version: batch/v1
kind: Job
name: enable-feature-flags-job
state: absent
tags:
- job

- name: Create the Enable Feature Flags Job
kubernetes.core.k8s:
kubeconfig: ~/.kube/config
namespace: "{{ NAMESPACE }}"
template: enable-feature-flags-job.yaml.j2
tags:
- job
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: enable-feature-flags-script
namespace: {{ NAMESPACE }}
labels:
app: rabbitmq
data:
enable_feature_flags.sh: |
#!/bin/bash
set -euo pipefail

if [ -z "${RABBITMQ_MGMT_USERNAME:-}" ] || [ -z "${RABBITMQ_MGMT_PASSWORD:-}" ]; then
echo "ERROR: RABBITMQ_MGMT_USERNAME and RABBITMQ_MGMT_PASSWORD must be set." >&2
exit 1
fi

RABBITMQ_API="${RABBITMQ_API:-http://rabbitmq-svc}"
RABBITMQ_PORT="${RABBITMQ_PORT:-15672}"

get_nodes() {
curl -sf -u "$RABBITMQ_MGMT_USERNAME:$RABBITMQ_MGMT_PASSWORD" "$RABBITMQ_API:$RABBITMQ_PORT/api/nodes" | jq -r '.[].name | sub("^.*@"; "")' || {
echo "ERROR: Failed to fetch nodes." >&2
exit 1
}
}

get_feature_flags() {
local node=$1
curl -sf -u "$RABBITMQ_MGMT_USERNAME:$RABBITMQ_MGMT_PASSWORD" "http://$node:$RABBITMQ_PORT/api/feature-flags" | jq -r '.[] | "\(.name) \(.state)"' || {
echo "ERROR: Failed to fetch feature flags for node $node." >&2
exit 1
}
}

enable_feature_flag() {
local flag_name=$1
local node=$2
curl -sf -u "$RABBITMQ_MGMT_USERNAME:$RABBITMQ_MGMT_PASSWORD" -X PUT \
-H "Content-Type: application/json" \
"http://$node:$RABBITMQ_PORT/api/feature-flags/$flag_name/enable" || {
echo "ERROR: Failed to enable feature flag $flag_name on node $node." >&2
exit 1
}
}

main() {
nodes=$(get_nodes)
if [ -z "$nodes" ]; then
echo "ERROR: No nodes found. Exiting." >&2
exit 1
fi
echo "$nodes"

for node in $nodes; do
feature_flags=$(get_feature_flags "$node")
if [ -z "$feature_flags" ]; then
echo "ERROR: No feature flags found for node $node. Exiting." >&2
exit 1
fi
echo "$feature_flags"

echo "$feature_flags" | while read -r flag state; do
if [ "$state" != "enabled" ]; then
enable_feature_flag "$flag" "$node"
echo "Enabled feature flag $flag on node $node"
else
echo "Feature flag $flag is already enabled on node $node."
fi
done
done
}

main
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
apiVersion: batch/v1
kind: Job
metadata:
name: enable-feature-flags-job
labels:
app: rabbitmq
spec:
template:
metadata:
labels:
app: rabbitmq
spec:
containers:
- name: rabbitmq-enable-feature-flags-job
image: quay.io/schulcloudverbund/infra-tools:latest
envFrom:
- secretRef:
name: rabbitmq-secret
volumeMounts:
- name: script
mountPath: /enable_feature_flags.sh
subPath: enable_feature_flags.sh
command: ['/bin/bash','-c']
args: ['cp /enable_feature_flags.sh /enable_feature_flags.run.sh && chmod +x /enable_feature_flags.run.sh && ./enable_feature_flags.run.sh']
volumes:
- name: script
configMap:
name: enable-feature-flags-script
items:
- key: enable_feature_flags.sh
path: enable_feature_flags.sh
restartPolicy: Never
backoffLimit: 4
Loading