From 87b57b8ac8dcb66da4ad1735925a4f39d852b6e8 Mon Sep 17 00:00:00 2001 From: Tal Shor Date: Wed, 2 Aug 2023 16:02:28 +0300 Subject: [PATCH] prevent deletion init --- .../serviceinstance_controller_test.go | 3 +-- controllers/suite_test.go | 26 ++++++++++--------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/controllers/serviceinstance_controller_test.go b/controllers/serviceinstance_controller_test.go index d253acda..9c4dffe2 100644 --- a/controllers/serviceinstance_controller_test.go +++ b/controllers/serviceinstance_controller_test.go @@ -54,7 +54,6 @@ var _ = Describe("ServiceInstance controller", func() { instanceSpec := v1.ServiceInstanceSpec{ ExternalName: fakeInstanceExternalName, - PreventDeletion: true, ServicePlanName: fakePlanName, ServiceOfferingName: fakeOfferingName, Parameters: &runtime.RawExtension{ @@ -625,7 +624,7 @@ var _ = Describe("ServiceInstance controller", func() { BeforeEach(func() { fakeClient.DeprovisionReturns("", nil) }) - FIt("should delete the k8s instance", func() { + It("should delete the k8s instance", func() { deleteInstance(ctx, serviceInstance, true) }) }) diff --git a/controllers/suite_test.go b/controllers/suite_test.go index e838e0dc..e1aabb50 100644 --- a/controllers/suite_test.go +++ b/controllers/suite_test.go @@ -19,15 +19,16 @@ package controllers import ( "context" "crypto/tls" + "github.com/SAP/sap-btp-service-operator/api/v1/webhooks" "net" "path/filepath" + "sigs.k8s.io/controller-runtime/pkg/webhook" + "sigs.k8s.io/controller-runtime/pkg/webhook/admission" "testing" "time" - "sigs.k8s.io/controller-runtime/pkg/webhook/admission" - + "fmt" "github.com/SAP/sap-btp-service-operator/api" - "github.com/SAP/sap-btp-service-operator/api/v1/webhooks" "github.com/SAP/sap-btp-service-operator/client/sm" "github.com/SAP/sap-btp-service-operator/client/sm/smfakes" "github.com/SAP/sap-btp-service-operator/internal/config" @@ -35,9 +36,6 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" logf "sigs.k8s.io/controller-runtime/pkg/log" "sigs.k8s.io/controller-runtime/pkg/log/zap" - "sigs.k8s.io/controller-runtime/pkg/webhook" - - "fmt" ctrl "sigs.k8s.io/controller-runtime" @@ -113,6 +111,16 @@ var _ = BeforeSuite(func(done Done) { testConfig := config.Get() testConfig.SyncPeriod = syncPeriod testConfig.PollInterval = pollInterval + + k8sManager.GetWebhookServer().Register("/mutate-services-cloud-sap-com-v1-serviceinstance", &webhook.Admission{Handler: &webhooks.ServiceInstanceDefaulter{Decoder: admission.NewDecoder(k8sManager.GetScheme())}}) + k8sManager.GetWebhookServer().Register("/mutate-services-cloud-sap-com-v1-servicebinding", &webhook.Admission{Handler: &webhooks.ServiceBindingDefaulter{Decoder: admission.NewDecoder(k8sManager.GetScheme())}}) + + err = (&servicesv1.ServiceBinding{}).SetupWebhookWithManager(k8sManager) + Expect(err).ToNot(HaveOccurred()) + + err = (&servicesv1.ServiceInstance{}).SetupWebhookWithManager(k8sManager) + Expect(err).ToNot(HaveOccurred()) + err = (&ServiceInstanceReconciler{ BaseReconciler: &BaseReconciler{ Client: k8sManager.GetClient(), @@ -125,12 +133,6 @@ var _ = BeforeSuite(func(done Done) { }).SetupWithManager(k8sManager) Expect(err).ToNot(HaveOccurred()) - k8sManager.GetWebhookServer().Register("/mutate-services-cloud-sap-com-v1-serviceinstance", &webhook.Admission{Handler: &webhooks.ServiceInstanceDefaulter{Decoder: admission.NewDecoder(k8sManager.GetScheme())}}) - k8sManager.GetWebhookServer().Register("/mutate-services-cloud-sap-com-v1-servicebinding", &webhook.Admission{Handler: &webhooks.ServiceBindingDefaulter{Decoder: admission.NewDecoder(k8sManager.GetScheme())}}) - - err = (&servicesv1.ServiceBinding{}).SetupWebhookWithManager(k8sManager) - Expect(err).ToNot(HaveOccurred()) - err = (&ServiceBindingReconciler{ BaseReconciler: &BaseReconciler{ Client: k8sManager.GetClient(),