diff --git a/api/v1beta1/queue_webhook.go b/api/v1beta1/queue_webhook.go index 6aec4915..35fd437a 100644 --- a/api/v1beta1/queue_webhook.go +++ b/api/v1beta1/queue_webhook.go @@ -22,6 +22,11 @@ var _ webhook.Validator = &Queue{} // ValidateCreate implements webhook.Validator so a webhook will be registered for the type // either rabbitmqClusterReference.name or rabbitmqClusterReference.connectionSecret must be provided but not both func (q *Queue) ValidateCreate() error { + if q.Spec.Type == "quorum" && q.Spec.Durable == false { + return apierrors.NewForbidden(q.GroupResource(), q.Name, + field.Forbidden(field.NewPath("spec", "durable"), + "Quorum queues must have durable set to true")) + } return q.Spec.RabbitmqClusterReference.ValidateOnCreate(q.GroupResource(), q.Name) } diff --git a/api/v1beta1/queue_webhook_test.go b/api/v1beta1/queue_webhook_test.go index d22e75c6..18957acd 100644 --- a/api/v1beta1/queue_webhook_test.go +++ b/api/v1beta1/queue_webhook_test.go @@ -39,6 +39,12 @@ var _ = Describe("queue webhook", func() { notAllowedQ.Spec.RabbitmqClusterReference.ConnectionSecret = nil Expect(apierrors.IsForbidden(notAllowedQ.ValidateCreate())).To(BeTrue()) }) + + It("does not allow non-durable quorum queues", func() { + notAllowedQ := queue.DeepCopy() + notAllowedQ.Spec.AutoDelete = false + Expect(apierrors.IsForbidden(notAllowedQ.ValidateCreate())).To(BeTrue(), "Expected 'forbidden' response for non-durable quorum queue") + }) }) Context("ValidateUpdate", func() {