Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Service Credential Bindings of type Key #3662

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

ddraganovv
Copy link

Is there a related GitHub Issue?

#2320

What is this change about?

With this PR we are introducing a new type of service binding - 'key'.

Does this PR introduce a breaking change?

No

Acceptance Steps

Tag your pair, your PM, and/or team

@ddraganovv ddraganovv force-pushed the add_service_binding_key_type branch from de22dd0 to 885960b Compare December 13, 2024 07:53
Copy link
Member

@danail-branekov danail-branekov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good overall, minor comments. The most important is that there is no controller test that verifies that servicebindingio bindings are not created when the binding is of type key

Could you please just push the changes addressing the comments into this branch without recreating the PR? When you recreate the PR my previous comments and review notes are lost and I have to rereview all the changes all over again which takes time

ServiceInstance: &payloads.Relationship{
Data: &payloads.RelationshipData{
GUID: "service-instance-guid",
When("creating a service binding of type key", func() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This When is missing the "happy" path when creating a binding of type key to a managed service succeeds. I guess this test should only check that the expected HTTP response code is returned and the repository has been invoked with correct arguments. Inspecting the response content is already done in the tests below, no need to duplicate it.

func (l *ServiceBindingList) ToMessage() repositories.ListServiceBindingsMessage {
return repositories.ListServiceBindingsMessage{
message := repositories.ListServiceBindingsMessage{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just return the literal here, the `message variable is not needed

@@ -18,13 +20,23 @@ var _ = Describe("ServiceBindingList", func() {
Expect(decodeErr).NotTo(HaveOccurred())
Expect(*actualServiceBindingList).To(Equal(expectedServiceBindingList))
},
Entry("type", "type=key", payloads.ServiceBindingList{Type: korifiv1alpha1.CFServiceBindingTypeKey}),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as the validation of the payload type now allows key and app values for type, I would suggest to test those valud values with two entries:

Entry("type=key", "type=key", payloads.ServiceBindingList{Type: korifiv1alpha1.CFServiceBindingTypeKey}),
Entry("type=app", "type=app", payloads.ServiceBindingList{Type: korifiv1alpha1.CFServiceBindingTypeApp}),

Same goes for ServiceBindingCreate - as the type now can be key, I guess you should ammend this test - I believe it would fail

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=include", payloads.ServiceBindingList{Include: "include"}),
Entry("include", "include=app", payloads.ServiceBindingList{Include: "app"}),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same goes here, include now can be either app, or service_instance, therefore two entries with those two values could verify they are accepted

Expect(serviceBindingCreate).To(gstruct.PointTo(Equal(createPayload)))
})

When("binding is key and name field is omitted", func() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when the binding is key has been already specified by the parent When description, no need to repeat it here (i.e. change the description to When("name field is imitted", ...)

@@ -272,9 +277,9 @@ var _ = Describe("ServiceBindingRepo", func() {

It("creates a new CFServiceBinding resource and returns a record", func() {
Expect(createErr).NotTo(HaveOccurred())

Expect(serviceBindingRecord.GUID).NotTo(BeEmpty())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

guid is asserted to be a valid guid below, no need to check for not being empty (an empty string is not a valid uuid)

Expect(serviceBindingRecord.GUID).To(matchers.BeValidUUID())
Expect(serviceBindingRecord.Type).To(Equal("app"))
Expect(serviceBindingRecord.Name).To(BeNil())
Expect(serviceBindingRecord.GUID).NotTo(BeEmpty())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In order to be consistent with the tests above, you could Expect(serviceBindingRecord.GUID).To(matchers.BeValidUUID())

},
},
))
Expect(serviceBinding.Spec.Type).To(Equal(korifiv1alpha1.CFServiceBindingTypeApp))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checking the spec's field one by one with Equal is a bit awkward. What you have done is perfectly fine, but if you want to, you could only match the fields that are interesting to this test. For example, the code does not set the Spec.Service.APIVersion explicitly, so no need to check it

Here is an example of MatchFields where we only check the fields we are interested in.

It("creates the binding with the specified name", func() {
Expect(serviceBindingRecord.Name).To(Equal(bindingName))
})
It("creates a key binding", func() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggesst shortening this It to only check the fields of the record that make sense to the key binding type, i.e. Type being set to key, AppGUID being empty and app relationship not being set. The rest of the fields are being checked in the parent context, so checking them here as well is just unneeded duplication

@@ -145,6 +144,10 @@ func (r *Reconciler) ReconcileResource(ctx context.Context, cfServiceBinding *ko
return res, err
}

if cfServiceBinding.Spec.Type == korifiv1alpha1.CFServiceBindingTypeKey {
return ctrl.Result{}, nil
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no controller test that asserts that no servicebindingio bindings are created to bindings of type key. Please add one

@ddraganovv ddraganovv force-pushed the add_service_binding_key_type branch 5 times, most recently from 9389946 to 9874f7f Compare January 10, 2025 08:52
@danail-branekov danail-branekov enabled auto-merge (squash) January 10, 2025 09:30
@danail-branekov danail-branekov force-pushed the add_service_binding_key_type branch from 9874f7f to 994ddbd Compare January 10, 2025 09:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants