Skip to content

Commit ca8f6cf

Browse files
authored
Merge pull request #1 from InformaticsMatters/rabbitmq-cluster-operator-changes
Rabbitmq cluster operator changes
2 parents 54dbe05 + 0ef412e commit ca8f6cf

12 files changed

+64
-327
lines changed

.yamllint

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,9 @@ ignore: |
4040
roles/infrastructure/templates/cronjob-postgres-backup-weekly.yaml.j2
4141
roles/infrastructure/templates/pvc-postgres.yaml.j2
4242
roles/infrastructure/templates/pvc-postgres-backup.yaml.j2
43-
roles/infrastructure/templates/pvc-rabbitmq-data.yaml.j2
44-
roles/infrastructure/templates/pvc-rabbitmq-log.yaml.j2
4543
roles/infrastructure/templates/serviceaccount-im-infra.yaml.j2
4644
roles/infrastructure/templates/statefulset-keycloak.yaml.j2
4745
roles/infrastructure/templates/statefulset-postgres.yaml.j2
48-
roles/infrastructure/templates/statefulset-rabbitmq.yaml.j2
46+
roles/infrastructure/templates/rabbitmqcluster.yaml.j2
4947
roles/infrastructure/templates/ingress-keycloak.yaml.j2
5048
provisioning/ingress-controller/ingress-nginx-2.9.1.yaml

roles/infrastructure/defaults/main.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ kc_admin_password: "{{ lookup('password', '/dev/null length=12 chars=ascii_lette
109109
# the Keycloak DB is (at the moment) part of the core database installation.
110110
rabbitmq_state: present
111111

112+
# The RabbitMQ management server version to deploy,
113+
# the version will have '-management' automatically applied as a postfix.
114+
rabbitmq_version: 4.2.1
115+
112116
# The hostname of the server that will host Keycloak,
113117
# devoid of the protocol (i.e. 'https://' assumed so just 'example.com').
114118
# If not set (blank) no ingress is created.
@@ -122,7 +126,7 @@ rabbitmq_cert_issuer: production
122126
rabbitmq_user: admin
123127
rabbitmq_user_password: "{{ lookup('password', '/dev/null length=12 chars=ascii_letters') }}"
124128

129+
rabbitmq_replicas: 2
130+
125131
rabbitmq_vol_storageclass: " "
126132
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: 4 additions & 81 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: rabbit-server-0
11841
namespace: "{{ infra_namespace }}"
11942
register: rabbitmq_result
12043
until: >-
121-
rabbitmq_result.resources | length == 1
44+
rabbitmq_result.resources | length > 0
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/ingress-rabbitmq.yaml.j2

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ spec:
2020
pathType: Prefix
2121
backend:
2222
service:
23-
name: rabbitmq
23+
name: rabbit
2424
port:
25-
name: http
25+
name: management

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: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
apiVersion: rabbitmq.com/v1beta1
3+
kind: RabbitmqCluster
4+
metadata:
5+
# The instance name can be called pretty-much anything...
6+
# except rabbitmq!?
7+
name: rabbit
8+
namespace: {{ infra_namespace }}
9+
spec:
10+
image: rabbitmq:{{ rabbitmq_version }}-management
11+
replicas: {{ rabbitmq_replicas }}
12+
rabbitmq:
13+
additionalPlugins:
14+
- rabbitmq_management
15+
- rabbitmq_peer_discovery_k8s
16+
- rabbitmq_prometheus
17+
- rabbitmq_stream
18+
- rabbitmq_stream_management
19+
resources:
20+
{% if rabbitmq_cpu_request or rabbitmq_mem_request %}
21+
requests:
22+
{% if rabbitmq_cpu_request %}
23+
cpu: {{ rabbitmq_cpu_request }}
24+
{% endif %}
25+
{% if rabbitmq_mem_request %}
26+
memory: {{ rabbitmq_mem_request }}
27+
{% endif %}
28+
{% endif %}
29+
{% if rabbitmq_cpu_limit or rabbitmq_mem_limit %}
30+
limits:
31+
{% if rabbitmq_cpu_limit %}
32+
cpu: {{ rabbitmq_cpu_limit }}
33+
{% endif %}
34+
{% if rabbitmq_mem_limit %}
35+
memory: {{ rabbitmq_mem_limit }}
36+
{% endif %}
37+
{% endif %}
38+
persistence:
39+
storageClassName: {{ rabbitmq_vol_storageclass }}
40+
storage: {{ rabbitmq_vol_size_g }}Gi
41+
override:
42+
statefulSet:
43+
spec:
44+
template:
45+
spec:
46+
containers: []
47+
priorityClassName: im-application-high

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

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

0 commit comments

Comments
 (0)