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 resource.update convenience function #98

Merged
merged 3 commits into from
Oct 10, 2024
Merged

Conversation

negz
Copy link
Member

@negz negz commented Oct 9, 2024

Description of your changes

This function can be used to add or update a resource.

For example, to add a desired composed bucket (assuming the "bucket" resource doesn't yet exist):

resource.update(rsp.desired.resources["bucket"], bucket)

Or to update the desired XR:

resource.update(rsp.desired.composite.resource, partial_xr)

The source resource can be a dictionary, a protobuf struct, or a Pydantic model.

I have:

crossplane/function/resource.py Outdated Show resolved Hide resolved
@@ -0,0 +1,301 @@
# generated by datamodel-codegen:
Copy link
Member Author

Choose a reason for hiding this comment

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

This is all generated code - no need to review it.

"grpcio==1.*",
"grpcio-reflection==1.*",
"protobuf==5.27.2",
"pydantic==2.*",
Copy link
Member Author

@negz negz Oct 9, 2024

Choose a reason for hiding this comment

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

I don't love introducing a dependency on pydantic just for the type annotation really. I think if it proves to be a pain we could move it out to an optional dependency.

I don't think pydantic has a lot of dependencies though, so it may not be so bad.

negz added 3 commits October 9, 2024 18:04
This function can be used to add or update a resource.

For example, to add a desired composed bucket (assuming the "bucket"
resource doesn't yet exist):

```python
resource.update(rsp.desired.resources["bucket"], bucket)
```

Or to update the desired XR:

```python
resource.update(rsp.desired.composite.resource, partial_xr)
```

The source resource can be a dictionary, a protobuf struct, or a
Pydantic model.

Signed-off-by: Nic Cope <[email protected]>
This was introduced in 3.10, and seems like a much better way to handle
matching a type.

Signed-off-by: Nic Cope <[email protected]>
@negz negz merged commit 33ee9e1 into crossplane:main Oct 10, 2024
6 checks passed
@negz negz deleted the pydants branch October 10, 2024 02:11
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