Skip to content

Commit 4b49493

Browse files
Merge pull request #1611 from lmiccini/quorum2
Switch to quorumqueues only for new controlplane resources
2 parents 5dbbe06 + a37e732 commit 4b49493

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

apis/core/v1beta1/openstackcontrolplane_webhook.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,6 +1044,22 @@ func (r *OpenStackControlPlane) DefaultServices() {
10441044
r.Spec.Designate.Template.Default()
10451045
}
10461046

1047+
// RabbitMQ
1048+
if r.Spec.Rabbitmq.Enabled || r.Spec.Rabbitmq.Templates != nil {
1049+
if r.Spec.Rabbitmq.Templates == nil {
1050+
r.Spec.Rabbitmq.Templates = ptr.To(map[string]rabbitmqv1.RabbitMqSpecCore{})
1051+
}
1052+
1053+
for key, template := range *r.Spec.Rabbitmq.Templates {
1054+
// Enforce queueType=Quorum for all new resources, preserve existing resources unchanged
1055+
if r.ObjectMeta.CreationTimestamp.IsZero() {
1056+
template.QueueType = "Quorum"
1057+
}
1058+
// By-value copy, need to update
1059+
(*r.Spec.Rabbitmq.Templates)[key] = template
1060+
}
1061+
}
1062+
10471063
// Redis
10481064
if r.Spec.Redis.Enabled || r.Spec.Redis.Templates != nil {
10491065
if r.Spec.Redis.Templates == nil {

tests/functional/ctlplane/openstackoperator_controller_test.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2909,6 +2909,54 @@ var _ = Describe("OpenStackOperator Webhook", func() {
29092909
Expect(OSCtlplane.Labels).Should(HaveKeyWithValue("core.openstack.org/openstackcontrolplane", "foo"))
29102910
})
29112911

2912+
It("Enforces queueType=Quorum for new resources", func() {
2913+
spec := GetDefaultOpenStackControlPlaneSpec()
2914+
spec["tls"] = GetTLSPublicSpec()
2915+
2916+
DeferCleanup(
2917+
th.DeleteInstance,
2918+
CreateOpenStackControlPlane(types.NamespacedName{Name: "test-new-quorum", Namespace: namespace}, spec),
2919+
)
2920+
2921+
OSCtlplane := GetOpenStackControlPlane(types.NamespacedName{Name: "test-new-quorum", Namespace: namespace})
2922+
Expect(OSCtlplane.Spec.Rabbitmq.Templates).Should(Not(BeNil()))
2923+
2924+
// Verify that all templates get queueType=Quorum for new resources
2925+
for templateName, template := range *OSCtlplane.Spec.Rabbitmq.Templates {
2926+
Expect(template.QueueType).Should(Equal("Quorum"), "RabbitMQ template %s should have queueType=Quorum", templateName)
2927+
}
2928+
})
2929+
2930+
It("Preserves existing queueType values on updates", func() {
2931+
spec := GetDefaultOpenStackControlPlaneSpec()
2932+
spec["tls"] = GetTLSPublicSpec()
2933+
2934+
// Create a resource first (will get Quorum by default)
2935+
ctlplane := CreateOpenStackControlPlane(types.NamespacedName{Name: "test-preserve-existing", Namespace: namespace}, spec)
2936+
DeferCleanup(th.DeleteInstance, ctlplane)
2937+
2938+
// Manually set it to Mirrored to simulate existing deployment
2939+
Eventually(func(g Gomega) {
2940+
existingCtlplane := GetOpenStackControlPlane(types.NamespacedName{Name: "test-preserve-existing", Namespace: namespace})
2941+
(*existingCtlplane.Spec.Rabbitmq.Templates)["rabbitmq"] = rabbitmqv1.RabbitMqSpecCore{
2942+
QueueType: "Mirrored", // Simulate existing value
2943+
}
2944+
g.Expect(k8sClient.Update(ctx, existingCtlplane)).Should(Succeed())
2945+
}).Should(Succeed())
2946+
2947+
// Verify it's preserved on subsequent updates
2948+
Eventually(func(g Gomega) {
2949+
updatedCtlplane := GetOpenStackControlPlane(types.NamespacedName{Name: "test-preserve-existing", Namespace: namespace})
2950+
updatedCtlplane.Spec.Secret = "updated-secret" // Trigger webhook
2951+
g.Expect(k8sClient.Update(ctx, updatedCtlplane)).Should(Succeed())
2952+
2953+
// Should still be Mirrored after update
2954+
finalCtlplane := GetOpenStackControlPlane(types.NamespacedName{Name: "test-preserve-existing", Namespace: namespace})
2955+
rabbitTemplate := (*finalCtlplane.Spec.Rabbitmq.Templates)["rabbitmq"]
2956+
g.Expect(rabbitTemplate.QueueType).Should(Equal("Mirrored"), "Existing queueType should be preserved")
2957+
}).Should(Succeed())
2958+
})
2959+
29122960
It("calls placement validation webhook", func() {
29132961
spec := GetDefaultOpenStackControlPlaneSpec()
29142962
spec["tls"] = GetTLSPublicSpec()

0 commit comments

Comments
 (0)