|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +set -euo pipefail |
| 4 | + |
| 5 | +# Update the Messaging Topology operator deployment, providing it with the Vault related environment variables |
| 6 | +echo "Updating Messaging Topology operator to work with Vault..." |
| 7 | +kubectl set env deployment/messaging-topology-operator -n rabbitmq-system --containers='manager' OPERATOR_VAULT_ROLE=messaging-topology-operator VAULT_ADDR=http://vault.default.svc.cluster.local:8200 |
| 8 | +kubectl wait --for=condition=Available deployment/messaging-topology-operator -n rabbitmq-system |
| 9 | +sleep 10 |
| 10 | + |
| 11 | +echo |
| 12 | +echo "Creating RabbitMQ clusters..." |
| 13 | +kubectl apply -f rabbitmq-clusters.yaml |
| 14 | +sleep 10 |
| 15 | +kubectl wait --for=condition=Ready pod/cluster-b-server-0 |
| 16 | +kubectl wait --for=condition=Ready pod/cluster-vault-a-server-0 |
| 17 | + |
| 18 | +echo |
| 19 | +echo "Messaging Topology operator attempting to create a queue in each of the RabbitMQ clusters..." |
| 20 | +kubectl apply -f rabbitmq-queue-a.yaml |
| 21 | +kubectl apply -f rabbitmq-queue-b.yaml |
| 22 | +kubectl wait --for=condition=Ready queue.rabbitmq.com/queue-a |
| 23 | +kubectl wait --for=condition=Ready queue.rabbitmq.com/queue-b |
| 24 | + |
| 25 | +# Verify that the expected queues exist (one in each cluster) |
| 26 | +echo |
| 27 | +echo "Listing all queues in RabbitMQ cluster 'cluster-vault-a'..." |
| 28 | +kubectl exec cluster-vault-a-server-0 -c rabbitmq -- rabbitmqadmin list queues |
| 29 | +echo |
| 30 | +echo "Listing all queues in RabbitMQ cluster 'cluster-b'..." |
| 31 | +kubectl exec cluster-b-server-0 -c rabbitmq -- rabbitmqadmin list queues |
| 32 | + |
| 33 | +echo |
| 34 | +echo "Deleting queues from clusters..." |
| 35 | +kubectl delete -f rabbitmq-queue-a.yaml |
| 36 | +kubectl delete -f rabbitmq-queue-b.yaml |
| 37 | +sleep 10 |
| 38 | + |
| 39 | +# Update the Messaging Topology operator deployment, providing it with an intentionally incorrect Vault role identifier |
| 40 | +echo |
| 41 | +echo "Updating Messaging Topology operator to intentionally break authentication with Vault..." |
| 42 | +kubectl set env deployment/messaging-topology-operator -n rabbitmq-system --containers='manager' OPERATOR_VAULT_ROLE=no-such-role |
| 43 | +kubectl wait --for=condition=Available deployment/messaging-topology-operator -n rabbitmq-system |
| 44 | +sleep 30 |
| 45 | + |
| 46 | +# Attempt to create queues in each cluster (creation in the cluster using Vault should fail) |
| 47 | +echo |
| 48 | +echo "Messaging Topology operator attempting to create a queue in each of the RabbitMQ clusters..." |
| 49 | +kubectl apply -f rabbitmq-queue-c.yaml |
| 50 | +kubectl apply -f rabbitmq-queue-d.yaml |
| 51 | +sleep 10 |
| 52 | +kubectl wait --for=condition=Ready queue.rabbitmq.com/queue-d |
| 53 | + |
| 54 | +# Verify that only the expected queue in the cluster not using Vault for admin credentials exists |
| 55 | +echo |
| 56 | +echo "Listing all queues in RabbitMQ cluster 'cluster-vault-a'..." |
| 57 | +kubectl exec cluster-vault-a-server-0 -c rabbitmq -- rabbitmqadmin list queues |
| 58 | +echo |
| 59 | +echo "Listing all queues in RabbitMQ cluster 'cluster-b'..." |
| 60 | +kubectl exec cluster-b-server-0 -c rabbitmq -- rabbitmqadmin list queues |
| 61 | + |
| 62 | +# Update the Messaging Topology operator deployment to restore correct Vault role identifier before continuing |
| 63 | +echo |
| 64 | +echo "Updating Messaging Topology operator to repair Vault authentication configuration..." |
| 65 | +kubectl set env deployment/messaging-topology-operator -n rabbitmq-system --containers='manager' OPERATOR_VAULT_ROLE=messaging-topology-operator |
| 66 | +kubectl wait --for=condition=Available deployment/messaging-topology-operator -n rabbitmq-system |
| 67 | +sleep 30 |
| 68 | + |
| 69 | +echo |
| 70 | +echo "Deleting queues from clusters..." |
| 71 | +kubectl delete -f rabbitmq-queue-c.yaml |
| 72 | +kubectl delete -f rabbitmq-queue-d.yaml |
| 73 | +sleep 10 |
| 74 | + |
| 75 | +echo |
| 76 | +echo "Deleting RabbitMQ clusters..." |
| 77 | +kubectl delete -f rabbitmq-clusters.yaml |
| 78 | +sleep 10 |
| 79 | +kubectl wait --for=delete pod/cluster-vault-a-server-0 |
| 80 | +kubectl wait --for=delete pod/cluster-b-server-0 |
| 81 | + |
| 82 | +echo |
| 83 | +echo "Removing Vault env vars from Messaging Topology operator deployment..." |
| 84 | +kubectl set env deployment/messaging-topology-operator -n rabbitmq-system --containers='manager' OPERATOR_VAULT_ROLE- VAULT_ADDR- |
| 85 | +kubectl wait --for=condition=Available deployment/messaging-topology-operator -n rabbitmq-system |
| 86 | +sleep 20 |
| 87 | + |
| 88 | +echo |
| 89 | +echo "Deleting Vault..." |
| 90 | +helm uninstall vault |
| 91 | +sleep 10 |
| 92 | +kubectl wait --for=delete pod/vault-0 |
0 commit comments