Skip to content

Commit

Permalink
Register webhooks using the new API
Browse files Browse the repository at this point in the history
Signed-off-by: Aitor Perez Cedres <acedres@vmware.com>
  • Loading branch information
Zerpet committed Feb 6, 2024
1 parent 4f7cca7 commit 9fe0aec
Show file tree
Hide file tree
Showing 14 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ just-integration-tests: $(KUBEBUILDER_ASSETS) vet
local-tests: unit-tests integration-tests ## Run all local tests (unit & integration)

system-tests: ## run end-to-end tests against Kubernetes cluster defined in ~/.kube/config. Expects cluster operator and messaging topology operator to be installed in the cluster
NAMESPACE="rabbitmq-system" ginkgo --randomize-all -r system_tests/
NAMESPACE="rabbitmq-system" ginkgo --randomize-all -r $(GINKGO_EXTRA) system_tests/

# Build manager binary
manager: generate fmt vet vuln
Expand Down
1 change: 1 addition & 0 deletions api/v1beta1/binding_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

func (b *Binding) SetupWebhookWithManager(mgr ctrl.Manager) error {
return ctrl.NewWebhookManagedBy(mgr).
WithValidator(b).
For(b).
Complete()
}
Expand Down
1 change: 1 addition & 0 deletions api/v1beta1/exchange_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

func (e *Exchange) SetupWebhookWithManager(mgr ctrl.Manager) error {
return ctrl.NewWebhookManagedBy(mgr).
WithValidator(e).
For(e).
Complete()
}
Expand Down
1 change: 1 addition & 0 deletions api/v1beta1/federation_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

func (f *Federation) SetupWebhookWithManager(mgr ctrl.Manager) error {
return ctrl.NewWebhookManagedBy(mgr).
WithValidator(f).
For(f).
Complete()
}
Expand Down
1 change: 1 addition & 0 deletions api/v1beta1/operatorpolicy_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

func (p *OperatorPolicy) SetupWebhookWithManager(mgr ctrl.Manager) error {
return ctrl.NewWebhookManagedBy(mgr).
WithValidator(p).
For(p).
Complete()
}
Expand Down
1 change: 1 addition & 0 deletions api/v1beta1/permission_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

func (p *Permission) SetupWebhookWithManager(mgr ctrl.Manager) error {
return ctrl.NewWebhookManagedBy(mgr).
WithValidator(p).
For(p).
Complete()
}
Expand Down
1 change: 1 addition & 0 deletions api/v1beta1/policy_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

func (p *Policy) SetupWebhookWithManager(mgr ctrl.Manager) error {
return ctrl.NewWebhookManagedBy(mgr).
WithValidator(p).
For(p).
Complete()
}
Expand Down
1 change: 1 addition & 0 deletions api/v1beta1/queue_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

func (q *Queue) SetupWebhookWithManager(mgr ctrl.Manager) error {
return ctrl.NewWebhookManagedBy(mgr).
WithValidator(q).
For(q).
Complete()
}
Expand Down
1 change: 1 addition & 0 deletions api/v1beta1/schemareplication_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

func (s *SchemaReplication) SetupWebhookWithManager(mgr ctrl.Manager) error {
return ctrl.NewWebhookManagedBy(mgr).
WithValidator(s).
For(s).
Complete()
}
Expand Down
2 changes: 1 addition & 1 deletion api/v1beta1/shovel_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

func (s *Shovel) SetupWebhookWithManager(mgr ctrl.Manager) error {
return ctrl.NewWebhookManagedBy(mgr).
WithValidator(s).
For(s).
Complete()
}
Expand All @@ -37,7 +38,6 @@ func (s *Shovel) ValidateCreate(_ context.Context, obj runtime.Object) (warnings

// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
func (s *Shovel) ValidateUpdate(_ context.Context, oldObj, newObj runtime.Object) (warnings admission.Warnings, err error) {
//TODO implement me
oldShovel, ok := oldObj.(*Shovel)
if !ok {
return nil, apierrors.NewBadRequest(fmt.Sprintf("expected a shovel but got a %T", oldShovel))
Expand Down
7 changes: 4 additions & 3 deletions api/v1beta1/topicpermission_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

func (t *TopicPermission) SetupWebhookWithManager(mgr ctrl.Manager) error {
return ctrl.NewWebhookManagedBy(mgr).
WithValidator(t).
For(t).
Complete()
}
Expand All @@ -29,16 +30,16 @@ func (t *TopicPermission) ValidateCreate(_ context.Context, obj runtime.Object)
return nil, fmt.Errorf("expected a RabbitMQ permission but got a %T", obj)
}

if t.Spec.User == "" && t.Spec.UserReference == nil {
if tp.Spec.User == "" && tp.Spec.UserReference == nil {
return nil, field.Required(field.NewPath("spec", "user and userReference"),
"must specify either spec.user or spec.userReference")
}

if t.Spec.User != "" && t.Spec.UserReference != nil {
if tp.Spec.User != "" && tp.Spec.UserReference != nil {
return nil, field.Required(field.NewPath("spec", "user and userReference"),
"cannot specify spec.user and spec.userReference at the same time")
}
return nil, t.Spec.RabbitmqClusterReference.validate(tp.RabbitReference())
return nil, tp.Spec.RabbitmqClusterReference.validate(tp.RabbitReference())
}

// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
Expand Down
1 change: 1 addition & 0 deletions api/v1beta1/user_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

func (u *User) SetupWebhookWithManager(mgr ctrl.Manager) error {
return ctrl.NewWebhookManagedBy(mgr).
WithValidator(u).
For(u).
Complete()
}
Expand Down
1 change: 1 addition & 0 deletions api/v1beta1/vhost_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

func (v *Vhost) SetupWebhookWithManager(mgr ctrl.Manager) error {
return ctrl.NewWebhookManagedBy(mgr).
WithValidator(v).
For(v).
Complete()
}
Expand Down
2 changes: 1 addition & 1 deletion system_tests/binding_system_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ var _ = Describe("Binding", func() {
updateBinding := topology.Binding{}
Expect(k8sClient.Get(ctx, types.NamespacedName{Name: binding.Name, Namespace: binding.Namespace}, &updateBinding)).To(Succeed())
updatedBinding.Spec.RoutingKey = "new-key"
Expect(k8sClient.Update(ctx, &updatedBinding).Error()).To(ContainSubstring("invalid: spec.routingKey: Invalid value: \"new-key\": routingKey cannot be updated"))
Expect(k8sClient.Update(ctx, &updatedBinding).Error()).To(ContainSubstring("spec.routingKey: Invalid value: \"new-key\": routingKey cannot be updated"))

By("deleting binding from rabbitmq server")
Expect(k8sClient.Delete(ctx, binding)).To(Succeed())
Expand Down

0 comments on commit 9fe0aec

Please sign in to comment.