From bd19ef3c924f34232acf19206c3de62f4ed0f897 Mon Sep 17 00:00:00 2001 From: Dimitar Draganov Date: Thu, 9 Jan 2025 13:35:12 +0200 Subject: [PATCH] Added key type filter in managed controller --- api/payloads/service_binding.go | 1 + api/payloads/service_binding_test.go | 2 +- .../service_binding_repository_test.go | 1 + .../api/v1alpha1/cfservicebinding_types.go | 5 ++--- .../services/bindings/controller_test.go | 17 +++++++++++++++++ .../services/bindings/managed/controller.go | 4 ++++ .../services/bindings/sbio/servicebinding.go | 6 +++--- .../bindings/sbio/servicebinding_test.go | 6 +++--- .../webhooks/relationships/webhook_test.go | 3 +++ tests/assets/sample-broker-golang/main.go | 3 +-- 10 files changed, 36 insertions(+), 12 deletions(-) diff --git a/api/payloads/service_binding.go b/api/payloads/service_binding.go index 767e9de2b..8899e3629 100644 --- a/api/payloads/service_binding.go +++ b/api/payloads/service_binding.go @@ -90,6 +90,7 @@ func (l *ServiceBindingList) ToMessage() repositories.ListServiceBindingsMessage AppGUIDs: parse.ArrayParam(l.AppGUIDs), LabelSelector: l.LabelSelector, PlanGUIDs: parse.ArrayParam(l.PlanGUIDs), + Type: &l.Type, } } diff --git a/api/payloads/service_binding_test.go b/api/payloads/service_binding_test.go index 701f634ea..066e325de 100644 --- a/api/payloads/service_binding_test.go +++ b/api/payloads/service_binding_test.go @@ -25,7 +25,7 @@ var _ = Describe("ServiceBindingList", func() { Entry("app_guids", "app_guids=app_guid", payloads.ServiceBindingList{AppGUIDs: "app_guid"}), Entry("service_instance_guids", "service_instance_guids=si_guid", payloads.ServiceBindingList{ServiceInstanceGUIDs: "si_guid"}), Entry("include", "include=app", payloads.ServiceBindingList{Include: "app"}), - Entry("include", "include=key", payloads.ServiceBindingList{Include: "key"}), + Entry("include", "include=service_instance", payloads.ServiceBindingList{Include: "service_instance"}), Entry("label_selector=foo", "label_selector=foo", payloads.ServiceBindingList{LabelSelector: "foo"}), Entry("service_plan_guids=plan-guid", "service_plan_guids=plan-guid", payloads.ServiceBindingList{PlanGUIDs: "plan-guid"}), ) diff --git a/api/repositories/service_binding_repository_test.go b/api/repositories/service_binding_repository_test.go index fbad8ccc7..f5ab0e653 100644 --- a/api/repositories/service_binding_repository_test.go +++ b/api/repositories/service_binding_repository_test.go @@ -800,6 +800,7 @@ var _ = Describe("ServiceBindingRepo", func() { Namespace: space2.Name, Labels: map[string]string{ korifiv1alpha1.PlanGUIDLabelKey: "plan-4", + korifiv1alpha1.SpaceGUIDKey: space.Name, }, }, Spec: korifiv1alpha1.CFServiceBindingSpec{ diff --git a/controllers/api/v1alpha1/cfservicebinding_types.go b/controllers/api/v1alpha1/cfservicebinding_types.go index b092e8460..abb36c838 100644 --- a/controllers/api/v1alpha1/cfservicebinding_types.go +++ b/controllers/api/v1alpha1/cfservicebinding_types.go @@ -34,9 +34,8 @@ const ( ServiceInstanceTypeAnnotationKey = "korifi.cloudfoundry.org/service-instance-type" PlanGUIDLabelKey = "korifi.cloudfoundry.org/plan-guid" - ServiceBindingGUIDLabel = "korifi.cloudfoundry.org/service-binding-guid" - ServiceCredentialBindingTypeLabel = "korifi.cloudfoundry.org/service-credential-binding-type" - CFServiceBindingFinalizerName = "cfServiceBinding.korifi.cloudfoundry.org" + ServiceBindingGUIDLabel = "korifi.cloudfoundry.org/service-binding-guid" + CFServiceBindingFinalizerName = "cfServiceBinding.korifi.cloudfoundry.org" ) // CFServiceBindingSpec defines the desired state of CFServiceBinding diff --git a/controllers/controllers/services/bindings/controller_test.go b/controllers/controllers/services/bindings/controller_test.go index c25b2302d..fb3499ca5 100644 --- a/controllers/controllers/services/bindings/controller_test.go +++ b/controllers/controllers/services/bindings/controller_test.go @@ -679,6 +679,23 @@ var _ = Describe("CFServiceBinding", func() { }).Should(Succeed()) }) + When("binding is of type key", func() { + BeforeEach(func() { + Expect(k8s.Patch(ctx, adminClient, binding, func() { + binding.Spec.Type = korifiv1alpha1.CFServiceBindingTypeKey + })).To(Succeed()) + }) + + It("does not create servicebinding.io", func() { + Consistently(func(g Gomega) { + sbList := &servicebindingv1beta1.ServiceBindingList{} + err := adminClient.List(ctx, sbList, client.InNamespace(testNamespace)) + g.Expect(err).NotTo(HaveOccurred()) + g.Expect(sbList.Items).To(BeEmpty()) + }).Should(Succeed()) + }) + }) + When("the credentials contain type key", func() { BeforeEach(func() { brokerClient.BindReturns(osbapi.BindResponse{ diff --git a/controllers/controllers/services/bindings/managed/controller.go b/controllers/controllers/services/bindings/managed/controller.go index 1300dec35..6a3407c64 100644 --- a/controllers/controllers/services/bindings/managed/controller.go +++ b/controllers/controllers/services/bindings/managed/controller.go @@ -89,6 +89,10 @@ func (r *ManagedBindingsReconciler) ReconcileResource(ctx context.Context, cfSer return ctrl.Result{}, err } + if cfServiceBinding.Spec.Type == korifiv1alpha1.CFServiceBindingTypeKey { + return ctrl.Result{}, nil + } + sbServiceBinding, err := r.reconcileSBServiceBinding(ctx, cfServiceBinding) if err != nil { log.Info("error creating/updating servicebinding.io servicebinding", "reason", err) diff --git a/controllers/controllers/services/bindings/sbio/servicebinding.go b/controllers/controllers/services/bindings/sbio/servicebinding.go index cdff4a669..dc373abdb 100644 --- a/controllers/controllers/services/bindings/sbio/servicebinding.go +++ b/controllers/controllers/services/bindings/sbio/servicebinding.go @@ -16,9 +16,9 @@ func ToSBServiceBinding(cfServiceBinding *korifiv1alpha1.CFServiceBinding, bindi Name: fmt.Sprintf("cf-binding-%s", cfServiceBinding.Name), Namespace: cfServiceBinding.Namespace, Labels: map[string]string{ - korifiv1alpha1.ServiceBindingGUIDLabel: cfServiceBinding.Name, - korifiv1alpha1.CFAppGUIDLabelKey: cfServiceBinding.Spec.AppRef.Name, - korifiv1alpha1.ServiceCredentialBindingTypeLabel: "app", + korifiv1alpha1.ServiceBindingGUIDLabel: cfServiceBinding.Name, + korifiv1alpha1.CFAppGUIDLabelKey: cfServiceBinding.Spec.AppRef.Name, + korifiv1alpha1.ServiceBindingTypeLabel: "app", }, }, Spec: servicebindingv1beta1.ServiceBindingSpec{ diff --git a/controllers/controllers/services/bindings/sbio/servicebinding_test.go b/controllers/controllers/services/bindings/sbio/servicebinding_test.go index edaf15d8c..58325b0ed 100644 --- a/controllers/controllers/services/bindings/sbio/servicebinding_test.go +++ b/controllers/controllers/services/bindings/sbio/servicebinding_test.go @@ -62,9 +62,9 @@ var _ = Describe("SBIO", func() { Name: "cf-binding-cf-binding", Namespace: cfServiceBinding.Namespace, Labels: map[string]string{ - korifiv1alpha1.ServiceBindingGUIDLabel: bindingName, - korifiv1alpha1.CFAppGUIDLabelKey: cfServiceBinding.Spec.AppRef.Name, - korifiv1alpha1.ServiceCredentialBindingTypeLabel: "app", + korifiv1alpha1.ServiceBindingGUIDLabel: bindingName, + korifiv1alpha1.CFAppGUIDLabelKey: cfServiceBinding.Spec.AppRef.Name, + korifiv1alpha1.ServiceBindingTypeLabel: "app", }, }, Spec: servicebindingv1beta1.ServiceBindingSpec{ diff --git a/controllers/webhooks/relationships/webhook_test.go b/controllers/webhooks/relationships/webhook_test.go index 1b71fbeef..f6bcb86ba 100644 --- a/controllers/webhooks/relationships/webhook_test.go +++ b/controllers/webhooks/relationships/webhook_test.go @@ -83,6 +83,9 @@ var _ = Describe("Setting the space-guid label", func() { Namespace: spaceNamespace, Name: uuid.NewString(), }, + Spec: korifiv1alpha1.CFServiceBindingSpec{ + Type: "app", + }, }, &korifiv1alpha1.CFServiceInstance{ ObjectMeta: metav1.ObjectMeta{ diff --git a/tests/assets/sample-broker-golang/main.go b/tests/assets/sample-broker-golang/main.go index 10b0aad0d..9799e0031 100644 --- a/tests/assets/sample-broker-golang/main.go +++ b/tests/assets/sample-broker-golang/main.go @@ -7,9 +7,8 @@ import ( "fmt" "net/http" "os" - "strings" - "sample-broker/osbapi" + "strings" ) const (