-
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
112 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
57 changes: 57 additions & 0 deletions
57
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,57 @@ | ||
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="http://rabbitmq-svc:15672" | ||
|
||
get_nodes() { | ||
curl -s -u "$RABBITMQ_MGMT_USERNAME:$RABBITMQ_MGMT_PASSWORD" "$RABBITMQ_API/api/nodes" | jq -r '.[].name' | ||
} | ||
|
||
get_feature_flags() { | ||
curl -s -u "$RABBITMQ_MGMT_USERNAME:$RABBITMQ_MGMT_PASSWORD" "$RABBITMQ_API/api/feature-flags" | jq -r '.[] | "\(.name) \(.state)"' | ||
} | ||
|
||
enable_feature_flag() { | ||
local flag_name=$1 | ||
curl -s -u "$RABBITMQ_MGMT_USERNAME:$RABBITMQ_MGMT_PASSWORD" -X PUT "$RABBITMQ_API/api/feature-flags/$flag_name" | jq . | ||
} | ||
|
||
main() { | ||
nodes=$(get_nodes) | ||
if [ -z "$nodes" ]; then | ||
echo "ERROR: No nodes found. Exiting." >&2 | ||
exit 1 | ||
fi | ||
echo "$nodes" | ||
|
||
feature_flags=$(get_feature_flags) | ||
if [ -z "$feature_flags" ]; then | ||
echo "ERROR: No feature flags found. 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" | ||
else | ||
echo "Feature flag $flag is already enabled." | ||
fi | ||
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 |