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

fix: allow using function only to patch to and from the environment #122

Merged
merged 2 commits into from
May 24, 2024

Conversation

phisco
Copy link
Collaborator

@phisco phisco commented May 24, 2024

From https://crossplane.slack.com/archives/CEG3T90A1/p1716529989392019:

Details

Hello, hopefully someone here can point me in the right direction.
I'm struggling a bit to understan pipeline context. My current assumption is that I should be able to run a function-patch-and-transform with a ToEnvironmentFieldPath patch to write a value to the context.
This is my setup:
$ crossplane version
Client Version: v1.16.0
Server Version: v1.15.2-up.1
XR from function-patch-and-transform multistep example
functions from function-patch-and-transform multistep example
composition from function-patch-and-transform multistep example with the addition below:
...

- step: patch-and-transform-to-env
  functionRef:
    name: function-patch-and-transform
  input:
    apiVersion: pt.fn.crossplane.io/v1beta1
    kind: Resources
    resources:
      - name: bucketACL 
        patches:
          - type: ToEnvironmentFieldPath
            fromFieldPath: "spec.acl"
            toFieldPath: key1

$ crossplane beta render xr.yaml composition.yaml function.yaml --include-context

...
54 │ ---
55 │ apiVersion: render.crossplane.io/v1beta1
56 │ fields:
57 │ apiextensions.crossplane.io/environment: {}
58 │ kind: Context
I'm expecting to see a key1 in apiextensions.crossplane.io/environment, but maybe this is not how it works?

The right approach was to instead define the following:

    - step: patch-and-transform-to-env
      functionRef:
        name: function-patch-and-transform
      input:
        apiVersion: pt.fn.crossplane.io/v1beta1
        kind: Resources
        environment:
          patches:
            - type: FromCompositeFieldPath
              fromFieldPath: spec.acl
              toFieldPath: key1

But it didn't work firstly because not specifying spec.resources wasn't allowed, which shouldn't be the case.
But after faking a resource it was still failing because the environment was missing the gvk we expect and that crossplane would have set if it had passed an environment:

crossplane: error: cannot render composite resource: pipeline step "patch-and-transform-to-env" returned a fatal result: cannot apply the "FromCompositeFieldPath" environment patch at index 0: cannot patch to object: Object 'Kind' is missing in '{"key1":"private"}'

This PR fixes both issues.

@phisco phisco requested a review from negz May 24, 2024 09:34
@negz negz merged commit 901f6a0 into crossplane-contrib:main May 24, 2024
6 checks passed
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