Conversation
c2e4a48 to
92b9428
Compare
negz
left a comment
There was a problem hiding this comment.
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.
|
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 |
2c5fa80 to
1b77621
Compare
|
@negz Please review again, the DCO bot should be fixed now and I rebased to the latest version of the branch |
Signed-off-by: Cyrill Näf <cyrill.naef@gmail.com>
Signed-off-by: bakito <github@bakito.ch>
Simplify error handling by directly returning the error Co-authored-by: Nic Cope <nicc@rk0n.org> Signed-off-by: Cyrill Näf <cyrill.naef@gmail.com>
|
@negz Could we have some feedback on this PR? It's by now a very old one.... |
| // Get known GVKs for the runtime object type | ||
| knownGVKs, _, err := Scheme.ObjectKinds(obj) | ||
| if err != nil { | ||
| return errors.Errorf("could not retrieve GVKs for the provided object: %v", err) | ||
| } | ||
|
|
||
| // Check if GVK is known as we should not try to convert it if it doesn't match | ||
| gvkMatches := false | ||
| for _, knownGVK := range knownGVKs { | ||
| if knownGVK == un.GetObjectKind().GroupVersionKind() { | ||
| gvkMatches = true | ||
| } | ||
| } | ||
|
|
||
| if !gvkMatches { | ||
| return errors.Errorf("GVK %v is not known by the scheme for the provided object type", un.GetObjectKind().GroupVersionKind()) | ||
| } |
There was a problem hiding this comment.
What would happen if we didn't check this here?
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:
make reviewableto ensure this PR is ready for review.How has this code been tested
Code is tested by unit-testing.