Skip to content
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
5 changes: 5 additions & 0 deletions api/v1beta1/queue_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
6 changes: 6 additions & 0 deletions api/v1beta1/queue_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down