Skip to content

Add a nil case to the expandWildcards function#627

Merged
turkenh merged 2 commits intocrossplane:masterfrom
sergenyalcin:handle-nil-value-paved
Dec 13, 2023
Merged

Add a nil case to the expandWildcards function#627
turkenh merged 2 commits intocrossplane:masterfrom
sergenyalcin:handle-nil-value-paved

Conversation

@sergenyalcin
Copy link
Copy Markdown
Member

Description of your changes

This PR adds a nil case to the expandWildcards function to handle the case that the value of the segment is nil.

The issue was observed while testing the GCP certificatemanager.Certificate resource. While trying to get the connection details of this resource, we try to read the self_managed[*].certificate_pem attribute of this resource. If the self_managed object is nil, then we observe an error:

cannot get connection details: cannot get connection details: cannot expand wildcards: cannot expand wildcards for segments: "self_managed[*].certificate_pem": "self_managed": unexpected wildcard usage'

If the value of this field is nil, then we do not want to return an error because there is nothing to read in the sensitive attribute. In this case, we want to handle this situation in Upjet as a specific case other than the different cases. So, by returning a specific error from the nil case, we can handle this in Upjet by ignoring this error type.

I observed a specific error type, errNotFound and used this for the nil case.

I have:

  • Read and followed Crossplane's contribution process.
  • Run make reviewable test to ensure this PR is ready for review.

How has this code been tested

This was tested in the Upjet-based GCP provider. Resource: certificatemanager.Certificate

Signed-off-by: Sergen Yalçın <yalcinsergen97@gmail.com>
res = append(res, r...)
}
case nil:
return nil, errNotFound{errors.Errorf("%s: value of the field is nil", segments[:i])}
Copy link
Copy Markdown
Contributor

@ulucinar ulucinar Dec 12, 2023

Choose a reason for hiding this comment

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

Here, we differentiate between the cases where an unexpected type is encountered versus the specified path is not found and we hit the newly added case nil here.

nit:

Suggested change
return nil, errNotFound{errors.Errorf("%s: value of the field is nil", segments[:i])}
return nil, errNotFound{errors.Errorf("wildcard field %q is not found in the path", segments[:i])}

- Added a unit-test case

Signed-off-by: Sergen Yalçın <yalcinsergen97@gmail.com>
@sergenyalcin sergenyalcin force-pushed the handle-nil-value-paved branch from 079e276 to 4e24aae Compare December 12, 2023 12:00
Copy link
Copy Markdown
Contributor

@ulucinar ulucinar left a comment

Choose a reason for hiding this comment

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

Thanks @sergenyalcin, lgtm.

Copy link
Copy Markdown
Member

@turkenh turkenh left a comment

Choose a reason for hiding this comment

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

Thanks @sergenyalcin 🙌 Returning errNotFound for that case makes sense to me.

@turkenh turkenh merged commit 0b37953 into crossplane:master Dec 13, 2023
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.

3 participants