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 a nil case to the expandWildcards function #627

Merged
merged 2 commits into from
Dec 13, 2023

Conversation

sergenyalcin
Copy link
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

@@ -204,6 +204,8 @@ func expandWildcards(data any, segments Segments) ([]Segments, error) { //nolint
}
res = append(res, r...)
}
case nil:
return nil, errNotFound{errors.Errorf("%s: value of the field is nil", segments[:i])}
Copy link
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])}

pkg/fieldpath/paved.go Show resolved Hide resolved
- Added a unit-test case

Signed-off-by: Sergen Yalçın <[email protected]>
@sergenyalcin sergenyalcin force-pushed the handle-nil-value-paved branch from 079e276 to 4e24aae Compare December 12, 2023 12:00
Copy link
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
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
8 checks passed
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