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

Support loading crossplane beta render inputs from stdin #5630

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

negz
Copy link
Member

@negz negz commented Apr 25, 2024

Description of your changes

This uses the standard convention of a file named "-" meaning "read this file from stdin". The XR and Composition are assumed to be single YAML files, while functions and observed resources could be a stream.

I have:

Need help with this checklist? See the cheat sheet.

This uses the standard convention of a file named "-" meaning "read this
file from stdin". The XR and Composition are assumed to be single YAML
files, while functions and observed resources could be a stream.

Signed-off-by: Nic Cope <nicc@rk0n.org>
@phisco
Copy link
Contributor

phisco commented Apr 27, 2024

Sounds reasonable to me, we should probably error if more than one input is "-" to avoid hanging indefinitely.

Copy link
Member

@jbw976 jbw976 left a comment

Choose a reason for hiding this comment

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

Looks good to me @negz, agreed with @phisco's idea to verify that no more than 1 argument is -.

files = append(files, fileOrDir)
} else {

files := []string{fileOrDir}
Copy link
Member

Choose a reason for hiding this comment

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

in the previous code, we would avoid adding fileOrDir to the files list if it was a directory. Is it correct to go ahead and add it to the files list here now? Will that cause a problem later on in this func when we range over the files list and call LoadYAMLStreamFromFile on each of them?

Copy link
Member

Choose a reason for hiding this comment

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

ah nevermind, it shouldn't be an issue, because in the case of a directory we end up overwriting the files list with the yamls list that comes back from getYAMLFiles(). sounds good!

@jbw976
Copy link
Member

jbw976 commented Apr 30, 2024

I also took this for a quick test spin with the demo scenario in https://github.com/jbw976/demo-xfn/tree/main/kcl. It looks like it works correctly when you pipe various resources to render which it will then read via stdin 🤩

  • XR: cat xr-without-gateway.yaml | ./crank-stdin beta render - composition.yaml functions.yaml -r
  • Composition: cat composition.yaml | ./crank-stdin beta render xr-without-gateway.yaml - functions.yaml -r
  • Functions: cat functions.yaml | ./crank-stdin beta render xr-without-gateway.yaml composition.yaml - -r

Example output of piping the composition to stdin:

❯ cat composition.yaml | ./crank-stdin beta render xr-without-gateway.yaml - functions.yaml -r
---
apiVersion: demo-kcl.crossplane.io/v1alpha1
kind: XNetwork
metadata:
  name: xnetwork-kcl
status:
  conditions:
  - lastTransitionTime: "2024-01-01T00:00:00Z"
    message: 'Unready resources: vpc-0'
    reason: Creating
    status: "False"
    type: Ready
---
apiVersion: ec2.aws.upbound.io/v1beta1
kind: VPC
metadata:
  annotations:
    crossplane.io/composition-resource-name: vpc-0
  generateName: xnetwork-kcl-
  labels:
    crossplane.io/composite: xnetwork-kcl
    networks.meta.fn.crossplane.io/network-id: xnetwork-kcl
    networks.meta.fn.crossplane.io/vpc-id: vpc-0
  name: vpc-0
  ownerReferences:
  - apiVersion: demo-kcl.crossplane.io/v1alpha1
    blockOwnerDeletion: true
    controller: true
    kind: XNetwork
    name: xnetwork-kcl
    uid: ""
spec:
  forProvider:
    cidrBlock: 192.168.0.0/16
    enableDnsHostnames: true
    enableDnsSupport: true
    region: eu-central-1
  providerConfigRef:
    name: default
---
apiVersion: render.crossplane.io/v1beta1
kind: Result
message: created resource "vpc-0:VPC"
severity: SEVERITY_NORMAL
step: render-with-kcl

@negz
Copy link
Member Author

negz commented May 9, 2024

FWIW, this was mostly a POC. Following up to get it to the finish line isn't a priority for me, unfortunately. I'm happy if someone else wants to take it and run with it. 🙂

@jbw976
Copy link
Member

jbw976 commented May 10, 2024

I'm happy if someone else wants to take it and run with it.

Cool @negz, thanks for getting it to here so far! I've got this PR tracked in ##3957, so folks should hopefully find it and take it to the finish line sometime soon.

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.

None yet

3 participants