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

feat: add more examples for crossplane kcl functions #1

Merged
merged 1 commit into from
Jan 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,21 @@ $ docker build . --tag=kcllang/crossplane-kcl
$ crossplane xpkg build -f package --embed-runtime-image=kcllang/crossplane-kcl
```

## Quick Start Examples
## Quick Start Examples and Debug Locally

See [here](./examples/resources/basic/)

## Installing

```yaml
apiVersion: pkg.crossplane.io/v1beta1
kind: Function
metadata:
name: kcl-function
spec:
package: kcllang/crossplane-kcl
```

## Expected Output

A KRM YAML list which means that each document must have an `apiVersion`, `kind`
Expand Down
2 changes: 2 additions & 0 deletions examples/patch_desired/patching/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
run:
crossplane beta render xr.yaml composition.yaml functions.yaml -r
31 changes: 31 additions & 0 deletions examples/patch_desired/patching/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Example Manifests

You can run your function locally and test it using `crossplane beta render`
with these example manifests.

```shell
# Run the function locally
$ go run . --insecure --debug
```

```shell
# Then, in another terminal, call it with these example manifests
$ crossplane beta render xr.yaml composition.yaml functions.yaml -r
---
apiVersion: nopexample.org/v1
kind: XSubnetwork
metadata:
annotations:
nobu.dev/app: someapp
nobu.dev/cueified: "true"
name: test-xrender
spec:
forProvider:
network: somenetwork
---
apiVersion: render.crossplane.io/v1beta1
kind: Result
message: updated xr ":XSubnetwork"
severity: SEVERITY_NORMAL
step: normal
```
29 changes: 29 additions & 0 deletions examples/patch_desired/patching/composition.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
apiVersion: apiextensions.crossplane.io/v1
kind: Composition
metadata:
name: function-template-go
spec:
compositeTypeRef:
apiVersion: example.crossplane.io/v1
kind: XR
mode: Pipeline
pipeline:
- step: normal
functionRef:
name: kcl-function
input:
apiVersion: krm.kcl.dev/v1alpha1
kind: KCLRun
metadata:
name: basic
spec:
target: PatchDesired
source: |
{
metadata.name = "test-desired"
metadata.annotations: {
"nobu.dev/cueified": "true",
"nobu.dev/app": "someapp",
}
spec.forProvider.network: "somenetwork"
}
9 changes: 9 additions & 0 deletions examples/patch_desired/patching/functions.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: pkg.crossplane.io/v1beta1
kind: Function
metadata:
name: kcl-function
annotations:
# This tells crossplane beta render to connect to the function locally.
render.crossplane.io/runtime: Development
spec:
package: kcllang/crossplane-kcl
5 changes: 5 additions & 0 deletions examples/patch_desired/patching/xr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Replace this with your XR!
apiVersion: nopexample.org/v1
kind: XSubnetwork
metadata:
name: test-xrender
2 changes: 2 additions & 0 deletions examples/patch_resources/patching/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
run:
crossplane beta render xr.yaml composition.yaml functions.yaml -r
47 changes: 47 additions & 0 deletions examples/patch_resources/patching/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Example Manifests

You can run your function locally and test it using `crossplane beta render`
with these example manifests.

```shell
# Run the function locally
$ go run . --insecure --debug
```

```shell
# Then, in another terminal, call it with these example manifests
$ crossplane beta render xr.yaml composition.yaml functions.yaml -r
---
apiVersion: nopexample.org/v1
kind: XSubnetwork
metadata:
name: test-xrender
---
apiVersion: nobu.dev/v1
kind: Bucket
metadata:
annotations:
crossplane.io/composition-resource-name: bucket
nobu.dev/app: someapp
nobu.dev/cueified: "true"
generateName: test-xrender-
labels:
crossplane.io/composite: test-xrender
name: bucket
ownerReferences:
- apiVersion: nopexample.org/v1
blockOwnerDeletion: true
controller: true
kind: XSubnetwork
name: test-xrender
uid: ""
spec:
forProvider:
network: somenetwork
---
apiVersion: render.crossplane.io/v1beta1
kind: Result
message: created resource "bucket:"
severity: SEVERITY_NORMAL
step: normal
```
36 changes: 36 additions & 0 deletions examples/patch_resources/patching/composition.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
apiVersion: apiextensions.crossplane.io/v1
kind: Composition
metadata:
name: function-template-go
spec:
compositeTypeRef:
apiVersion: example.crossplane.io/v1
kind: XR
mode: Pipeline
pipeline:
- step: normal
functionRef:
name: kcl-function
input:
apiVersion: krm.kcl.dev/v1alpha1
kind: KCLRun
metadata:
name: basic
spec:
target: PatchResources
resources:
- name: bucket
base:
apiVersion: nobu.dev/v1
kind: Bucket
metadata:
name: bucket
source: |
{
metadata.name = "bucket"
metadata.annotations: {
"nobu.dev/cueified": "true",
"nobu.dev/app": "someapp",
}
spec.forProvider.network: "somenetwork"
}
9 changes: 9 additions & 0 deletions examples/patch_resources/patching/functions.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: pkg.crossplane.io/v1beta1
kind: Function
metadata:
name: kcl-function
annotations:
# This tells crossplane beta render to connect to the function locally.
render.crossplane.io/runtime: Development
spec:
package: kcllang/crossplane-kcl
5 changes: 5 additions & 0 deletions examples/patch_resources/patching/xr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Replace this with your XR!
apiVersion: nopexample.org/v1
kind: XSubnetwork
metadata:
name: test-xrender
2 changes: 2 additions & 0 deletions examples/patch_resources/patching_multiple/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
run:
crossplane beta render xr.yaml composition.yaml functions.yaml -r
104 changes: 104 additions & 0 deletions examples/patch_resources/patching_multiple/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# Example Manifests

You can run your function locally and test it using `crossplane beta render`
with these example manifests.

```shell
# Run the function locally
$ go run . --insecure --debug
```

```shell
# Then, in another terminal, call it with these example manifests
$ crossplane beta render xr.yaml composition.yaml functions.yaml -r
crossplane beta render xr.yaml composition.yaml functions.yaml -r
---
apiVersion: nopexample.org/v1
kind: XSubnetwork
metadata:
name: test-xrender
---
apiVersion: nobu.dev/v1
kind: Bucket
metadata:
annotations:
crossplane.io/composition-resource-name: bucket
nobu.dev/app: someapp
nobu.dev/cueified: "true"
generateName: test-xrender-
labels:
crossplane.io/composite: test-xrender
name: bucket
ownerReferences:
- apiVersion: nopexample.org/v1
blockOwnerDeletion: true
controller: true
kind: XSubnetwork
name: test-xrender
uid: ""
spec:
forProvider:
policy: some-bucket-policy
---
apiVersion: nobu.dev/v1
kind: User
metadata:
annotations:
crossplane.io/composition-resource-name: iam-user
nobu.dev/app: someapp
nobu.dev/cueified: "true"
generateName: test-xrender-
labels:
crossplane.io/composite: test-xrender
name: iam-user
ownerReferences:
- apiVersion: nopexample.org/v1
blockOwnerDeletion: true
controller: true
kind: XSubnetwork
name: test-xrender
uid: ""
spec:
forProvider:
name: somename
---
apiVersion: nobu.dev/v1
kind: Role
metadata:
annotations:
crossplane.io/composition-resource-name: iam-role
nobu.dev/app: someapp
nobu.dev/cueified: "true"
generateName: test-xrender-
labels:
crossplane.io/composite: test-xrender
name: iam-role
ownerReferences:
- apiVersion: nopexample.org/v1
blockOwnerDeletion: true
controller: true
kind: XSubnetwork
name: test-xrender
uid: ""
spec:
forProvider:
policy: some-role-policy
---
apiVersion: render.crossplane.io/v1beta1
kind: Result
message: created resource "bucket:"
severity: SEVERITY_NORMAL
step: normal
---
apiVersion: render.crossplane.io/v1beta1
kind: Result
message: created resource "iam-role:"
severity: SEVERITY_NORMAL
step: normal
---
apiVersion: render.crossplane.io/v1beta1
kind: Result
message: created resource "iam-user:"
severity: SEVERITY_NORMAL
step: normal
```
69 changes: 69 additions & 0 deletions examples/patch_resources/patching_multiple/composition.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
apiVersion: apiextensions.crossplane.io/v1
kind: Composition
metadata:
name: function-template-go
spec:
compositeTypeRef:
apiVersion: example.crossplane.io/v1
kind: XR
mode: Pipeline
pipeline:
- step: normal
functionRef:
name: kcl-function
input:
apiVersion: krm.kcl.dev/v1alpha1
kind: KCLRun
metadata:
name: basic
spec:
target: PatchResources
resources:
- name: bucket
base:
apiVersion: nobu.dev/v1
kind: Bucket
metadata:
name: bucket
- name: iam-user
base:
apiVersion: nobu.dev/v1
kind: User
metadata:
name: iam-user
- name: iam-role
base:
apiVersion: nobu.dev/v1
kind: Role
metadata:
name: iam-role
source: |
items = [
{
# Target the bucket by name
metadata.name = "bucket"
metadata.annotations: {
"nobu.dev/cueified": "true",
"nobu.dev/app": "someapp",
}
spec.forProvider.policy: "some-bucket-policy"
}
{
# Target the user by name
metadata.name = "iam-user"
metadata.annotations: {
"nobu.dev/cueified": "true",
"nobu.dev/app": "someapp",
}
spec.forProvider.name: "somename"
}
{
# Target the role by name
metadata.name = "iam-role"
metadata.annotations: {
"nobu.dev/cueified": "true",
"nobu.dev/app": "someapp",
}
spec.forProvider.policy: "some-role-policy"
}
]
9 changes: 9 additions & 0 deletions examples/patch_resources/patching_multiple/functions.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: pkg.crossplane.io/v1beta1
kind: Function
metadata:
name: kcl-function
annotations:
# This tells crossplane beta render to connect to the function locally.
render.crossplane.io/runtime: Development
spec:
package: kcllang/crossplane-kcl
Loading