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

Adding composed.To() method #150

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

Conversation

BigGold1310
Copy link

Description of your changes

Adds the composed.To() method to allow an easy conversion from a function-sdk-go Unstructured to a concrete/strongly typed object.

Fixes #93

I have:

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

How has this code been tested

Code is tested by unit-testing.

Signed-off-by: Cyrill Näf <cyrill.naef@gmail.com>
Signed-off-by: bakito <github@bakito.ch>
Copy link
Member

@negz negz left a comment

Choose a reason for hiding this comment

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

Thanks @BigGold1310!

Could you provide a little more context around how you'd expect to use this function? Is the idea that you'd convert observed composed resources to their real types?

When a function deserializes the Protobuf request the resources are a *structpb.Struct. Behind the scenes we're already using resource.AsObject to convert the Struct to a *composed.Unstructured when you call request.GetObservedComposedResources. Part of me wonders whether we should make it possible to go straight from Struct -> your desired type and skip the Unstructured in the middle, to avoid a layer of serialization. Not a blocker for this PR though given there's already the From function here that has a similar issue.

resource/composed/composed.go Outdated Show resolved Hide resolved
Simplify error handling by directly returning the error

Co-authored-by: Nic Cope <nicc@rk0n.org>
@BigGold1310
Copy link
Author

Thank you @negz for taking a look at this PR.

The idea of this function is to make it easier writing functions with strongly typed objects. So the function should help converting from the composed.Unstructured to a structured resource.

Converting the object directly from the *structpb.Struct sounds reasonable. I would suggest that we look at that implementation in a separate PR as more parts of the code need to be touched.
I'm happy to give it a try if you could provide me some guidance/pointers on where to look at/where to start.

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.

Improve support of typed objects
3 participants