Skip to content

feat: configurable environment path#95

Open
tenstad wants to merge 2 commits intocrossplane-contrib:mainfrom
tenstad:tofieldpath
Open

feat: configurable environment path#95
tenstad wants to merge 2 commits intocrossplane-contrib:mainfrom
tenstad:tofieldpath

Conversation

@tenstad
Copy link

@tenstad tenstad commented Feb 1, 2026

Description of your changes

Related to #82 and https://crossplane.slack.com/archives/C08BBMDCH7W/p1769759797425119?thread_ts=1769438184.689339&cid=C08BBMDCH7W

When loading multiple EnvironmentConfig resources directly into the environment context at the root level, conflicts will occur if they overlap in structure. They can also easily conflict with keys used in patch-and-transform:

---
apiVersion: apiextensions.crossplane.io/v1beta1
kind: EnvironmentConfig
metadata:
  name: foo
data:
  name: foo
---
apiVersion: apiextensions.crossplane.io/v1beta1
kind: EnvironmentConfig
metadata:
  name: bar
data:
  name: bar
---
apiVersion: apiextensions.crossplane.io/v1
kind: Composition
spec:
  pipeline:
    - input:
        apiVersion: environmentconfigs.fn.crossplane.io/v1beta1
        kind: Input
        spec:
          environmentConfigs:
            - type: Reference # environment is '{name: foo}'
              ref:
                name: foo
            - type: Reference # overrides 'name' in environment to 'bar'
              ref:
                name: bar
    - input:
        apiVersion: pt.fn.crossplane.io/v1beta1
        kind: Resources
        environment:
          patches:
            - type: FromCompositeFieldPath # overrides 'name' in environment to 'baz'
              fromFieldPath: metadata.name
              toFieldPath: name

I suggest adding toFieldPath to configure where in the environment to put the referenced resources. Using it as shown below, the composition above would end up with the environment {foo: {name: foo}, bar: {name: bar}, name: baz} instead of just {name: baz}.

environmentConfigs:
  - type: Reference
    toFieldPath: foo
    ref:
      name: foo
  - type: Reference
    toFieldPath: bar
    ref:
      name: bar

Another alternative is to create the EnvironmentConfigs in such a way that they wont conflict (which you would still have to do when loading multiple EnvironmentConfigs with a single label selector). It however tightly binds the EnvironmentConfig content to the composition where it is used, instead of just containing the raw data:

---
apiVersion: apiextensions.crossplane.io/v1beta1
kind: EnvironmentConfig
metadata:
  name: foo
data:
  foo:
    name: foo

I have:

@tenstad tenstad requested a review from phisco as a code owner February 1, 2026 10:46
Signed-off-by: Amund Tenstad <github@amund.io>
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.

1 participant