Skip to content

Commit 1eae840

Browse files
author
a.b.christie
committed
feat: Initial rabbitmq cluster operator changes
1 parent 54dbe05 commit 1eae840

File tree

10 files changed

+30
-317
lines changed

10 files changed

+30
-317
lines changed

roles/infrastructure/defaults/main.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ rabbitmq_cert_issuer: production
122122
rabbitmq_user: admin
123123
rabbitmq_user_password: "{{ lookup('password', '/dev/null length=12 chars=ascii_letters') }}"
124124

125+
rabbitmq_replicas: 1
126+
125127
rabbitmq_vol_storageclass: " "
126128
rabbitmq_vol_size_g: 1
127-
rabbitmq_log_vol_storageclass: " "
128-
rabbitmq_log_vol_size_g: 1

roles/infrastructure/tasks/deploy-rabbitmq.yaml

Lines changed: 3 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -16,40 +16,6 @@
1616
ansible.builtin.assert:
1717
that: n_result.resources | length == 1
1818

19-
# Secrets (RabbitMQ) ----------------------------------------------------------
20-
21-
- name: Create RabbitMQ Secret
22-
when: rabbitmq_state|string == 'present'
23-
block:
24-
25-
- name: Check RabbitMQ secrets
26-
kubernetes.core.k8s_info:
27-
kind: Secret
28-
api_version: v1
29-
namespace: "{{ infra_namespace }}"
30-
name: im-rabbitmq
31-
register: rmq_s_result
32-
33-
- name: Set RabbitMQ secret facts
34-
ansible.builtin.set_fact:
35-
rabbitmq_user_fact: "{{ rabbitmq_user }}"
36-
rabbitmq_user_password_fact: "{{ rabbitmq_user_password }}"
37-
rabbitmq_erlang_cookie_fact: "{{ rabbitmq_erlang_cookie }}"
38-
when: rmq_s_result.resources | length == 0
39-
40-
- name: Set RabbitMQ secret facts (pre-deployed secrets)
41-
ansible.builtin.set_fact:
42-
rabbitmq_user_fact: "{{ rmq_s_result.resources[0].data.user | b64decode }}"
43-
rabbitmq_user_password_fact: "{{ rmq_s_result.resources[0].data.password | b64decode }}"
44-
rabbitmq_erlang_cookie_fact: "{{ rmq_s_result.resources[0].data.erlang_cookie | b64decode }}"
45-
when: rmq_s_result.resources | length == 1
46-
47-
- name: Write RabbitMQ secrets
48-
kubernetes.core.k8s:
49-
definition: "{{ lookup('template', 'secret-rabbitmq.yaml.j2') }}"
50-
wait: yes
51-
when: rmq_s_result.resources | length == 0
52-
5319
# RabbitMQ --------------------------------------------------------------------
5420

5521
- name: Deploy RabbitMQ
@@ -60,68 +26,25 @@
6026
that:
6127
- kc_cert_issuer in cert_issuer_set
6228

63-
- name: Get {{ rabbitmq_vol_storageclass }} StorageClass
64-
kubernetes.core.k8s_info:
65-
kind: StorageClass
66-
name: "{{ rabbitmq_vol_storageclass }}"
67-
register: sc_result
68-
when: rabbitmq_vol_storageclass != " "
69-
70-
- name: Assert {{ pg_vol_storageclass }} StorageClass
71-
ansible.builtin.assert:
72-
that: sc_result.resources | length == 1
73-
fail_msg: The {{ rabbitmq_vol_storageclass }} StorageClass must be available on the cluster
74-
when: rabbitmq_vol_storageclass != " "
75-
76-
- name: Create RabbitMQ volume claims
77-
kubernetes.core.k8s:
78-
definition: "{{ lookup('template', item) }}"
79-
wait: yes
80-
wait_timeout: "{{ wait_timeout }}"
81-
loop:
82-
- pvc-rabbitmq-data.yaml.j2
83-
- pvc-rabbitmq-log.yaml.j2
84-
85-
# Best practice ... wait for the PVC to bind.
86-
# e.g. wait until resources[0].status.phase == Bound (initially Pending)
87-
88-
- name: Wait for RabbitMQ volume claim to bind
89-
kubernetes.core.k8s_info:
90-
kind: PersistentVolumeClaim
91-
name: rabbitmq-data
92-
namespace: "{{ infra_namespace }}"
93-
register: rabbitmq_pvc_result
94-
until: >-
95-
rabbitmq_pvc_result.resources | length > 0
96-
and rabbitmq_pvc_result.resources[0].status is defined
97-
and rabbitmq_pvc_result.resources[0].status.phase is defined
98-
and rabbitmq_pvc_result.resources[0].status.phase == 'Bound'
99-
delay: 5
100-
retries: "{{ (bind_timeout | int / 5) | int }}"
101-
when: wait_for_bind | bool
102-
10329
- name: RabbitMQ
10430
kubernetes.core.k8s:
10531
definition: "{{ lookup('template', item) }}"
10632
wait: yes
10733
wait_timeout: "{{ wait_timeout }}"
10834
loop:
109-
- configmap-rabbitmq-conf.yaml.j2
110-
- configmap-rabbitmq-plugins.yaml.j2
111-
- service-rabbitmq.yaml.j2
112-
- statefulset-rabbitmq.yaml.j2
35+
- rabbitmqcluster.yaml.j2
11336

11437
- name: Wait for RabbitMQ to become Ready ({{ wait_timeout }} seconds)
11538
kubernetes.core.k8s_info:
11639
kind: Pod
117-
name: rabbitmq-0
40+
name: "{{ infra_namespace }}-server-0"
11841
namespace: "{{ infra_namespace }}"
11942
register: rabbitmq_result
12043
until: >-
12144
rabbitmq_result.resources | length == 1
12245
and rabbitmq_result.resources[0].status is defined
12346
and rabbitmq_result.resources[0].status.containerStatuses is defined
124-
and rabbitmq_result.resources[0].status.containerStatuses | length == 1
47+
and rabbitmq_result.resources[0].status.containerStatuses | length > 0
12548
and rabbitmq_result.resources[0].status.containerStatuses[0].ready
12649
delay: 30
12750
retries: "{{ (wait_timeout | int / 30) | int }}"

roles/infrastructure/templates/configmap-rabbitmq-conf.yaml.j2

Lines changed: 0 additions & 18 deletions
This file was deleted.

roles/infrastructure/templates/configmap-rabbitmq-plugins.yaml.j2

Lines changed: 0 additions & 9 deletions
This file was deleted.

roles/infrastructure/templates/pvc-rabbitmq-data.yaml.j2

Lines changed: 0 additions & 15 deletions
This file was deleted.

roles/infrastructure/templates/pvc-rabbitmq-log.yaml.j2

Lines changed: 0 additions & 15 deletions
This file was deleted.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
apiVersion: rabbitmq.com/v1beta1
3+
kind: RabbitmqCluster
4+
metadata:
5+
name: {{ infra_namespace }}
6+
namespace: {{ infra_namespace }}
7+
spec:
8+
replicas: {{ rabbitmq_replicas }}
9+
rabbitmq:
10+
additionalPlugins:
11+
- rabbitmq_management
12+
- rabbitmq_peer_discovery_k8s
13+
- rabbitmq_prometheus
14+
- rabbitmq_stream
15+
- rabbitmq_stream_management
16+
resources:
17+
requests:
18+
cpu: {{ rabbitmq_cpu_request }}
19+
memory: {{ rabbitmq_mem_request }}
20+
limits:
21+
cpu: {{ rabbitmq_cpu_limit }}
22+
memory: {{ rabbitmq_mem_limit }}
23+
persistence:
24+
storageClassName: {{ rabbitmq_vol_storageclass }}
25+
storage: {{ rabbitmq_vol_size_g }}Gi

roles/infrastructure/templates/service-rabbitmq.yaml.j2

Lines changed: 0 additions & 25 deletions
This file was deleted.

roles/infrastructure/templates/statefulset-rabbitmq.yaml.j2

Lines changed: 0 additions & 146 deletions
This file was deleted.

roles/infrastructure/vars/main.yaml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,6 @@ kc_mem_limit: 1Gi
8181

8282
# RabbitMQ --------------------------------------------------------------------
8383

84-
# The RabbitMQ image, version and image registry
85-
rabbitmq_image: rabbitmq
86-
rabbitmq_version: 3.12.14-management-alpine
87-
rabbitmq_registry: ""
88-
89-
rabbitmq_erlang_cookie: "{{ lookup('password', '/dev/null length=80 chars=ascii_letters') }}"
90-
9184
# CPU and Memory requests and limits
9285
rabbitmq_cpu_request: 4
9386
rabbitmq_cpu_limit: 4

0 commit comments

Comments
 (0)