Skip to content

Add fieldRef #74

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

stevendborrelli
Copy link
Collaborator

@stevendborrelli stevendborrelli commented Aug 13, 2025

Description of your changes

Adds a fieldRef to shellEnvVars. A fieldRef is like a valueRef, but it allows the ability to return a null string or a defaultValue if the field is not present.

Fixes #75

An image is available for testing at index.docker.io/steve/function-shell:fieldref.

shellEnvVars:
- key: EXAMPLE_VAR
  type: FieldRef
  fieldRef:
    policy: "Optional"
    path: "status.field"
    defaultValue: "NotSet"

Testing

Ran the example/functionRef composition in a cluster. It correctly sets default fields and reads from the XR status:

apiVersion: example.crossplane.io/v1
kind: XR
metadata:
  annotations:
    kubectl.kubernetes.io/last-applied-configuration: |
      {"apiVersion":"example.crossplane.io/v1","kind":"XR","metadata":{"annotations":{},"name":"example-echo"},"spec":{"field":"hello from the XR"}}
  creationTimestamp: "2025-08-13T16:16:54Z"
  finalizers:
  - composite.apiextensions.crossplane.io
  generation: 5
  labels:
    crossplane.io/composite: example-echo
  name: example-echo
  resourceVersion: "62783"
  uid: c5439354-df24-4494-af80-65375852ea03
spec:
  compositionRef:
    name: shell-example
  compositionRevisionRef:
    name: shell-example-c375c75
  compositionUpdatePolicy: Automatic
  field: hello from the XR
  resourceRefs: []
status:
  atFunction:
    shell:
      stderr: ""
      stdout: |-
        echo: hello from the XR optional: defaultValue from Composition
        status.atFunction.shell.stdout is populated
  conditions:
  - lastTransitionTime: "2025-08-13T16:18:14Z"
    observedGeneration: 5
    reason: ReconcileSuccess
    status: "True"
    type: Synced
  - lastTransitionTime: "2025-08-13T16:18:14Z"
    observedGeneration: 5
    reason: Available
    status: "True"
    type: Ready

I have:

Signed-off-by: Steven Borrelli <[email protected]>
Signed-off-by: Steven Borrelli <[email protected]>
Signed-off-by: Steven Borrelli <[email protected]>
Signed-off-by: Steven Borrelli <[email protected]>
Signed-off-by: Steven Borrelli <[email protected]>
Signed-off-by: Steven Borrelli <[email protected]>
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.

valueRef errors if field is not present
1 participant