Skip to content

feat: support reading from context - #124

Open
tenstad wants to merge 1 commit into
crossplane-contrib:mainfrom
tenstad:context
Open

tenstad wants to merge 1 commit into
crossplane-contrib:mainfrom
tenstad:context

Conversation

@tenstad

@tenstad tenstad commented Sep 3, 2026 •

Copy link
Copy Markdown

Description of your changes

Adds support for use of context values in templated resources, through schema.context.
Example: region: '${schema.context["apiextensions.crossplane.io/environment"].region'

Very useful when the value of a managed resource is determined by some other function. It can be some custom logic in e.g function-python, or reading in data with function-environment-configs. Then using that value when creating a resource in function-kro.

Function context is added to the XR, meaning function-kro can then not support XRs with a top leven context field of their own (as it would be overwritten).

Relates to #30

I have:

@jbw976 jbw976 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

thanks for taking the initiative to explore and push more on function-kro could support context. clearly there is some community demand for this feature, so thanks for stepping up!

i spent some time on this today because i really want to avoid any changes to KRO at all to support this.

Check out #30 (comment) and let me know what you think. If you like that direction, you can take first crack here at the implementation (absolutely feel free to use my agent prompt gist) and keep driving since you are showing the initiative here! 🙇‍♂️

@tenstad

tenstad commented Sep 14, 2026

Copy link
Copy Markdown
Author

Thank you for #30 (comment) @jbw976!

The issue has two parts, reading and writing context. The two parts can be implemented independently of each other. I've focused on reading in this PR, as it's quite a bit easier and more important IMO. Also, another function can independantly read observed resources and output values from them to context.

@tenstad tenstad changed the title feat: support context feat: support reading from context Sep 14, 2026

@jbw976 jbw976 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you for updating this PR to go in this direction @tenstad - seeing the diff be pretty minimal is encouraging and I'm feeling good about this being the right approach that is also cheap for us!

A few more feedback items to incorporate in addition to the inline comments:

  • docs/examples: this new functionality should 100% get a new example added for it, it's great new functionality that people should have an example to see and follow. Add one under the example/ folder and follow the existing conventions/patterns there.
  • we still have the first attempt of updating vendored KRO code in the commit history - no need to keep that, let's just remove it from the history completely, e.g. rebase/squash your commits to just the new approach
  • just FYI, this new functionality is subject to issue #126 which I just opened. I don't think we need to solve it as part of this PR, but we'll want to fix that issue soon too, since I think context reading is probably one of the easier scenarios to make that accidental resource deletion happen 😂

Comment thread fn.go Resolved
Comment thread fn_test.go Resolved
Comment thread fn.go Resolved
Comment thread fn.go Resolved
Comment thread fn_test.go Resolved
Comment thread example/context/README.md Resolved
Signed-off-by: Amund Tenstad <github@amund.io>
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