diff --git a/api/v1alpha1/binding_webhook_test.go b/api/v1alpha1/binding_webhook_test.go index d739a3c5..e4b85f89 100644 --- a/api/v1alpha1/binding_webhook_test.go +++ b/api/v1alpha1/binding_webhook_test.go @@ -15,6 +15,7 @@ var _ = Describe("Binding webhook", func() { Name: "update-binding", }, Spec: BindingSpec{ + Vhost: "/test", Source: "test", Destination: "test", DestinationType: "queue", @@ -25,114 +26,47 @@ var _ = Describe("Binding webhook", func() { }, } + It("does not allow updates on vhost", func() { + newBinding := oldBinding.DeepCopy() + newBinding.Spec.Vhost = "/new-vhost" + Expect(apierrors.IsForbidden(newBinding.ValidateUpdate(&oldBinding))).To(BeTrue()) + }) + It("does not allow updates on source", func() { - newBinding := Binding{ - ObjectMeta: metav1.ObjectMeta{ - Name: "update-binding", - }, - Spec: BindingSpec{ - Source: "updated-source", - Destination: "test", - DestinationType: "queue", - RabbitmqClusterReference: RabbitmqClusterReference{ - Name: "some-cluster", - Namespace: "default", - }, - }, - } + newBinding := oldBinding.DeepCopy() + newBinding.Spec.Source = "updated-source" Expect(apierrors.IsForbidden(newBinding.ValidateUpdate(&oldBinding))).To(BeTrue()) }) It("does not allow updates on destination", func() { - newBinding := Binding{ - ObjectMeta: metav1.ObjectMeta{ - Name: "update-binding", - }, - Spec: BindingSpec{ - Source: "test", - Destination: "updated-des", - DestinationType: "queue", - RabbitmqClusterReference: RabbitmqClusterReference{ - Name: "some-cluster", - Namespace: "default", - }, - }, - } + newBinding := oldBinding.DeepCopy() + newBinding.Spec.Destination = "updated-des" Expect(apierrors.IsForbidden(newBinding.ValidateUpdate(&oldBinding))).To(BeTrue()) }) It("does not allow updates on destination type", func() { - newBinding := Binding{ - ObjectMeta: metav1.ObjectMeta{ - Name: "update-binding", - }, - Spec: BindingSpec{ - Source: "test", - Destination: "test", - DestinationType: "exchange", - RabbitmqClusterReference: RabbitmqClusterReference{ - Name: "some-cluster", - Namespace: "default", - }, - }, - } + newBinding := oldBinding.DeepCopy() + newBinding.Spec.DestinationType = "exchange" Expect(apierrors.IsForbidden(newBinding.ValidateUpdate(&oldBinding))).To(BeTrue()) }) It("does not allow updates on routing key", func() { - newBinding := Binding{ - ObjectMeta: metav1.ObjectMeta{ - Name: "update-binding", - }, - Spec: BindingSpec{ - Source: "test", - Destination: "test", - DestinationType: "queue", - RoutingKey: "not-allowed", - RabbitmqClusterReference: RabbitmqClusterReference{ - Name: "some-cluster", - Namespace: "default", - }, - }, - } + newBinding := oldBinding.DeepCopy() + newBinding.Spec.RoutingKey = "not-allowed" Expect(apierrors.IsForbidden(newBinding.ValidateUpdate(&oldBinding))).To(BeTrue()) }) It("does not allow updates on binding arguments", func() { - newBinding := Binding{ - ObjectMeta: metav1.ObjectMeta{ - Name: "update-binding", - }, - Spec: BindingSpec{ - Source: "test", - Destination: "test", - DestinationType: "queue", - Arguments: &runtime.RawExtension{ - Raw: []byte(`{"new":"new-value"}`), - }, - RabbitmqClusterReference: RabbitmqClusterReference{ - Name: "some-cluster", - Namespace: "default", - }, - }, - } + newBinding := oldBinding.DeepCopy() + newBinding.Spec.Arguments = &runtime.RawExtension{Raw: []byte(`{"new":"new-value"}`)} Expect(apierrors.IsForbidden(newBinding.ValidateUpdate(&oldBinding))).To(BeTrue()) }) It("does not allow updates on RabbitmqClusterReference", func() { - newBinding := Binding{ - ObjectMeta: metav1.ObjectMeta{ - Name: "update-binding", - }, - Spec: BindingSpec{ - Source: "test", - Destination: "test", - DestinationType: "queue", - RabbitmqClusterReference: RabbitmqClusterReference{ - Name: "new-cluster", - Namespace: "default", - }, - }, + newBinding := oldBinding.DeepCopy() + newBinding.Spec.RabbitmqClusterReference = RabbitmqClusterReference{ + Name: "new-cluster", + Namespace: "default", } Expect(apierrors.IsForbidden(newBinding.ValidateUpdate(&oldBinding))).To(BeTrue()) }) diff --git a/main.go b/main.go index 38adbe56..68fad4e2 100644 --- a/main.go +++ b/main.go @@ -44,7 +44,6 @@ func init() { _ = rabbitmqv1beta1.AddToScheme(scheme) _ = topologyv1alpha1.AddToScheme(scheme) - _ = rabbitmqcomv1alpha1.AddToScheme(scheme) // +kubebuilder:scaffold:scheme } diff --git a/system_tests/utils.go b/system_tests/utils.go index 71a8f435..27a5cb89 100644 --- a/system_tests/utils.go +++ b/system_tests/utils.go @@ -16,8 +16,8 @@ import ( rabbitmqv1beta1 "github.com/rabbitmq/cluster-operator/api/v1beta1" "github.com/rabbitmq/messaging-topology-operator/api/v1alpha1" corev1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/api/resource" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/kubernetes" "k8s.io/client-go/rest" "k8s.io/client-go/tools/clientcmd"