-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
127 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
ansible/roles/dof_rabbitmq/templates/enable-feature-flags-job-configmap.yaml.j2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
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 "http://$node:$RABBITMQ_PORT/api/feature-flags/$flag_name" | jq . || { | ||
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 |
33 changes: 33 additions & 0 deletions
33
ansible/roles/dof_rabbitmq/templates/enable-feature-flags-job.yaml.j2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |