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

Function Context support #128

Merged
merged 12 commits into from
Oct 8, 2024

Conversation

stevendborrelli
Copy link
Contributor

@stevendborrelli stevendborrelli commented Oct 3, 2024

Description of your changes

Adds support for writing to Context

apiVersion: meta.gotemplating.fn.crossplane.io/v1alpha1
kind: Context
  data:

Fixes #66

I have:

Testing

Given the following template:

 ---
          apiVersion: meta.gotemplating.fn.crossplane.io/v1alpha1
          kind: Context
          data:
            "apiextensions.crossplane.io/environment":
               update: environment
               nestedEnvUpdate:
                 hello: world
            "other-context-key":
              complex: {{ index .context "apiextensions.crossplane.io/environment" "complex" | toYaml | nindent 6 }}
            newkey:
              hello: world
          ---
          apiVersion: example.crossplane.io/v1
          kind: XR
          status:
            fromEnv: {{ index .context "apiextensions.crossplane.io/environment" "complex" "c" "d" }} 

Render will output

---
apiVersion: example.crossplane.io/v1
kind: XR
metadata:
  name: example-xr
status:
  conditions:
  - lastTransitionTime: "2024-01-01T00:00:00Z"
    reason: Available
    status: "True"
    type: Ready
  fromEnv: e
---
apiVersion: render.crossplane.io/v1beta1
fields:
  apiextensions.crossplane.io/environment:
    apiVersion: internal.crossplane.io/v1alpha1
    complex:
      a: b
      c:
        d: e
        f: "1"
    kind: Environment
    nestedEnvUpdate:
      hello: world
    update: environment
  newkey:
    hello: world
  other-context-key:
    complex:
      a: b
      c:
        d: e
        f: "1"
kind: Context

@stevendborrelli stevendborrelli marked this pull request as draft October 3, 2024 09:33
@stevendborrelli
Copy link
Contributor Author

@phisco can you take a look? For the merging I am using mergo right now

@phisco
Copy link
Collaborator

phisco commented Oct 3, 2024

Awesome! Yes, I was thinking about mergo too, I'd say it looks pretty good, let me take it for a spin tomorrow!

Maybe I'd add some annotation to the context meta resource to allow replacing it instead of merging if needed.

@stevendborrelli stevendborrelli changed the title initial Context support Function Context support Oct 4, 2024
@stevendborrelli stevendborrelli marked this pull request as ready for review October 4, 2024 08:36
@phisco
Copy link
Collaborator

phisco commented Oct 8, 2024

opened stevendborrelli#1 with a few changes

@stevendborrelli
Copy link
Contributor Author

@phisco merged your changes. All looks good.

Copy link
Collaborator

@phisco phisco left a comment

Choose a reason for hiding this comment

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

sorry forgot to update the examples

example/context/composition.yaml Outdated Show resolved Hide resolved
README.md Show resolved Hide resolved
example/context/README.md Outdated Show resolved Hide resolved
example/context/README.md Outdated Show resolved Hide resolved
renovate bot and others added 12 commits October 8, 2024 14:29
Signed-off-by: Steven Borrelli <steve@borrelli.org>
Signed-off-by: Steven Borrelli <steve@borrelli.org>
Signed-off-by: Steven Borrelli <steve@borrelli.org>
Signed-off-by: Steven Borrelli <steve@borrelli.org>
Signed-off-by: Steven Borrelli <steve@borrelli.org>
Signed-off-by: Steven Borrelli <steve@borrelli.org>
Signed-off-by: Steven Borrelli <steve@borrelli.org>
Signed-off-by: Steven Borrelli <steve@borrelli.org>
Signed-off-by: Steven Borrelli <steve@borrelli.org>
Signed-off-by: Steven Borrelli <steve@borrelli.org>
…text

Signed-off-by: Philippe Scorsolini <p.scorsolini@gmail.com>
Signed-off-by: Steven Borrelli <steve@borrelli.org>
Co-authored-by: Philippe Scorsolini <p.scorsolini@gmail.com>
Signed-off-by: Steven Borrelli <steve@borrelli.org>
@phisco phisco merged commit 9c47d51 into crossplane-contrib:main Oct 8, 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.

Support writing to Context
2 participants