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

Example of importing from a ConfigMap and a Secret #1802

Merged
merged 1 commit into from
Jan 7, 2025
Merged
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
14 changes: 14 additions & 0 deletions docs/examples/import-multiple-definition-files/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Import Multiple Definition Files Example

RabbitMQ supports importing definitions from a folder with multiple JSON files.
In this example we take advantage of this feature to split the definitions into a ConfigMap
with most of the definitions and a Secret that contains user definitions only.

First, we need to create the ConfigMap and Secret with the definitions:
```bash
kubectl create configmap definitions --from-file='definitions.json=/my/path/to/definitions.json'
kubectl create secret generic users --from-file='definitions.json=/my/path/to/users.json'
```

Afterwards, we leverage the StatefulSet Override to mount these resources as files in a folder
and specify that folder as the defintion import path.
65 changes: 65 additions & 0 deletions docs/examples/import-multiple-definition-files/definitions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{
"permissions": [
{
"configure": ".*",
"read": ".*",
"user": "guest",
"vhost": "/",
"write": ".*"
}
],
"bindings": [
{
"arguments": {},
"destination": "qq",
"destination_type": "queue",
"routing_key": "3c01b232-e21a-4320-bbdb-329eede5188c",
"source": "direct",
"vhost": "/"
}
],
"queues": [
{
"arguments": {
"x-queue-type": "quorum"
},
"auto_delete": false,
"durable": true,
"name": "qq",
"type": "quorum",
"vhost": "/"
}
],
"parameters": [],
"policies": [],
"rabbitmq_version": "4.1.0+beta.3.47.gac7dcc9",
"rabbit_version": "4.1.0+beta.3.47.gac7dcc9",
"exchanges": [
{
"arguments": {},
"auto_delete": false,
"durable": true,
"name": "direct",
"type": "direct",
"vhost": "/"
}
],
"vhosts": [
{
"default_queue_type": "classic",
"limits": [],
"metadata": {
"description": "Default virtual host",
"tags": []
},
"name": "/"
}
],
"global_parameters": [
{
"name": "cluster_tags",
"value": []
}
],
"topic_permissions": []
}
33 changes: 33 additions & 0 deletions docs/examples/import-multiple-definition-files/rabbitmq.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
apiVersion: rabbitmq.com/v1beta1
kind: RabbitmqCluster
metadata:
name: import-multiple-definition-files
spec:
replicas: 1
override:
statefulSet:
spec:
template:
spec:
containers:
- name: rabbitmq
volumeMounts:
# 01- prefix is used to ensure that users are imported first
- mountPath: /etc/rabbitmq/definitions/01-users.json
name: users
subPath: users.json
# 02- prefix is used to ensure that definitions are imported after users, since
# they might reference users (eg. to set up permissions)
- mountPath: /etc/rabbitmq/definitions/02-definitions.json
name: definitions
subPath: definitions.json
volumes:
- name: users
secret:
secretName: users # Name of the Secret containing user definitions
- name: definitions
configMap:
name: definitions # Name of the ConfigMap containing other definitions
rabbitmq:
additionalConfig: |
load_definitions = /etc/rabbitmq/definitions # Path to the folder
4 changes: 4 additions & 0 deletions docs/examples/import-multiple-definition-files/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

kubectl create configmap definitions --from-file=definitions.json
kubectl create secret generic users --from-file=users.json
5 changes: 5 additions & 0 deletions docs/examples/import-multiple-definition-files/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

set -x

kubectl exec import-multiple-definition-files-server-0 -c rabbitmq -- rabbitmqctl authenticate_user guest guest
13 changes: 13 additions & 0 deletions docs/examples/import-multiple-definition-files/users.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"users": [
{
"hashing_algorithm": "rabbit_password_hashing_sha256",
"limits": {},
"name": "guest",
"password_hash": "KYBvEg5fU0m1sE8E6qNmjITswwixc9EMjxWcjiC5f/70vgmC",
"tags": [
"administrator"
]
}
]
}
Loading