Skip to content

feat: match labels FromEnvironmentFieldPath#119

Open
tenstad wants to merge 6 commits into
crossplane-contrib:mainfrom
tenstad:from-environment-field-path
Open

feat: match labels FromEnvironmentFieldPath#119
tenstad wants to merge 6 commits into
crossplane-contrib:mainfrom
tenstad:from-environment-field-path

Conversation

@tenstad

@tenstad tenstad commented May 30, 2026

Copy link
Copy Markdown
Contributor

Description of your changes

It is currently difficult to lookup EnvironmentConfigs based on values from environment. For example fetching one environment config (or resource, using function-extra-resources) and then fetch another environment config based on values in the first one.

The PR extends the types of matchLabels to include FromEnvironmentFieldPath.

It reuses the valueFromFieldPath and fromFieldPathPolicy fields used by FromCompositeFieldPath, as they did not contain composite, but could instead create valueFromEnvironmentFieldPath and fromEnvironmentFieldPathPolicy.

Tests are updated to also test FromEnvironmentFieldPath wherever FromCompositeFieldPath is tested.

I have:

@tenstad tenstad requested a review from phisco as a code owner May 30, 2026 10:52
Comment thread input/v1beta1/composition_environment.go Outdated
Comment thread fn.go Outdated
// Note(phisco): We need to compute the selectors even if we already
// requested them already at the previous iteration.
requirements, err := buildRequirements(in, oxr)
env, _ := request.GetContextKey(req, FunctionContextKeyEnvironment)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

missing error handling here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I don't check the ok from v, ok := f[key] as there is no guarantee that the environment key exists in the context. And we want the resulting map to just be empty if it does not exist exit. Both .GetStructValue() and .AsMap() are nil-safe, so there is no need to do conditionally call them. Added a comment to clarify.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

What do you think is best? Skipping the check, or performing it as in #119 (comment)

tenstad added 3 commits June 12, 2026 17:12
Signed-off-by: Amund Tenstad <github@amund.io>
Signed-off-by: Amund Tenstad <github@amund.io>
Signed-off-by: Amund Tenstad <github@amund.io>
@tenstad tenstad force-pushed the from-environment-field-path branch from 9a077ed to 51fb4d5 Compare June 12, 2026 15:12
tenstad added 2 commits June 12, 2026 17:14
…h typo

Signed-off-by: Amund Tenstad <github@amund.io>
Signed-off-by: Amund Tenstad <github@amund.io>
@tenstad tenstad force-pushed the from-environment-field-path branch from 7dbda1a to 508610e Compare June 12, 2026 15:18
Signed-off-by: Amund Tenstad <github@amund.io>
Comment thread fn.go
Comment on lines +64 to +66
// Skip key presence check as the context key is not required and map conversion is nil safe.
envCtx, _ := request.GetContextKey(req, FunctionContextKeyEnvironment)
env := envCtx.GetStructValue().AsMap()

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Could also just do the if check I guess, avoiding the comment and potential confusion.

Suggested change
// Skip key presence check as the context key is not required and map conversion is nil safe.
envCtx, _ := request.GetContextKey(req, FunctionContextKeyEnvironment)
env := envCtx.GetStructValue().AsMap()
var env map[string]any
if envCtx, ok := request.GetContextKey(req, FunctionContextKeyEnvironment); ok {
env = envCtx.GetStructValue().AsMap()
}

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