Skip to content

Commit

Permalink
Added key type filter in managed controller
Browse files Browse the repository at this point in the history
  • Loading branch information
ddraganovv committed Jan 10, 2025
1 parent ae722ab commit 9874f7f
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 10 deletions.
1 change: 1 addition & 0 deletions api/payloads/service_binding.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

Expand Down
2 changes: 1 addition & 1 deletion api/payloads/service_binding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"}),
)
Expand Down
1 change: 1 addition & 0 deletions api/repositories/service_binding_repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
5 changes: 2 additions & 3 deletions controllers/api/v1alpha1/cfservicebinding_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions controllers/controllers/services/bindings/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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).To(BeNil())

Check failure on line 693 in controllers/controllers/services/bindings/controller_test.go

View workflow job for this annotation

GitHub Actions / linter

ginkgo-linter: wrong error assertion. Consider using `g.Expect(err).ToNot(HaveOccurred())` instead (ginkgolinter)
g.Expect(sbList.Items).To(BeEmpty())
}).Should(Succeed())
})
})

When("the credentials contain type key", func() {
BeforeEach(func() {
brokerClient.BindReturns(osbapi.BindResponse{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit 9874f7f

Please sign in to comment.