crossplane-contrib / function-cue-archived

Cuelang Integration for Crossplane's Composition Function
Apache License 2.0
10 stars 1 forks source link

Notice

This repo is Deprecated and will be merging with https://github.com/elastic/crossplane-function-cue. It is recommended that if you are using this repo to move to the elastic repository until it is migrated into this repo

function-cue

A cuelang integration for Crossplane's Composition Functions.

This function is based on /play codebase and cmd

Purpose

This function is intended to give a crossplane composition creator the ability to compile and run cue templates within a composition function. The user can target the compilation output to various objects determined by the target passed into the CUEInput.Export.Target

Targeting Patches

See Targeting Objects for info on utilizing the types of targets

Resources (default)
PatchDesired
PatchResources
XR

Expected Function Input

See the kubebuilder generated CRD or the go definition

Example Compositions

See examples folder

Expected Output

The compilation output of the CUEInput.Export.Value must be in YAML or JSON documents, or it will fail parsing.

Ex cueCompile() output schema

#outputSchema: {
    // Name of your resource
    name: string
    // Optional connection details
    // see docs/CONNECTION_DETAILS.md for more details
    connectionDetails?: [...#connectionDetail]
    // Optional readiness checks
    // see docs/READINESS_CHECKS.md for more details
    readinessChecks?: [...#readinessCheck]
    // Resource spec
    resource: {
        // Example
        // apiVersion: "nobu.dev/v1"
        // kind: "Example"
        //
        // etc...
    }
}

json

single

{
  "name": "my-cluster",
  "resource": {
    "apiVersion": "nobu.dev/v1",
    "kind": "XCluster"
  }
}

multiple - single json document per line, -e json.MarshalStream(field) will produce this format

{"name": "my-cluster", "resource": {"apiVersion": "nobu.dev/v1", "kind": "XCluster"}}
{"name": "my-network", "resource": {"apiVersion": "nobu.dev/v1", "kind": "XNetwork"}}

yaml

single

name: "my-cluster"
resource:
  apiVersion: "nobu.dev/v1"
  kind: "XCluster"

multiple documents, separated by ---, -e yaml.MarshalStream(field) will produce this format

name: "my-cluster"
resource:
  apiVersion: "nobu.dev/v1"
  kind: "XCluster"
---
name: "my-network"
resource:
  apiVersion: "nobu.dev/v1"
  kind: "XNetwork"
...

CUE Version supported

v0.7.0

Command Support

export

Runs cue export based off of a cue template provided by the CUEInput.Export.Value field

See the currently supported options

Installing

apiVersion: pkg.crossplane.io/v1beta1
kind: Function
metadata:
  name: function-cue
spec:
  package: mitsuwa/function-cue:v0.1.2

Importable Packages

See libraries

Debugging

Logs are emitted to the Function's pod logs. Look for the Function pod in crossplane-system.

Levels

Info   # default
Debug  # run with --debug flag