Skip to content

feat: support returning result in custom context key or environment#85

Open
tenstad wants to merge 14 commits intocrossplane-contrib:mainfrom
sn-atmos:env-context
Open

feat: support returning result in custom context key or environment#85
tenstad wants to merge 14 commits intocrossplane-contrib:mainfrom
sn-atmos:env-context

Conversation

@tenstad
Copy link

@tenstad tenstad commented Feb 12, 2026

Description of your changes

Related to https://crossplane.slack.com/archives/C08BBMDCH7W/p1769948003900819

Enables storing the fetched result in the environment (context) instead of the default context key used by this function. Makes it easy to load e.g. the data of a Secret or ConfigMap into environment (crossplane-contrib/function-environment-configs#78) and use it in patch and transform. Will also support loading namespace scoped EnvironmentConfigs into environment if such were to be created in the future.

To fetch a Secret into the environment:

        into:
          type: Environment
        extraResources:
          - kind: Secret
            apiVersion: v1
            namespace: default
            fromFieldPath: data
            type: Reference
            ref:
              name: credentials

Note: stacked on top of #84

See commit log for step by step implementation process.

Resolves crossplane-contrib/function-environment-configs#78

I have:

Signed-off-by: Amund Tenstad <github@amund.io>
Signed-off-by: Amund Tenstad <github@amund.io>
Signed-off-by: Amund Tenstad <github@amund.io>
…mFieldPath

Signed-off-by: Amund Tenstad <github@amund.io>
… within context

Signed-off-by: Amund Tenstad <github@amund.io>
Signed-off-by: Amund Tenstad <github@amund.io>
Signed-off-by: Amund Tenstad <github@amund.io>
Signed-off-by: Amund Tenstad <github@amund.io>
Signed-off-by: Amund Tenstad <github@amund.io>
Signed-off-by: Amund Tenstad <github@amund.io>
…nvironment-configs

Signed-off-by: Amund Tenstad <github@amund.io>
…unction-environment-configs

Signed-off-by: Amund Tenstad <github@amund.io>
…ment

Signed-off-by: Amund Tenstad <github@amund.io>
Comment on lines -97 to -98
// Into is the key into which extra resources for this selector will be placed.
Into string `json:"into"`
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is a breaking change, we should keep into here and make it the default.

Copy link
Collaborator

Choose a reason for hiding this comment

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

on top of that it's changing the semantic completely, previously each resource could go to a different key in the context, now they all go to the same one specified at the top level, but at different paths. I'd keep the into here, add a defaultInto at the top level which can be overridden from the resource level one, and make the top level one just a string, mentioning apiextensions.crossplane.io/environment as a well-known key in the comments for both.

Copy link
Author

Choose a reason for hiding this comment

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

I don't quite understand, and think it might be the into.contextKey thats confusing. It is not the same as into within extraResources.

The top level into specifies where to put the results (what key to use in response.SetContextKey). It's a sort of toggle between the behaviour of function-extra-resources and function-environment-configs.

  • type: Environment uses apiextensions.crossplane.io/environment
    (and also performs merge)
  • type: Context defaults to apiextensions.crossplane.io/extra-resources
    (but can be changed using contextKey: apiextensions.custom.io/custom)

The following into configuration would be the same as not specifying into at all, and has the same behaviour as the function has today.

into:
  type: Context
  # rename contextKey to just `context`?
  contextKey: apiextensions.crossplane.io/extra-resources
extraResources:
  - kind: Namespace
    apiVersion: v1
    into: obj-0
    type: Reference
    ref:
      name: crossplane-system

Copy link
Author

Choose a reason for hiding this comment

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

And yeah, we can ofc keep extraResources[].into instead of renaming the field to toFieldPath.

Should we then support the suggested nesting, or keep the current functionality using a simple key.

extraResources:
  - kind: Namespace
    fromFieldPath: metadata.name # only extract metadata.name
    into: resources.namespaces

Nested field path

apiextensions.crossplane.io/extra-resources:
  resources:
    namespaces: # nested inside of `resources`
      - kube-system
      - crossplane-system

Simple key

apiextensions.crossplane.io/extra-resources:
  resources.namespaces: # just a simple single-layer key
    - kube-system
    - crossplane-system

Copy link
Author

Choose a reason for hiding this comment

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

The top level into might be a bad name, open to other suggestions.
It does two things, configures the context, and toggles between the behaviour of function-extra-resources and function-environment-configs.

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.

Feature Request: Load keys from Secret or ConfigMap resources

2 participants