diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index ac06289..a543204 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -31,7 +31,7 @@ env: XPKG_ACCESS_ID: ${{ secrets.XPKG_ACCESS_ID }} # The package to push, without a version tag. The default matches GitHub. For - # example xpkg.upbound.io/crossplane/function-template-go. + # example xpkg.upbound.io/crossplane/function-kcl. XPKG: xpkg.upbound.io/${{ github.repository}} CROSSPLANE_REGORG: ghcr.io/${{ github.repository}} # xpkg.crossplane.io/crossplane-contrib diff --git a/README.md b/README.md index eaa99a1..12d6f3f 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,10 @@ ## Introduction -Crossplane KCL function allows developers to use [KCL](https://kcl-lang.io/) (a DSL) to write composite logic without the need for repeated packaging of crossplane functions, and we support package management and the [KRM KCL specification](https://github.com/kcl-lang/krm-kcl), which allows for OCI/Git source and the reuse of [KCL's module ecosystem](https://artifacthub.io/packages/search?org=kcl&sort=relevance&page=1). +Crossplane KCL function allows developers to use [KCL](https://kcl-lang.io/) (a DSL) +to write composite logic without the need for repeated packaging of crossplane functions, +and we support package management and the [KRM KCL specification](https://github.com/kcl-lang/krm-kcl), +which allows for OCI/Git source and the reuse of [KCL's module ecosystem](https://artifacthub.io/packages/search?org=kcl&sort=relevance&page=1). Check out these following blogs to learn more. @@ -32,25 +35,26 @@ spec: input: apiVersion: krm.kcl.dev/v1alpha1 kind: KCLInput - source: | - # Read the XR - oxr = option("params").oxr - # Patch the XR with the status field - dxr = { - **option("params").dxr - status.dummy = "cool-status" - } - # Construct a bucket - bucket = { - apiVersion = "s3.aws.upbound.io/v1beta1" - kind = "Bucket" - metadata.annotations: { - "krm.kcl.dev/composition-resource-name" = "bucket" - } - spec.forProvider.region = option("oxr").spec.region - } - # Return the bucket and patched XR - items = [bucket, dxr] + spec: + source: | + # Read the XR + oxr = option("params").oxr + # Patch the XR with the status field + dxr = { + **option("params").dxr + status.dummy = "cool-status" + } + # Construct a bucket + bucket = { + apiVersion = "s3.aws.upbound.io/v1beta1" + kind = "Bucket" + metadata.annotations: { + "krm.kcl.dev/composition-resource-name" = "bucket" + } + spec.forProvider.region = option("oxr").spec.region + } + # Return the bucket and patched XR + items = [bucket, dxr] - step: automatically-detect-ready-composed-resources functionRef: name: function-auto-ready @@ -80,8 +84,6 @@ To use a `KCLInput` as the function config, the KCL source must be specified in ```yaml apiVersion: krm.kcl.dev/v1alpha1 kind: KCLInput -metadata: - name: basic spec: source: | { @@ -99,8 +101,6 @@ spec: ```yaml apiVersion: krm.kcl.dev/v1alpha1 kind: KCLInput -metadata: - name: basic spec: source: oci://ghcr.io/kcl-lang/crossplane-xnetwork-kcl-function ``` @@ -110,8 +110,6 @@ spec: ```yaml apiVersion: krm.kcl.dev/v1alpha1 kind: KCLInput -metadata: - name: basic spec: source: github.com/kcl-lang/modules/crossplane-xnetwork-kcl-function ``` @@ -121,8 +119,6 @@ spec: ```yaml apiVersion: krm.kcl.dev/v1alpha1 kind: KCLInput -metadata: - name: basic spec: source: ./path/to/kcl/file.k ``` @@ -136,6 +132,7 @@ kubectl create configmap templates --from-file=templates.k -n crossplane-system This `ConfigMap` will be mounted to the function pod and the templates will be available in the `/templates` directory. See the following function config for details. ```yaml +--- apiVersion: pkg.crossplane.io/v1beta1 kind: Function metadata: @@ -169,7 +166,8 @@ spec: ### Use as a Base Image -This function can also be used as a base image to build complex functions in KCL. To do this, add your KCL code to the image and set the `FUNCTION_KCL_DEFAULT_SOURCE` environment variable to the path where you put your code. +This function can also be used as a base image to build complex functions in KCL. +To do this, add your KCL code to the image and set the `FUNCTION_KCL_DEFAULT_SOURCE` environment variable to the path where you put your code. For example, if you have the following in `main.k`: @@ -217,7 +215,7 @@ Next, add a file specifying the dependencies to be added to all functions, using the syntax of the `[dependencies]` section of `kcl.mod`, for example: ```dockerfile -ADD dependencies /dependecies +ADD dependencies /dependencies ``` where the file `dependencies` contains: @@ -250,8 +248,6 @@ You can define your custom parameters in the `params` field and use `option("par ```yaml apiVersion: krm.kcl.dev/v1alpha1 kind: KCLInput -metadata: - name: basic spec: params: custom_key: custom_value @@ -263,8 +259,6 @@ spec: ```yaml apiVersion: krm.kcl.dev/v1alpha1 kind: KCLInput -metadata: - name: kcl-xnetwork spec: params: annotations: @@ -296,25 +290,26 @@ spec: input: apiVersion: krm.kcl.dev/v1alpha1 kind: KCLInput - source: | - # Read the XR - oxr = option("params").oxr - # Patch the XR with the status field - dxr = { - **option("params").dxr - status.dummy = "cool-status" - } - # Construct a bucket - bucket = { - apiVersion = "s3.aws.upbound.io/v1beta1" - kind = "Bucket" - metadata.annotations: { - "krm.kcl.dev/composition-resource-name" = "bucket" - } - spec.forProvider.region = option("oxr").spec.region - } - # Return the bucket and patched XR - items = [bucket, dxr] + spec: + source: | + # Read the XR + oxr = option("params").oxr + # Patch the XR with the status field + dxr = { + **option("params").dxr + status.dummy = "cool-status" + } + # Construct a bucket + bucket = { + apiVersion = "s3.aws.upbound.io/v1beta1" + kind = "Bucket" + metadata.annotations: { + "krm.kcl.dev/composition-resource-name" = "bucket" + } + spec.forProvider.region = option("oxr").spec.region + } + # Return the bucket and patched XR + items = [bucket, dxr] credentials: # If private OCI registry - name: kcl-registry source: Secret @@ -330,7 +325,7 @@ apiVersion: v1 kind: Secret metadata: name: default - namsepace: default + namespace: default data: username: dXNlcm5hbWU= password: cGFzc3dvcmQ= @@ -384,8 +379,6 @@ A KRM YAML list means that each document must have an `apiVersion`, `kind` throu ```yaml apiVersion: krm.kcl.dev/v1alpha1 kind: KCLInput -metadata: - name: basic spec: source: | items = [{ @@ -406,8 +399,6 @@ spec: ```yaml apiVersion: krm.kcl.dev/v1alpha1 kind: KCLInput -metadata: - name: basic spec: source: | { @@ -420,7 +411,9 @@ spec: } ``` -> Note that when returning multiple resources, we need to set different `metadata.name` or `metadata.annotations."krm.kcl.dev/composition-resource-name" ` to distinguish between different resources in the composition functions. +> [!NOTE] +> When returning multiple resources, we need to set different `metadata.name` or `metadata.annotations."krm.kcl.dev/composition-resource-name" ` +> to distinguish between different resources in the composition functions. ### Target Support @@ -437,8 +430,6 @@ This is controlled by fields on the `KCInput` ```yaml apiVersion: krm.kcl.dev/v1alpha1 kind: KCLInput -metadata: - name: basic spec: # default: Default target: Default | PatchDesired | PatchResources | Resources | XR @@ -449,13 +440,14 @@ spec: ### Extract Data from a Specific Composed Resource -To extract data from a specific composed resource by using the resource name, we can use the `option("params").ocds` variable, `ocds` is a mapping that its key is the resource name and its value is the [`observed composed resource`](https://pkg.go.dev/github.com/crossplane/function-sdk-go@v0.2.0/resource#ObservedComposed) like [the example](./examples/default/read_ocds_resource/composition.yaml). +To extract data from a specific composed resource by using the resource name, we can use the `option("params").ocds` variable, +`ocds` is a mapping that its key is the resource name and its value is +the [`observed composed resource`](https://pkg.go.dev/github.com/crossplane/function-sdk-go@v0.2.0/resource#ObservedComposed) +like [the example](./examples/default/read_ocds_resource/composition.yaml). ```yaml apiVersion: krm.kcl.dev/v1alpha1 kind: KCLInput -metadata: - name: show-ocds spec: source: | { @@ -469,7 +461,8 @@ spec: ### Composite Resource Connection Details -To return desired composite resource connection details, include a KCL config that produces the special CompositeConnectionDetails resource like [the example](./examples/default/connection_details/composition.yaml): +To return desired composite resource connection details, include a KCL config that produces the special CompositeConnectionDetails resource +like [the example](./examples/default/connection_details/composition.yaml): ```yaml apiVersion: krm.kcl.dev/v1alpha1 @@ -493,13 +486,14 @@ spec: ] ``` -> Note: The value of the connection secret value must be base64 encoded. This is already the case if you are referencing a key from a managed resource's connectionDetails field. However, if you want to include a connection secret value from somewhere else, you will need to use the `base64.encode` function: +> [!NOTE] +> The value of the connection secret value must be base64 encoded. +> This is already the case if you are referencing a key from a managed resource's connectionDetails field. +> However, if you want to include a connection secret value from somewhere else, you will need to use the `base64.encode` function: ```yaml apiVersion: krm.kcl.dev/v1alpha1 kind: KCLInput -metadata: - name: basic spec: source: | import base64 @@ -520,8 +514,6 @@ To mark a desired composed resource as ready, use the `krm.kcl.dev/ready` annota ```yaml apiVersion: krm.kcl.dev/v1alpha1 kind: KCLInput -metadata: - name: basic spec: source: | # Omit other logic @@ -536,18 +528,19 @@ spec: ``` ### Extra resources -By defining one or more special `ExtraResources`, you can ask Crossplane to retrieve additional resources from the local cluster and make them available to your templates. See the [docs](https://github.com/crossplane/crossplane/blob/main/design/design-doc-composition-functions-extra-resources.md) for more information. +By defining one or more special `ExtraResources`, you can ask Crossplane to retrieve additional resources from the local cluster +and make them available to your templates. +See the [docs](https://github.com/crossplane/crossplane/blob/main/design/design-doc-composition-functions-extra-resources.md) for more information. +> [!NOTE] > With ExtraResources, you can fetch cluster-scoped resources, but not namespaced resources such as claims. > If you need to get a composite resource via its claim name you can use `matchLabels` with `crossplane.io/claim-name: `. - -> Namespace scoped resources can be queried with the `matchNamespace` field. Leaving the `matchNamespace` field empty or not defining it will query a cluster scoped resource. +> Namespace scoped resources can be queried with the `matchNamespace` field. +> Leaving the `matchNamespace` field empty or not defining it will query a cluster scoped resource. ```yaml apiVersion: krm.kcl.dev/v1alpha1 kind: KCLInput -metadata: - name: basic spec: source: | # Omit other logic @@ -593,6 +586,7 @@ spec: You can retrieve the extra resources either via labels with `matchLabels` or via name with `matchName: somename`. This will result in Crossplane receiving the requested resources and make them available with the following format. + ```yaml foo: - Resource: @@ -617,14 +611,17 @@ bar: name: my-bar # Omitted for brevity ``` + You can access the retrieved resources in your code like this: -> Note that Crossplane performs an additional reconciliation pass for extra resources. -> Consequently, during the initial execution, these resources may be uninitialized. It is essential to implement checks to handle this scenario. + +> [!NOTE] +> Crossplane performs an additional reconciliation pass for extra resources. +> Consequently, during the initial execution, these resources may be uninitialized. +> It is essential to implement checks to handle this scenario. + ```yaml apiVersion: krm.kcl.dev/v1alpha1 kind: KCLInput -metadata: - name: basic spec: source: | er = option("params")?.extraResources @@ -641,8 +638,6 @@ You can read the XR, patch it with the status field and return the new patched X ```yaml apiVersion: krm.kcl.dev/v1alpha1 kind: KCLInput -metadata: - name: basic spec: source: | # Read the XR @@ -654,17 +649,18 @@ spec: ### Settings conditions and events +> [!NOTE] > This feature requires Crossplane v1.17 or newer. You can set conditions and events directly from KCL, either in the composite resource or both the composite and claim resources. To set one or more conditions, use the following approach: + ```yaml apiVersion: krm.kcl.dev/v1alpha1 kind: KCLInput metadata: annotations: "krm.kcl.dev/default_ready": "True" - name: basic spec: source: | oxr = option("params").oxr @@ -696,17 +692,19 @@ spec: ] ``` -- **target**: Specifies whether the condition should be present in the composite resource or both the composite and claim resources. Possible values are `CompositeAndClaim` and `Composite` -- **force**: Forces the overwrite of existing conditions. If a condition with the same `type` already exists, it will not be overwritten by default. Setting force to `True` will overwrite the first condition. +- **target**: Specifies whether the condition should be present in the composite resource or both the composite and claim resources. + Possible values are `CompositeAndClaim` and `Composite` +- **force**: Forces the overwrite of existing conditions. If a condition with the same `type` already exists, it will not be overwritten by default. + Setting force to `True` will overwrite the first condition. You can also set events as follows: + ```yaml apiVersion: krm.kcl.dev/v1alpha1 kind: KCLInput metadata: annotations: "krm.kcl.dev/default_ready": "True" - name: basic spec: source: | oxr = option("params").oxr diff --git a/cspell.json b/cspell.json new file mode 100644 index 0000000..381d097 --- /dev/null +++ b/cspell.json @@ -0,0 +1,18 @@ +{ + "version": "0.2", + "words": [ + "Crossplane", + "apiextensions", + "claimname", + "configmap", + "dcds", + "kcllang", + "ocds", + "somename", + "upbound", + "xnetwork", + "xpkg" + ], + "language": "en", + "flagWords": [] +} diff --git a/examples/default/conditions/composition.yaml b/examples/default/conditions/composition.yaml index a277ff5..8a93054 100644 --- a/examples/default/conditions/composition.yaml +++ b/examples/default/conditions/composition.yaml @@ -1,49 +1,48 @@ apiVersion: apiextensions.crossplane.io/v1 kind: Composition metadata: - name: function-template-go + name: kcl-function spec: compositeTypeRef: apiVersion: example.crossplane.io/v1beta1 kind: XR mode: Pipeline pipeline: - - step: normal - functionRef: - name: kcl-function - input: - apiVersion: krm.kcl.dev/v1alpha1 - kind: KCLInput - metadata: - annotations: - "krm.kcl.dev/default_ready": "True" - name: basic - spec: - source: | - oxr = option("params").oxr - - dxr = { - **oxr - } - - conditions = { - apiVersion: "meta.krm.kcl.dev/v1alpha1" - kind: "Conditions" - conditions = [ - { - target: "CompositeAndClaim" - force: False - condition = { - type: "DatabaseReady" - status: "False" - reason: "FailedToCreate" - message: "Encountered an error creating the database" + - step: normal + functionRef: + name: kcl-function + input: + apiVersion: krm.kcl.dev/v1alpha1 + kind: KCLInput + metadata: + annotations: + "krm.kcl.dev/default_ready": "True" + spec: + source: | + oxr = option("params").oxr + + dxr = { + **oxr + } + + conditions = { + apiVersion: "meta.krm.kcl.dev/v1alpha1" + kind: "Conditions" + conditions = [ + { + target: "CompositeAndClaim" + force: False + condition = { + type: "DatabaseReady" + status: "False" + reason: "FailedToCreate" + message: "Encountered an error creating the database" + } } - } - ] - - } - items = [ - conditions - dxr - ] + ] + + } + items = [ + conditions + dxr + ] diff --git a/examples/default/connection_details/composition.yaml b/examples/default/connection_details/composition.yaml index 50080ca..41ff02d 100644 --- a/examples/default/connection_details/composition.yaml +++ b/examples/default/connection_details/composition.yaml @@ -1,92 +1,89 @@ apiVersion: apiextensions.crossplane.io/v1 kind: Composition metadata: - name: function-template-go + name: kcl-function spec: compositeTypeRef: apiVersion: example.crossplane.io/v1beta1 kind: XR mode: Pipeline pipeline: - - step: normal - functionRef: - name: kcl-function - input: - apiVersion: krm.kcl.dev/v1alpha1 - kind: KCLInput - metadata: - annotations: - "krm.kcl.dev/default_ready": "True" - name: basic - spec: - source: | - import base64 + - step: normal + functionRef: + name: kcl-function + input: + apiVersion: krm.kcl.dev/v1alpha1 + kind: KCLInput + metadata: + annotations: + "krm.kcl.dev/default_ready": "True" + spec: + source: | + import base64 - oxr = option("params").oxr - count = oxr.spec.count or 1 - ocds = option("params").ocds - dxr = { - **option("params").dxr - status.dummy = "cool-status" - } - details = { - apiVersion: "meta.krm.kcl.dev/v1alpha1" - kind: "CompositeConnectionDetails" - if "sample-access-key-0" in ocds: - data: { - username = ocds["sample-access-key-0"].ConnectionDetails.username - password = ocds["sample-access-key-0"].ConnectionDetails.password - url = base64.encode("http://www.example.com") - } - else: - data: {} - } - items = sum([[{ - apiVersion: "iam.aws.upbound.io/v1beta1" - kind: "User" - metadata.name = "test-user-{}".format(i) - metadata.labels: { - "testing.upbound.io/example-name" = "test-user-{}".format(i) - if "test-user-{}".format(i) in ocds: - dummy = ocds["test-user-{}".format(i)].Resource.metadata.labels.dummy - else: - dummy = "foo" - } - metadata.annotations: { - "krm.kcl.dev/ready": "False" - } - spec.forProvider: {} - }, { - apiVersion: "iam.aws.upbound.io/v1beta1" - kind: "AccessKey" - metadata.name = "sample-access-key-{}".format(i) - metadata.annotations: { - "krm.kcl.dev/ready": "True" - } - spec.forProvider.userSelector.matchLabels: { - "testing.upbound.io/example-name" = "test-user-{}".format(i) - } - spec.writeConnectionSecretToRef: { - name: "sample-access-key-secret-{}".format(i) - namespace: "crossplane-system" - } - }] for i in range(count)], []) + [ - details - dxr - ] + oxr = option("params").oxr + count = oxr.spec.count or 1 + ocds = option("params").ocds + dxr = { + **option("params").dxr + status.dummy = "cool-status" + } + details = { + apiVersion: "meta.krm.kcl.dev/v1alpha1" + kind: "CompositeConnectionDetails" + if "sample-access-key-0" in ocds: + data: { + username = ocds["sample-access-key-0"].ConnectionDetails.username + password = ocds["sample-access-key-0"].ConnectionDetails.password + url = base64.encode("http://www.example.com") + } + else: + data: {} + } + items = sum([[{ + apiVersion: "iam.aws.upbound.io/v1beta1" + kind: "User" + metadata.name = "test-user-{}".format(i) + metadata.labels: { + "testing.upbound.io/example-name" = "test-user-{}".format(i) + if "test-user-{}".format(i) in ocds: + dummy = ocds["test-user-{}".format(i)].Resource.metadata.labels.dummy + else: + dummy = "foo" + } + metadata.annotations: { + "krm.kcl.dev/ready": "False" + } + spec.forProvider: {} + }, { + apiVersion: "iam.aws.upbound.io/v1beta1" + kind: "AccessKey" + metadata.name = "sample-access-key-{}".format(i) + metadata.annotations: { + "krm.kcl.dev/ready": "True" + } + spec.forProvider.userSelector.matchLabels: { + "testing.upbound.io/example-name" = "test-user-{}".format(i) + } + spec.writeConnectionSecretToRef: { + name: "sample-access-key-secret-{}".format(i) + namespace: "crossplane-system" + } + }] for i in range(count)], []) + [ + details + dxr + ] - # Just for test - - step: normal1 - functionRef: - name: kcl-function - input: - apiVersion: krm.kcl.dev/v1alpha1 - kind: KCLInput - metadata: - name: show-dcds - spec: - source: | - { - metadata.name = "dcds" - dcds: option("params").dcds - } + # Just for test + - step: normal1 + functionRef: + name: kcl-function + input: + apiVersion: krm.kcl.dev/v1alpha1 + kind: KCLInput + spec: + source: | + { + metadata.name = "dcds" + dcds: option("params").dcds + } diff --git a/examples/default/context/composition.yaml b/examples/default/context/composition.yaml index 256bfb3..f6ef8fd 100644 --- a/examples/default/context/composition.yaml +++ b/examples/default/context/composition.yaml @@ -1,42 +1,41 @@ apiVersion: apiextensions.crossplane.io/v1 kind: Composition metadata: - name: function-template-go + name: kcl-function spec: compositeTypeRef: apiVersion: example.crossplane.io/v1beta1 kind: XR mode: Pipeline pipeline: - - step: normal - functionRef: - name: kcl-function - input: - apiVersion: krm.kcl.dev/v1alpha1 - kind: KCLInput - metadata: - annotations: - "krm.kcl.dev/default_ready": "True" - name: basic - spec: - source: | - oxr = option("params").oxr + - step: normal + functionRef: + name: kcl-function + input: + apiVersion: krm.kcl.dev/v1alpha1 + kind: KCLInput + metadata: + annotations: + "krm.kcl.dev/default_ready": "True" + spec: + source: | + oxr = option("params").oxr - dxr = { - **oxr - } + dxr = { + **oxr + } - context = { - apiVersion: "meta.krm.kcl.dev/v1alpha1" - kind: "Context" - data = { - contextField = "contextValue" - moreComplexField = { - test: "field" + context = { + apiVersion: "meta.krm.kcl.dev/v1alpha1" + kind: "Context" + data = { + contextField = "contextValue" + moreComplexField = { + test: "field" + } } - } - } - items = [ - context - dxr - ] + } + items = [ + context + dxr + ] diff --git a/examples/default/debug_print/composition.yaml b/examples/default/debug_print/composition.yaml index a1c3366..3fe68b5 100644 --- a/examples/default/debug_print/composition.yaml +++ b/examples/default/debug_print/composition.yaml @@ -1,69 +1,67 @@ apiVersion: apiextensions.crossplane.io/v1 kind: Composition metadata: - name: function-template-go + name: kcl-function spec: compositeTypeRef: apiVersion: example.crossplane.io/v1beta1 kind: XR mode: Pipeline pipeline: - - step: normal - functionRef: - name: kcl-function - input: - apiVersion: krm.kcl.dev/v1alpha1 - kind: KCLInput - metadata: - name: basic - spec: - source: | - import base64 + - step: normal + functionRef: + name: kcl-function + input: + apiVersion: krm.kcl.dev/v1alpha1 + kind: KCLInput + spec: + source: | + import base64 - oxr = option("params").oxr - count = oxr.spec.count or 1 - print("The value of `count` field in the XR is", count) - ocds = option("params").ocds - dxr = { - **option("params").dxr - status.dummy = "cool-status" - } - details = { - apiVersion: "meta.krm.kcl.dev/v1alpha1" - kind: "CompositeConnectionDetails" - if "sample-access-key-0" in ocds: - data: { - username = ocds["sample-access-key-0"].ConnectionDetails.username - password = ocds["sample-access-key-0"].ConnectionDetails.password - url = base64.encode("http://www.example.com") - } - else: - data: {} - } - items = sum([[{ - apiVersion: "iam.aws.upbound.io/v1beta1" - kind: "User" - metadata.name = "test-user-{}".format(i) - metadata.labels: { - "testing.upbound.io/example-name" = "test-user-{}".format(i) - if "test-user-{}".format(i) in ocds: - dummy = ocds["test-user-{}".format(i)].Resource.metadata.labels.dummy - else: - dummy = "foo" - } - spec.forProvider: {} - }, { - apiVersion: "iam.aws.upbound.io/v1beta1" - kind: "AccessKey" - metadata.name = "sample-access-key-{}".format(i) - spec.forProvider.userSelector.matchLabels: { - "testing.upbound.io/example-name" = "test-user-{}".format(i) - } - spec.writeConnectionSecretToRef: { - name: "sample-access-key-secret-{}".format(i) - namespace: "crossplane-system" - } - }] for i in range(count)], []) + [ - details - dxr - ] + oxr = option("params").oxr + count = oxr.spec.count or 1 + print("The value of `count` field in the XR is", count) + ocds = option("params").ocds + dxr = { + **option("params").dxr + status.dummy = "cool-status" + } + details = { + apiVersion: "meta.krm.kcl.dev/v1alpha1" + kind: "CompositeConnectionDetails" + if "sample-access-key-0" in ocds: + data: { + username = ocds["sample-access-key-0"].ConnectionDetails.username + password = ocds["sample-access-key-0"].ConnectionDetails.password + url = base64.encode("http://www.example.com") + } + else: + data: {} + } + items = sum([[{ + apiVersion: "iam.aws.upbound.io/v1beta1" + kind: "User" + metadata.name = "test-user-{}".format(i) + metadata.labels: { + "testing.upbound.io/example-name" = "test-user-{}".format(i) + if "test-user-{}".format(i) in ocds: + dummy = ocds["test-user-{}".format(i)].Resource.metadata.labels.dummy + else: + dummy = "foo" + } + spec.forProvider: {} + }, { + apiVersion: "iam.aws.upbound.io/v1beta1" + kind: "AccessKey" + metadata.name = "sample-access-key-{}".format(i) + spec.forProvider.userSelector.matchLabels: { + "testing.upbound.io/example-name" = "test-user-{}".format(i) + } + spec.writeConnectionSecretToRef: { + name: "sample-access-key-secret-{}".format(i) + namespace: "crossplane-system" + } + }] for i in range(count)], []) + [ + details + dxr + ] diff --git a/examples/default/dependencies/composition.yaml b/examples/default/dependencies/composition.yaml index 677992f..8c5b793 100644 --- a/examples/default/dependencies/composition.yaml +++ b/examples/default/dependencies/composition.yaml @@ -1,64 +1,62 @@ apiVersion: apiextensions.crossplane.io/v1 kind: Composition metadata: - name: function-template-go + name: kcl-function spec: compositeTypeRef: apiVersion: example.crossplane.io/v1beta1 kind: XR mode: Pipeline pipeline: - - step: normal - functionRef: - name: kcl-function - input: - apiVersion: krm.kcl.dev/v1alpha1 - kind: KCLInput - metadata: - name: basic - spec: - dependencies: | - k8s = "1.31" - crossplane = "1.16.0" - source: | - import k8s.api.rbac.v1 as k8srbac - import crossplane.v1 as cpv1 - import crossplane.v1beta1 as cpv1beta1 + - step: normal + functionRef: + name: kcl-function + input: + apiVersion: krm.kcl.dev/v1alpha1 + kind: KCLInput + spec: + dependencies: | + k8s = "1.31" + crossplane = "1.16.0" + source: | + import k8s.api.rbac.v1 as k8srbac + import crossplane.v1 as cpv1 + import crossplane.v1beta1 as cpv1beta1 - items = [ - cpv1.Provider { - metadata.name = "provider-helm" - spec: { - package = "xpkg.upbound.io/crossplane-contrib/provider-helm:v0.19.0" - runtimeConfigRef.name = "provider-helm" - } - } - cpv1beta1.DeploymentRuntimeConfig { - metadata.name = "provider-helm" - metadata.annotations: { - "krm.kcl.dev/composition-resource-name" = "provider-helm-config" - } - spec: { - serviceAccountTemplate: {metadata.name = "provider-helm"} - } - } - k8srbac.ClusterRoleBinding { - metadata.name = "provider-helm-cluster-admin" - subjects: [{ - kind = "ServiceAccount" - name = "provider-helm" - namespace = "crossplane-system" - }] - roleRef: { - kind = "ClusterRole" - name = "provider-helm-cluster-admin" - apiGroup = "rbac.authorization.k8s.io" + items = [ + cpv1.Provider { + metadata.name = "provider-helm" + spec: { + package = "xpkg.upbound.io/crossplane-contrib/provider-helm:v0.19.0" + runtimeConfigRef.name = "provider-helm" + } + } + cpv1beta1.DeploymentRuntimeConfig { + metadata.name = "provider-helm" + metadata.annotations: { + "krm.kcl.dev/composition-resource-name" = "provider-helm-config" + } + spec: { + serviceAccountTemplate: {metadata.name = "provider-helm"} + } + } + k8srbac.ClusterRoleBinding { + metadata.name = "provider-helm-cluster-admin" + subjects: [{ + kind = "ServiceAccount" + name = "provider-helm" + namespace = "crossplane-system" + }] + roleRef: { + kind = "ClusterRole" + name = "provider-helm-cluster-admin" + apiGroup = "rbac.authorization.k8s.io" + } + } + cpv1beta1.ProviderConfig { + metadata.name = "helm-provider" + spec = { + credentials.source = "InjectedIdentity" } - } - cpv1beta1.ProviderConfig { - metadata.name = "helm-provider" - spec = { - credentials.source = "InjectedIdentity" } - } - ] + ] diff --git a/examples/default/events/composition.yaml b/examples/default/events/composition.yaml index cc81fa1..476ec64 100644 --- a/examples/default/events/composition.yaml +++ b/examples/default/events/composition.yaml @@ -1,46 +1,45 @@ apiVersion: apiextensions.crossplane.io/v1 kind: Composition metadata: - name: function-template-go + name: kcl-function spec: compositeTypeRef: apiVersion: example.crossplane.io/v1beta1 kind: XR mode: Pipeline pipeline: - - step: normal - functionRef: - name: kcl-function - input: - apiVersion: krm.kcl.dev/v1alpha1 - kind: KCLInput - metadata: - annotations: - "krm.kcl.dev/default_ready": "True" - name: basic - spec: - source: | - oxr = option("params").oxr - - dxr = { - **oxr - } - - events = { - apiVersion: "meta.krm.kcl.dev/v1alpha1" - kind: "Events" - events = [ - { - target: "CompositeAndClaim" - event = { - type: "Warning" - reason: "ResourceLimitExceeded" - message: "The resource limit has been exceeded" + - step: normal + functionRef: + name: kcl-function + input: + apiVersion: krm.kcl.dev/v1alpha1 + kind: KCLInput + metadata: + annotations: + "krm.kcl.dev/default_ready": "True" + spec: + source: | + oxr = option("params").oxr + + dxr = { + **oxr + } + + events = { + apiVersion: "meta.krm.kcl.dev/v1alpha1" + kind: "Events" + events = [ + { + target: "CompositeAndClaim" + event = { + type: "Warning" + reason: "ResourceLimitExceeded" + message: "The resource limit has been exceeded" + } } - } - ] - } - items = [ - events - dxr - ] + ] + } + items = [ + events + dxr + ] diff --git a/examples/default/external_deps/composition.yaml b/examples/default/external_deps/composition.yaml index e857226..66c748a 100644 --- a/examples/default/external_deps/composition.yaml +++ b/examples/default/external_deps/composition.yaml @@ -1,31 +1,28 @@ apiVersion: apiextensions.crossplane.io/v1 kind: Composition metadata: - name: function-template-go + name: kcl-function spec: compositeTypeRef: apiVersion: example.crossplane.io/v1beta1 kind: XR mode: Pipeline pipeline: - - step: normal - functionRef: - name: kcl-function - input: - apiVersion: krm.kcl.dev/v1alpha1 - kind: KCLInput - metadata: - name: basic - spec: - dependencies: - k8s = "1.31" - source: | - import k8s.api.core.v1 as k8core + - step: normal + functionRef: + name: kcl-function + input: + apiVersion: krm.kcl.dev/v1alpha1 + kind: KCLInput + spec: + dependencies: k8s = "1.31" + source: | + import k8s.api.core.v1 as k8core - k8core.Pod { - spec: k8core.PodSpec{ - containers: [{ - name = "main" - }] - } - } + k8core.Pod { + spec: k8core.PodSpec{ + containers: [{ + name = "main" + }] + } + } diff --git a/examples/default/extra_resources/composition.yaml b/examples/default/extra_resources/composition.yaml index 44a88e2..0f6b934 100644 --- a/examples/default/extra_resources/composition.yaml +++ b/examples/default/extra_resources/composition.yaml @@ -1,54 +1,53 @@ apiVersion: apiextensions.crossplane.io/v1 kind: Composition metadata: - name: function-template-go + name: kcl-function spec: compositeTypeRef: apiVersion: example.crossplane.io/v1beta1 kind: XR mode: Pipeline pipeline: - - step: normal - functionRef: - name: kcl-function - input: - apiVersion: krm.kcl.dev/v1alpha1 - kind: KCLInput - metadata: - annotations: - "krm.kcl.dev/default_ready": "True" - name: basic - spec: - source: | - oxr = option("params").oxr - er = option("params")?.extraResources - - foo = [{ - apiVersion: "example/v1alpha1" - kind: "Foo" - metadata = { - name: k.Resource.metadata.name - } - } for k in er?.bucket] if er?.bucket else [] - - dxr = { - **oxr - } - - details = { - apiVersion: "meta.krm.kcl.dev/v1alpha1" - kind: "ExtraResources" - requirements = { - bucket = { - apiVersion: "s3.aws.upbound.io/v1beta1", - kind: "Bucket", - matchLabels: { - "foo": "bar" - } - } + - step: normal + functionRef: + name: kcl-function + input: + apiVersion: krm.kcl.dev/v1alpha1 + kind: KCLInput + metadata: + annotations: + "krm.kcl.dev/default_ready": "True" + spec: + source: | + oxr = option("params").oxr + er = option("params")?.extraResources + + foo = [{ + apiVersion: "example/v1alpha1" + kind: "Foo" + metadata = { + name: k.Resource.metadata.name } - } - items = [ - details - dxr - ] + foo + } for k in er?.bucket] if er?.bucket else [] + + dxr = { + **oxr + } + + details = { + apiVersion: "meta.krm.kcl.dev/v1alpha1" + kind: "ExtraResources" + requirements = { + bucket = { + apiVersion: "s3.aws.upbound.io/v1beta1", + kind: "Bucket", + matchLabels: { + "foo": "bar" + } + } + } + } + items = [ + details + dxr + ] + foo diff --git a/examples/default/extra_resources_namespaced/composition.yaml b/examples/default/extra_resources_namespaced/composition.yaml index 2e8ab83..924afc1 100644 --- a/examples/default/extra_resources_namespaced/composition.yaml +++ b/examples/default/extra_resources_namespaced/composition.yaml @@ -1,55 +1,54 @@ apiVersion: apiextensions.crossplane.io/v1 kind: Composition metadata: - name: function-template-go + name: kcl-function spec: compositeTypeRef: apiVersion: example.crossplane.io/v1beta1 kind: XR mode: Pipeline pipeline: - - step: normal - functionRef: - name: kcl-function - input: - apiVersion: krm.kcl.dev/v1alpha1 - kind: KCLInput - metadata: - annotations: - "krm.kcl.dev/default_ready": "True" - name: basic - spec: - source: | - oxr = option("params").oxr - er = option("params")?.extraResources - - foo = [{ - apiVersion: "example/v1alpha1" - kind: "Foo" - metadata = { - name: k.Resource.metadata.name - } - } for k in er?.bucket] if er?.bucket else [] - - dxr = { - **oxr - } - - details = { - apiVersion: "meta.krm.kcl.dev/v1alpha1" - kind: "ExtraResources" - requirements = { - bucket = { - apiVersion: "s3.aws.m.upbound.io/v1beta1", - kind: "Bucket", - matchLabels: { - "foo": "bar" - } - matchNamespace: "awesome-namespace" - } + - step: normal + functionRef: + name: kcl-function + input: + apiVersion: krm.kcl.dev/v1alpha1 + kind: KCLInput + metadata: + annotations: + "krm.kcl.dev/default_ready": "True" + spec: + source: | + oxr = option("params").oxr + er = option("params")?.extraResources + + foo = [{ + apiVersion: "example/v1alpha1" + kind: "Foo" + metadata = { + name: k.Resource.metadata.name } - } - items = [ - details - dxr - ] + foo + } for k in er?.bucket] if er?.bucket else [] + + dxr = { + **oxr + } + + details = { + apiVersion: "meta.krm.kcl.dev/v1alpha1" + kind: "ExtraResources" + requirements = { + bucket = { + apiVersion: "s3.aws.m.upbound.io/v1beta1", + kind: "Bucket", + matchLabels: { + "foo": "bar" + } + matchNamespace: "awesome-namespace" + } + } + } + items = [ + details + dxr + ] + foo diff --git a/examples/default/function_ctx/composition.yaml b/examples/default/function_ctx/composition.yaml index aee41d4..5adc58c 100644 --- a/examples/default/function_ctx/composition.yaml +++ b/examples/default/function_ctx/composition.yaml @@ -1,23 +1,21 @@ apiVersion: apiextensions.crossplane.io/v1 kind: Composition metadata: - name: function-template-go + name: kcl-function spec: compositeTypeRef: apiVersion: example.crossplane.io/v1beta1 kind: XR mode: Pipeline pipeline: - - step: normal - functionRef: - name: kcl-function - input: - apiVersion: krm.kcl.dev/v1alpha1 - kind: KCLInput - metadata: - name: basic - spec: - source: | - ctx = option("params").ctx - # Show function pipeline's context. - items = [{ctx = ctx}] + - step: normal + functionRef: + name: kcl-function + input: + apiVersion: krm.kcl.dev/v1alpha1 + kind: KCLInput + spec: + source: | + ctx = option("params").ctx + # Show function pipeline's context. + items = [{ctx = ctx}] diff --git a/examples/default/read_ocds_resource/composition.yaml b/examples/default/read_ocds_resource/composition.yaml index 03265a3..b78588a 100644 --- a/examples/default/read_ocds_resource/composition.yaml +++ b/examples/default/read_ocds_resource/composition.yaml @@ -1,29 +1,26 @@ apiVersion: apiextensions.crossplane.io/v1 kind: Composition metadata: - name: function-template-go + name: kcl-function spec: compositeTypeRef: apiVersion: example.crossplane.io/v1beta1 kind: XR mode: Pipeline pipeline: - - # Just for test - - step: normal - functionRef: - name: kcl-function - input: - apiVersion: krm.kcl.dev/v1alpha1 - kind: KCLInput - metadata: - name: show-ocds - spec: - source: | - { - metadata.name = "ocds" - spec.ocds = option("params").ocds - spec.user_kind = option("params").ocds["test-user"]?.Resource.Kind - spec.user_metadata = option("params").ocds["test-user"]?.Resource.metadata - spec.user_status = option("params").ocds["test-user"]?.Resource.status - } + # Just for test + - step: normal + functionRef: + name: kcl-function + input: + apiVersion: krm.kcl.dev/v1alpha1 + kind: KCLInput + spec: + source: | + { + metadata.name = "ocds" + spec.ocds = option("params").ocds + spec.user_kind = option("params").ocds["test-user"]?.Resource.Kind + spec.user_metadata = option("params").ocds["test-user"]?.Resource.metadata + spec.user_status = option("params").ocds["test-user"]?.Resource.status + } diff --git a/examples/default/resources/composition.yaml b/examples/default/resources/composition.yaml index b039523..a177856 100644 --- a/examples/default/resources/composition.yaml +++ b/examples/default/resources/composition.yaml @@ -1,68 +1,66 @@ apiVersion: apiextensions.crossplane.io/v1 kind: Composition metadata: - name: function-template-go + name: kcl-function spec: compositeTypeRef: apiVersion: example.crossplane.io/v1beta1 kind: XR mode: Pipeline pipeline: - - step: normal - functionRef: - name: kcl-function - input: - apiVersion: krm.kcl.dev/v1alpha1 - kind: KCLInput - metadata: - name: basic - spec: - source: | - import base64 + - step: normal + functionRef: + name: kcl-function + input: + apiVersion: krm.kcl.dev/v1alpha1 + kind: KCLInput + spec: + source: | + import base64 - oxr = option("params").oxr - count = oxr.spec.count or 1 - ocds = option("params").ocds - dxr = { - **option("params").dxr - status.dummy = "cool-status" - } - details = { - apiVersion: "meta.krm.kcl.dev/v1alpha1" - kind: "CompositeConnectionDetails" - if "sample-access-key-0" in ocds: - data: { - username = ocds["sample-access-key-0"].ConnectionDetails.username - password = ocds["sample-access-key-0"].ConnectionDetails.password - url = base64.encode("http://www.example.com") - } - else: - data: {} - } - items = sum([[{ - apiVersion: "iam.aws.upbound.io/v1beta1" - kind: "User" - metadata.name = "test-user-{}".format(i) - metadata.labels: { - "testing.upbound.io/example-name" = "test-user-{}".format(i) - if "test-user-{}".format(i) in ocds: - dummy = ocds["test-user-{}".format(i)].Resource.metadata.labels.dummy - else: - dummy = "foo" - } - spec.forProvider: {} - }, { - apiVersion: "iam.aws.upbound.io/v1beta1" - kind: "AccessKey" - metadata.name = "sample-access-key-{}".format(i) - spec.forProvider.userSelector.matchLabels: { - "testing.upbound.io/example-name" = "test-user-{}".format(i) - } - spec.writeConnectionSecretToRef: { - name: "sample-access-key-secret-{}".format(i) - namespace: "crossplane-system" - } - }] for i in range(count)], []) + [ - details - dxr - ] + oxr = option("params").oxr + count = oxr.spec.count or 1 + ocds = option("params").ocds + dxr = { + **option("params").dxr + status.dummy = "cool-status" + } + details = { + apiVersion: "meta.krm.kcl.dev/v1alpha1" + kind: "CompositeConnectionDetails" + if "sample-access-key-0" in ocds: + data: { + username = ocds["sample-access-key-0"].ConnectionDetails.username + password = ocds["sample-access-key-0"].ConnectionDetails.password + url = base64.encode("http://www.example.com") + } + else: + data: {} + } + items = sum([[{ + apiVersion: "iam.aws.upbound.io/v1beta1" + kind: "User" + metadata.name = "test-user-{}".format(i) + metadata.labels: { + "testing.upbound.io/example-name" = "test-user-{}".format(i) + if "test-user-{}".format(i) in ocds: + dummy = ocds["test-user-{}".format(i)].Resource.metadata.labels.dummy + else: + dummy = "foo" + } + spec.forProvider: {} + }, { + apiVersion: "iam.aws.upbound.io/v1beta1" + kind: "AccessKey" + metadata.name = "sample-access-key-{}".format(i) + spec.forProvider.userSelector.matchLabels: { + "testing.upbound.io/example-name" = "test-user-{}".format(i) + } + spec.writeConnectionSecretToRef: { + name: "sample-access-key-secret-{}".format(i) + namespace: "crossplane-system" + } + }] for i in range(count)], []) + [ + details + dxr + ] diff --git a/examples/default/resources_without_xr/composition.yaml b/examples/default/resources_without_xr/composition.yaml index ad3f936..1b612c2 100644 --- a/examples/default/resources_without_xr/composition.yaml +++ b/examples/default/resources_without_xr/composition.yaml @@ -1,67 +1,65 @@ apiVersion: apiextensions.crossplane.io/v1 kind: Composition metadata: - name: function-template-go + name: kcl-function spec: compositeTypeRef: apiVersion: example.crossplane.io/v1beta1 kind: XR mode: Pipeline pipeline: - - step: normal - functionRef: - name: kcl-function - input: - apiVersion: krm.kcl.dev/v1alpha1 - kind: KCLInput - metadata: - name: basic - spec: - source: | - import base64 + - step: normal + functionRef: + name: kcl-function + input: + apiVersion: krm.kcl.dev/v1alpha1 + kind: KCLInput + spec: + source: | + import base64 - oxr = option("params").oxr - count = oxr.spec.count or 1 - ocds = option("params").ocds - dxr = { - **option("params").dxr - status.dummy = "cool-status" - } - details = { - apiVersion: "meta.krm.kcl.dev/v1alpha1" - kind: "CompositeConnectionDetails" - if "sample-access-key-0" in ocds: - data: { - username = ocds["sample-access-key-0"].ConnectionDetails.username - password = ocds["sample-access-key-0"].ConnectionDetails.password - url = base64.encode("http://www.example.com") - } - else: - data: {} - } - items = sum([[{ - apiVersion: "iam.aws.upbound.io/v1beta1" - kind: "User" - metadata.name = "test-user-{}".format(i) - metadata.labels: { - "testing.upbound.io/example-name" = "test-user-{}".format(i) - if "test-user-{}".format(i) in ocds: - dummy = ocds["test-user-{}".format(i)].Resource.metadata.labels.dummy - else: - dummy = "foo" - } - spec.forProvider: {} - }, { - apiVersion: "iam.aws.upbound.io/v1beta1" - kind: "AccessKey" - metadata.name = "sample-access-key-{}".format(i) - spec.forProvider.userSelector.matchLabels: { - "testing.upbound.io/example-name" = "test-user-{}".format(i) - } - spec.writeConnectionSecretToRef: { - name: "sample-access-key-secret-{}".format(i) - namespace: "crossplane-system" - } - }] for i in range(count)], []) + [ - details - ] + oxr = option("params").oxr + count = oxr.spec.count or 1 + ocds = option("params").ocds + dxr = { + **option("params").dxr + status.dummy = "cool-status" + } + details = { + apiVersion: "meta.krm.kcl.dev/v1alpha1" + kind: "CompositeConnectionDetails" + if "sample-access-key-0" in ocds: + data: { + username = ocds["sample-access-key-0"].ConnectionDetails.username + password = ocds["sample-access-key-0"].ConnectionDetails.password + url = base64.encode("http://www.example.com") + } + else: + data: {} + } + items = sum([[{ + apiVersion: "iam.aws.upbound.io/v1beta1" + kind: "User" + metadata.name = "test-user-{}".format(i) + metadata.labels: { + "testing.upbound.io/example-name" = "test-user-{}".format(i) + if "test-user-{}".format(i) in ocds: + dummy = ocds["test-user-{}".format(i)].Resource.metadata.labels.dummy + else: + dummy = "foo" + } + spec.forProvider: {} + }, { + apiVersion: "iam.aws.upbound.io/v1beta1" + kind: "AccessKey" + metadata.name = "sample-access-key-{}".format(i) + spec.forProvider.userSelector.matchLabels: { + "testing.upbound.io/example-name" = "test-user-{}".format(i) + } + spec.writeConnectionSecretToRef: { + name: "sample-access-key-secret-{}".format(i) + namespace: "crossplane-system" + } + }] for i in range(count)], []) + [ + details + ] diff --git a/examples/patch_desired/patching/composition.yaml b/examples/patch_desired/patching/composition.yaml index c4b8756..62a0ef1 100644 --- a/examples/patch_desired/patching/composition.yaml +++ b/examples/patch_desired/patching/composition.yaml @@ -1,43 +1,39 @@ apiVersion: apiextensions.crossplane.io/v1 kind: Composition metadata: - name: function-template-go + name: kcl-function spec: compositeTypeRef: apiVersion: nopexample.org/v1 kind: XSubnetwork mode: Pipeline pipeline: - - step: generate desired resources - functionRef: - name: kcl-function - input: - apiVersion: krm.kcl.dev/v1alpha1 - kind: KCLInput - metadata: - name: kcl-function-1 - spec: - source: | - { - apiVersion: "v1" - kind: "XR" - metadata.annotations: { - "krm.kcl.dev/composition-resource-name" = "bucket" - } - spec.forProvider.network: "some-network" - } - - step: patch desired resources - functionRef: - name: kcl-function - input: - apiVersion: krm.kcl.dev/v1alpha1 - kind: KCLInput - metadata: - name: kcl-function-2 - spec: - target: PatchDesired - source: | - { - metadata.name = "bucket" - spec.forProvider.network: "some-override-network" - } + - step: generate desired resources + functionRef: + name: kcl-function + input: + apiVersion: krm.kcl.dev/v1alpha1 + kind: KCLInput + spec: + source: | + { + apiVersion: "v1" + kind: "XR" + metadata.annotations: { + "krm.kcl.dev/composition-resource-name" = "bucket" + } + spec.forProvider.network: "some-network" + } + - step: patch desired resources + functionRef: + name: kcl-function + input: + apiVersion: krm.kcl.dev/v1alpha1 + kind: KCLInput + spec: + target: PatchDesired + source: | + { + metadata.name = "bucket" + spec.forProvider.network: "some-override-network" + } diff --git a/examples/patch_desired/patching_multiple/composition.yaml b/examples/patch_desired/patching_multiple/composition.yaml index 045b4ed..6103ac8 100644 --- a/examples/patch_desired/patching_multiple/composition.yaml +++ b/examples/patch_desired/patching_multiple/composition.yaml @@ -1,51 +1,47 @@ apiVersion: apiextensions.crossplane.io/v1 kind: Composition metadata: - name: function-template-go + name: kcl-function spec: compositeTypeRef: apiVersion: nopexample.org/v1 kind: XSubnetwork mode: Pipeline pipeline: - - step: generate desired resources - functionRef: - name: kcl-function - input: - apiVersion: krm.kcl.dev/v1alpha1 - kind: KCLInput - metadata: - name: kcl-function-1 - spec: - source: | - items = [{ - apiVersion: "v1" - kind: "XR" - metadata.annotations: { - "krm.kcl.dev/composition-resource-name" = "bucket1" - } - spec.forProvider.network: "some-network" - }, { - apiVersion: "v1" - kind: "XR" - metadata.name = "bucket2" - spec.forProvider.network: "some-network" - }] - - step: patch desired resources - functionRef: - name: kcl-function - input: - apiVersion: krm.kcl.dev/v1alpha1 - kind: KCLInput - metadata: - name: kcl-function-2 - spec: - target: PatchDesired - source: | - items = [{ - metadata.name = "bucket1" - spec.forProvider.network: "some-override-network1" - }, { - metadata.name = "bucket2" - spec.forProvider.network: "some-override-network2" - }] + - step: generate desired resources + functionRef: + name: kcl-function + input: + apiVersion: krm.kcl.dev/v1alpha1 + kind: KCLInput + spec: + source: | + items = [{ + apiVersion: "v1" + kind: "XR" + metadata.annotations: { + "krm.kcl.dev/composition-resource-name" = "bucket1" + } + spec.forProvider.network: "some-network" + }, { + apiVersion: "v1" + kind: "XR" + metadata.name = "bucket2" + spec.forProvider.network: "some-network" + }] + - step: patch desired resources + functionRef: + name: kcl-function + input: + apiVersion: krm.kcl.dev/v1alpha1 + kind: KCLInput + spec: + target: PatchDesired + source: | + items = [{ + metadata.name = "bucket1" + spec.forProvider.network: "some-override-network1" + }, { + metadata.name = "bucket2" + spec.forProvider.network: "some-override-network2" + }] diff --git a/examples/patch_resources/patching/composition.yaml b/examples/patch_resources/patching/composition.yaml index e2b7093..d3d3e75 100644 --- a/examples/patch_resources/patching/composition.yaml +++ b/examples/patch_resources/patching/composition.yaml @@ -1,36 +1,34 @@ apiVersion: apiextensions.crossplane.io/v1 kind: Composition metadata: - name: function-template-go + name: kcl-function 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: KCLInput - 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" - } + - step: normal + functionRef: + name: kcl-function + input: + apiVersion: krm.kcl.dev/v1alpha1 + kind: KCLInput + 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" + } diff --git a/examples/patch_resources/patching_multiple/composition.yaml b/examples/patch_resources/patching_multiple/composition.yaml index 0fe046d..1fd0004 100644 --- a/examples/patch_resources/patching_multiple/composition.yaml +++ b/examples/patch_resources/patching_multiple/composition.yaml @@ -1,69 +1,67 @@ apiVersion: apiextensions.crossplane.io/v1 kind: Composition metadata: - name: function-template-go + name: kcl-function 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: KCLInput - 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" - } - ] + - step: normal + functionRef: + name: kcl-function + input: + apiVersion: krm.kcl.dev/v1alpha1 + kind: KCLInput + 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" + } + ] diff --git a/examples/resources/basic/composition.yaml b/examples/resources/basic/composition.yaml index 4d01dbe..43cba43 100644 --- a/examples/resources/basic/composition.yaml +++ b/examples/resources/basic/composition.yaml @@ -1,29 +1,27 @@ apiVersion: apiextensions.crossplane.io/v1 kind: Composition metadata: - name: function-template-go + name: kcl-function 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: KCLInput - metadata: - name: basic - spec: - target: Resources - source: | - { - apiVersion: "ec2.aws.upbound.io/v1beta1" - kind: "Instance" - metadata.name = "instance" - spec.forProvider.ami: "ami-0d9858aa3c6322f73" - spec.forProvider.instanceType: "t2.micro" - spec.forProvider.region: "us-east-2" - } + - step: normal + functionRef: + name: kcl-function + input: + apiVersion: krm.kcl.dev/v1alpha1 + kind: KCLInput + spec: + target: Resources + source: | + { + apiVersion: "ec2.aws.upbound.io/v1beta1" + kind: "Instance" + metadata.name = "instance" + spec.forProvider.ami: "ami-0d9858aa3c6322f73" + spec.forProvider.instanceType: "t2.micro" + spec.forProvider.region: "us-east-2" + } diff --git a/examples/resources/condition/composition.yaml b/examples/resources/condition/composition.yaml index 885cf85..c5c9f5f 100644 --- a/examples/resources/condition/composition.yaml +++ b/examples/resources/condition/composition.yaml @@ -1,41 +1,39 @@ apiVersion: apiextensions.crossplane.io/v1 kind: Composition metadata: - name: function-template-go + name: kcl-function spec: compositeTypeRef: apiVersion: nopexample.org/v1 kind: XNopResource mode: Pipeline pipeline: - - step: normal - functionRef: - name: kcl-function - input: - apiVersion: krm.kcl.dev/v1alpha1 - kind: KCLInput - metadata: - name: basic - spec: - target: Resources - params: - name: "input-instance" - source: | - env: str = option("params").oxr.spec.provider - items = [ - { - if env == "aws": - apiVersion = "eks.nobu.dev/v1beta" - if env == "gcp": - apiVersion = "gke.nobu.dev/v1beta1" - kind = "XNodepool" - spec.parameters: { - autoscaling: [{ - maxNodeCount: 1 - minNodeCount: 1 - }] - clusterName: "example-injections" - region: "us-east-2" - } - } - ] + - step: normal + functionRef: + name: kcl-function + input: + apiVersion: krm.kcl.dev/v1alpha1 + kind: KCLInput + spec: + target: Resources + params: + name: "input-instance" + source: | + env: str = option("params").oxr.spec.provider + items = [ + { + if env == "aws": + apiVersion = "eks.nobu.dev/v1beta" + if env == "gcp": + apiVersion = "gke.nobu.dev/v1beta1" + kind = "XNodepool" + spec.parameters: { + autoscaling: [{ + maxNodeCount: 1 + minNodeCount: 1 + }] + clusterName: "example-injections" + region: "us-east-2" + } + } + ] diff --git a/examples/resources/custom_composition_resource_name/composition.yaml b/examples/resources/custom_composition_resource_name/composition.yaml index f4a8dc8..8142151 100644 --- a/examples/resources/custom_composition_resource_name/composition.yaml +++ b/examples/resources/custom_composition_resource_name/composition.yaml @@ -1,31 +1,29 @@ apiVersion: apiextensions.crossplane.io/v1 kind: Composition metadata: - name: function-template-go + name: kcl-function 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: KCLInput - metadata: - name: basic - spec: - source: | - { - apiVersion: "ec2.aws.upbound.io/v1beta1" - kind: "Instance" - metadata.name = "instance" - metadata.annotations = { - "krm.kcl.dev/composition-resource-name" = "custom-composition-resource-name" - } - spec.forProvider.ami: "ami-0d9858aa3c6322f73" - spec.forProvider.instanceType: "t2.micro" - spec.forProvider.region: "us-east-2" - } + - step: normal + functionRef: + name: kcl-function + input: + apiVersion: krm.kcl.dev/v1alpha1 + kind: KCLInput + spec: + source: | + { + apiVersion: "ec2.aws.upbound.io/v1beta1" + kind: "Instance" + metadata.name = "instance" + metadata.annotations = { + "krm.kcl.dev/composition-resource-name" = "custom-composition-resource-name" + } + spec.forProvider.ami: "ami-0d9858aa3c6322f73" + spec.forProvider.instanceType: "t2.micro" + spec.forProvider.region: "us-east-2" + } diff --git a/examples/resources/custom_external_name/composition.yaml b/examples/resources/custom_external_name/composition.yaml index 6e01e53..b5c2ed9 100644 --- a/examples/resources/custom_external_name/composition.yaml +++ b/examples/resources/custom_external_name/composition.yaml @@ -1,31 +1,29 @@ apiVersion: apiextensions.crossplane.io/v1 kind: Composition metadata: - name: function-template-go + name: kcl-function 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: KCLInput - metadata: - name: basic - spec: - source: | - { - apiVersion: "ec2.aws.upbound.io/v1beta1" - kind: "Instance" - metadata.name = "instance" - metadata.annotations = { - "crossplane.io/external-name" = "custom-external-name" - } - spec.forProvider.ami: "ami-0d9858aa3c6322f73" - spec.forProvider.instanceType: "t2.micro" - spec.forProvider.region: "us-east-2" - } + - step: normal + functionRef: + name: kcl-function + input: + apiVersion: krm.kcl.dev/v1alpha1 + kind: KCLInput + spec: + source: | + { + apiVersion: "ec2.aws.upbound.io/v1beta1" + kind: "Instance" + metadata.name = "instance" + metadata.annotations = { + "crossplane.io/external-name" = "custom-external-name" + } + spec.forProvider.ami: "ami-0d9858aa3c6322f73" + spec.forProvider.instanceType: "t2.micro" + spec.forProvider.region: "us-east-2" + } diff --git a/examples/resources/database/composition.yaml b/examples/resources/database/composition.yaml index 8c5dc66..79aeaac 100644 --- a/examples/resources/database/composition.yaml +++ b/examples/resources/database/composition.yaml @@ -1,7 +1,7 @@ apiVersion: apiextensions.crossplane.io/v1 kind: Composition metadata: - name: xlabels.fn-demo.crossplane.io + name: kcl-function labels: provider: aws spec: @@ -11,27 +11,25 @@ spec: kind: Database mode: Pipeline pipeline: - - step: normal - functionRef: - name: kcl-function - input: - apiVersion: krm.kcl.dev/v1alpha1 - kind: KCLInput - metadata: - name: basic - spec: - target: Resources - source: | - items = [{ - apiVersion: "sql.gcp.upbound.io/v1beta1" - kind: "DatabaseInstance" - spec: { - forProvider: { - project: "test-project" - settings: [{databaseFlags: [{ - name: "log_checkpoints" - value: "on" - }]}] - } - } - }] + - step: normal + functionRef: + name: kcl-function + input: + apiVersion: krm.kcl.dev/v1alpha1 + kind: KCLInput + spec: + target: Resources + source: | + items = [{ + apiVersion: "sql.gcp.upbound.io/v1beta1" + kind: "DatabaseInstance" + spec: { + forProvider: { + project: "test-project" + settings: [{databaseFlags: [{ + name: "log_checkpoints" + value: "on" + }]}] + } + } + }] diff --git a/examples/resources/format/composition.yaml b/examples/resources/format/composition.yaml index 006f04c..a36b995 100644 --- a/examples/resources/format/composition.yaml +++ b/examples/resources/format/composition.yaml @@ -1,40 +1,38 @@ apiVersion: apiextensions.crossplane.io/v1 kind: Composition metadata: - name: function-template-go + name: kcl-function spec: compositeTypeRef: apiVersion: nopexample.org/v1 kind: XNopResource mode: Pipeline pipeline: - - step: normal - functionRef: - name: kcl-function - input: - apiVersion: krm.kcl.dev/v1alpha1 - kind: KCLInput - metadata: - name: basic - spec: - target: Resources - params: - name_suffix: 1 - source: | - name_suffix: str = str(option("params").name_suffix) or "" - name_suffix_with_line: str = "-{}".format(name_suffix) if name_suffix else "" - items = [ - { - apiVersion = "eks.nobu.dev/v1beta" - kind = "XNodepool" - metadata.name = "pool" + name_suffix_with_line - spec.parameters: { - autoscaling: [{ - maxNodeCount: 1 - minNodeCount: 1 - }] - clusterName: "example-injections" - region: "us-east-2" - } - } - ] + - step: normal + functionRef: + name: kcl-function + input: + apiVersion: krm.kcl.dev/v1alpha1 + kind: KCLInput + spec: + target: Resources + params: + name_suffix: 1 + source: | + name_suffix: str = str(option("params").name_suffix) or "" + name_suffix_with_line: str = "-{}".format(name_suffix) if name_suffix else "" + items = [ + { + apiVersion = "eks.nobu.dev/v1beta" + kind = "XNodepool" + metadata.name = "pool" + name_suffix_with_line + spec.parameters: { + autoscaling: [{ + maxNodeCount: 1 + minNodeCount: 1 + }] + clusterName: "example-injections" + region: "us-east-2" + } + } + ] diff --git a/examples/resources/loop/composition.yaml b/examples/resources/loop/composition.yaml index 421db6b..aece43d 100644 --- a/examples/resources/loop/composition.yaml +++ b/examples/resources/loop/composition.yaml @@ -1,34 +1,32 @@ apiVersion: apiextensions.crossplane.io/v1 kind: Composition metadata: - name: function-template-go + name: kcl-function 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: KCLInput - metadata: - name: basic - spec: - target: Resources - params: - name: "input-instance" - source: | - regions = ["us-east-1", "us-east-2"] - items = [{ - apiVersion: "ec2.aws.upbound.io/v1beta1" - kind: "Instance" - metadata.name = "instance-" + r - spec.forProvider: { - ami: "ami-0d9858aa3c6322f73" - instanceType: "t2.micro" - region: r - } - } for r in regions] + - step: normal + functionRef: + name: kcl-function + input: + apiVersion: krm.kcl.dev/v1alpha1 + kind: KCLInput + spec: + target: Resources + params: + name: "input-instance" + source: | + regions = ["us-east-1", "us-east-2"] + items = [{ + apiVersion: "ec2.aws.upbound.io/v1beta1" + kind: "Instance" + metadata.name = "instance-" + r + spec.forProvider: { + ami: "ami-0d9858aa3c6322f73" + instanceType: "t2.micro" + region: r + } + } for r in regions] diff --git a/examples/resources/network/composition.yaml b/examples/resources/network/composition.yaml index f3ef7be..a390438 100644 --- a/examples/resources/network/composition.yaml +++ b/examples/resources/network/composition.yaml @@ -1,7 +1,7 @@ apiVersion: apiextensions.crossplane.io/v1 kind: Composition metadata: - name: xlabels.fn-demo.crossplane.io + name: kcl-function labels: provider: aws spec: @@ -11,41 +11,39 @@ spec: kind: Network mode: Pipeline pipeline: - - step: normal - functionRef: - name: kcl-function - input: - apiVersion: krm.kcl.dev/v1alpha1 - kind: KCLInput - metadata: - name: basic - spec: - target: Resources - source: | - # Get the XR spec fields - id = option("params")?.oxr?.spec.id or "" - # Render XR to crossplane managed resources - network_id_labels = {"networks.meta.fn.crossplane.io/network-id" = id} if id else {} - vpc = { - apiVersion = "ec2.aws.upbound.io/v1beta1" - kind = "VPC" - metadata.name = "vpc" - metadata.labels: network_id_labels - spec.forProvider = { - region = "eu-west-1" - cidrBlock = "192.168.0.0/16" - enableDnsSupport = True - enableDnsHostnames = True - } - } - gateway = { - apiVersion = "ec2.aws.upbound.io/v1beta1" - kind = "InternetGateway" - metadata.name = "gateway" - metadata.labels: network_id_labels - spec.forProvider = { - region = "eu-west-1" - vpcIdSelector.matchControllerRef = True - } - } - items = [vpc, gateway] + - step: normal + functionRef: + name: kcl-function + input: + apiVersion: krm.kcl.dev/v1alpha1 + kind: KCLInput + spec: + target: Resources + source: | + # Get the XR spec fields + id = option("params")?.oxr?.spec.id or "" + # Render XR to crossplane managed resources + network_id_labels = {"networks.meta.fn.crossplane.io/network-id" = id} if id else {} + vpc = { + apiVersion = "ec2.aws.upbound.io/v1beta1" + kind = "VPC" + metadata.name = "vpc" + metadata.labels: network_id_labels + spec.forProvider = { + region = "eu-west-1" + cidrBlock = "192.168.0.0/16" + enableDnsSupport = True + enableDnsHostnames = True + } + } + gateway = { + apiVersion = "ec2.aws.upbound.io/v1beta1" + kind = "InternetGateway" + metadata.name = "gateway" + metadata.labels: network_id_labels + spec.forProvider = { + region = "eu-west-1" + vpcIdSelector.matchControllerRef = True + } + } + items = [vpc, gateway] diff --git a/examples/resources/network/git_composition.yaml b/examples/resources/network/git_composition.yaml index fe361d1..a2d6f5e 100644 --- a/examples/resources/network/git_composition.yaml +++ b/examples/resources/network/git_composition.yaml @@ -1,7 +1,7 @@ apiVersion: apiextensions.crossplane.io/v1 kind: Composition metadata: - name: xlabels.fn-demo.crossplane.io + name: kcl-function labels: provider: aws spec: @@ -11,14 +11,12 @@ spec: kind: Network mode: Pipeline pipeline: - - step: normal - functionRef: - name: kcl-function - input: - apiVersion: krm.kcl.dev/v1alpha1 - kind: KCLInput - metadata: - name: basic - spec: - target: Resources - source: github.com/kcl-lang/modules/crossplane-xnetwork-kcl-function + - step: normal + functionRef: + name: kcl-function + input: + apiVersion: krm.kcl.dev/v1alpha1 + kind: KCLInput + spec: + target: Resources + source: github.com/kcl-lang/modules/crossplane-xnetwork-kcl-function diff --git a/examples/resources/network/local_composition.yaml b/examples/resources/network/local_composition.yaml index d1ebed7..fe192ac 100644 --- a/examples/resources/network/local_composition.yaml +++ b/examples/resources/network/local_composition.yaml @@ -1,7 +1,7 @@ apiVersion: apiextensions.crossplane.io/v1 kind: Composition metadata: - name: xlabels.fn-demo.crossplane.io + name: kcl-function labels: provider: aws spec: @@ -11,14 +11,12 @@ spec: kind: Network mode: Pipeline pipeline: - - step: normal - functionRef: - name: kcl-function - input: - apiVersion: krm.kcl.dev/v1alpha1 - kind: KCLInput - metadata: - name: basic - spec: - target: Resources - source: ./examples/resources/network/composition.k + - step: normal + functionRef: + name: kcl-function + input: + apiVersion: krm.kcl.dev/v1alpha1 + kind: KCLInput + spec: + target: Resources + source: ./examples/resources/network/composition.k diff --git a/examples/resources/network/oci_composition.yaml b/examples/resources/network/oci_composition.yaml index d383285..2729c3d 100644 --- a/examples/resources/network/oci_composition.yaml +++ b/examples/resources/network/oci_composition.yaml @@ -1,7 +1,7 @@ apiVersion: apiextensions.crossplane.io/v1 kind: Composition metadata: - name: xlabels.fn-demo.crossplane.io + name: kcl-function labels: provider: aws spec: @@ -11,14 +11,12 @@ spec: kind: Network mode: Pipeline pipeline: - - step: normal - functionRef: - name: kcl-function - input: - apiVersion: krm.kcl.dev/v1alpha1 - kind: KCLInput - metadata: - name: basic - spec: - target: Resources - source: oci://ghcr.io/kcl-lang/crossplane-xnetwork-kcl-function + - step: normal + functionRef: + name: kcl-function + input: + apiVersion: krm.kcl.dev/v1alpha1 + kind: KCLInput + spec: + target: Resources + source: oci://ghcr.io/kcl-lang/crossplane-xnetwork-kcl-function diff --git a/examples/resources/options/composition.yaml b/examples/resources/options/composition.yaml index 950f92c..4910047 100644 --- a/examples/resources/options/composition.yaml +++ b/examples/resources/options/composition.yaml @@ -1,33 +1,31 @@ apiVersion: apiextensions.crossplane.io/v1 kind: Composition metadata: - name: function-template-go + name: kcl-function 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: KCLInput - metadata: - name: basic - spec: - target: Resources - params: - name: "input-instance" - source: | - { - apiVersion: "ec2.aws.upbound.io/v1beta1" - kind: "Instance" - metadata.name = option("params").name - spec.forProvider: { - ami: "ami-0d9858aa3c6322f73" - instanceType: "t2.micro" - region: "us-east-2" - } - } + - step: normal + functionRef: + name: kcl-function + input: + apiVersion: krm.kcl.dev/v1alpha1 + kind: KCLInput + spec: + target: Resources + params: + name: "input-instance" + source: | + { + apiVersion: "ec2.aws.upbound.io/v1beta1" + kind: "Instance" + metadata.name = option("params").name + spec.forProvider: { + ami: "ami-0d9858aa3c6322f73" + instanceType: "t2.micro" + region: "us-east-2" + } + } diff --git a/examples/resources/options_oxr/composition.yaml b/examples/resources/options_oxr/composition.yaml index 5e4e292..7ac76eb 100644 --- a/examples/resources/options_oxr/composition.yaml +++ b/examples/resources/options_oxr/composition.yaml @@ -1,35 +1,33 @@ apiVersion: apiextensions.crossplane.io/v1 kind: Composition metadata: - name: function-template-go + name: kcl-function 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: KCLInput - metadata: - name: basic - spec: - target: Resources - params: - name: "input-instance" - source: | - oxr = option("params").oxr - # Return YAML list and append to dxr. - items = [{ - apiVersion: "ec2.aws.upbound.io/v1beta1" - kind: "Instance" - metadata.name = oxr.metadata.name - spec.forProvider: { - ami: "ami-0d9858aa3c6322f73" - instanceType: "t2.micro" - region: "us-east-2" - } - }] + - step: normal + functionRef: + name: kcl-function + input: + apiVersion: krm.kcl.dev/v1alpha1 + kind: KCLInput + spec: + target: Resources + params: + name: "input-instance" + source: | + oxr = option("params").oxr + # Return YAML list and append to dxr. + items = [{ + apiVersion: "ec2.aws.upbound.io/v1beta1" + kind: "Instance" + metadata.name = oxr.metadata.name + spec.forProvider: { + ami: "ami-0d9858aa3c6322f73" + instanceType: "t2.micro" + region: "us-east-2" + } + }] diff --git a/examples/resources/pass_data/composition.yaml b/examples/resources/pass_data/composition.yaml index 78c8475..551d496 100644 --- a/examples/resources/pass_data/composition.yaml +++ b/examples/resources/pass_data/composition.yaml @@ -1,42 +1,38 @@ apiVersion: apiextensions.crossplane.io/v1 kind: Composition metadata: - name: function-template-go + name: kcl-function spec: compositeTypeRef: apiVersion: nopexample.org/v1 kind: XSubnetwork mode: Pipeline pipeline: - - step: normal1 - functionRef: - name: kcl-function - input: - apiVersion: krm.kcl.dev/v1alpha1 - kind: KCLInput - metadata: - name: basic - spec: - target: Resources - source: | - { - apiVersion: "nopexample.org/v1" - metadata.name = "resource1" - spec.atProvider.network: "somenetwork" - } - - step: normal2 - functionRef: - name: kcl-function - input: - apiVersion: krm.kcl.dev/v1alpha1 - kind: KCLInput - metadata: - name: basic - spec: - target: Resources - source: | - { - apiVersion: "nopexample.org/v1" - metadata.name = "resource2" - spec.forProvider = option("params").dcds["resource1"].Resource.spec.atProvider - } + - step: normal1 + functionRef: + name: kcl-function + input: + apiVersion: krm.kcl.dev/v1alpha1 + kind: KCLInput + spec: + target: Resources + source: | + { + apiVersion: "nopexample.org/v1" + metadata.name = "resource1" + spec.atProvider.network: "somenetwork" + } + - step: normal2 + functionRef: + name: kcl-function + input: + apiVersion: krm.kcl.dev/v1alpha1 + kind: KCLInput + spec: + target: Resources + source: | + { + apiVersion: "nopexample.org/v1" + metadata.name = "resource2" + spec.forProvider = option("params").dcds["resource1"].Resource.spec.atProvider + } diff --git a/examples/resources/regex/composition.yaml b/examples/resources/regex/composition.yaml index d0a4005..e3e0ed4 100644 --- a/examples/resources/regex/composition.yaml +++ b/examples/resources/regex/composition.yaml @@ -1,42 +1,40 @@ apiVersion: apiextensions.crossplane.io/v1 kind: Composition metadata: - name: function-template-go + name: kcl-function spec: compositeTypeRef: apiVersion: nopexample.org/v1 kind: XNopResource mode: Pipeline pipeline: - - step: normal - functionRef: - name: kcl-function - input: - apiVersion: krm.kcl.dev/v1alpha1 - kind: KCLInput - metadata: - name: basic - spec: - target: Resources - params: - name: name - source: | - import regex + - step: normal + functionRef: + name: kcl-function + input: + apiVersion: krm.kcl.dev/v1alpha1 + kind: KCLInput + spec: + target: Resources + params: + name: name + source: | + import regex - name: str = option("params").name or "" - assert regex.match(name, r"[A-Za-z_][A-Za-z0-9_]*"), "invalid name: ${name}, expected the regex [A-Za-z_][A-Za-z0-9_]*" - items = [ - { - apiVersion = "eks.nobu.dev/v1beta" - kind = "XNodepool" - metadata.name = name - spec.parameters: { - autoscaling: [{ - maxNodeCount: 1 - minNodeCount: 1 - }] - clusterName: "example-injections" - region: "us-east-2" - } - } - ] + name: str = option("params").name or "" + assert regex.match(name, r"[A-Za-z_][A-Za-z0-9_]*"), "invalid name: ${name}, expected the regex [A-Za-z_][A-Za-z0-9_]*" + items = [ + { + apiVersion = "eks.nobu.dev/v1beta" + kind = "XNodepool" + metadata.name = name + spec.parameters: { + autoscaling: [{ + maxNodeCount: 1 + minNodeCount: 1 + }] + clusterName: "example-injections" + region: "us-east-2" + } + } + ] diff --git a/examples/xr/patching/composition.yaml b/examples/xr/patching/composition.yaml index 779c3fe..289d03a 100644 --- a/examples/xr/patching/composition.yaml +++ b/examples/xr/patching/composition.yaml @@ -1,29 +1,27 @@ apiVersion: apiextensions.crossplane.io/v1 kind: Composition metadata: - name: function-template-go + name: kcl-function spec: compositeTypeRef: apiVersion: nopexample.org/v1 kind: XSubnetwork mode: Pipeline pipeline: - - step: normal - functionRef: - name: kcl-function - input: - apiVersion: krm.kcl.dev/v1alpha1 - kind: KCLInput - metadata: - name: basic - spec: - target: XR - source: | - { - metadata.annotations: { - "nobu.dev/cueified": "true", - "nobu.dev/app": "someapp", - } - spec.forProvider.network: "somenetwork" - status.is_ok = True - } + - step: normal + functionRef: + name: kcl-function + input: + apiVersion: krm.kcl.dev/v1alpha1 + kind: KCLInput + spec: + target: XR + source: | + { + metadata.annotations: { + "nobu.dev/cueified": "true", + "nobu.dev/app": "someapp", + } + spec.forProvider.network: "somenetwork" + status.is_ok = True + } diff --git a/fn.go b/fn.go index 6e4dbd2..e24322b 100644 --- a/fn.go +++ b/fn.go @@ -18,7 +18,7 @@ import ( "github.com/crossplane/function-sdk-go/request" "github.com/crossplane/function-sdk-go/response" - "github.com/crossplane-contrib/function-kcl/input/v1beta1" + fkcl "github.com/crossplane-contrib/function-kcl/input/v1alpha1" pkgresource "github.com/crossplane-contrib/function-kcl/pkg/resource" "sigs.k8s.io/yaml" ) @@ -39,7 +39,7 @@ func (f *Function) RunFunction(_ context.Context, req *fnv1.RunFunctionRequest) log.Info("Running Function") rsp := response.To(req, response.DefaultTTL) - in := &v1beta1.KCLInput{} + in := &fkcl.KCLInput{} if err := request.GetInput(req, in); err != nil { response.Fatal(rsp, errors.Wrapf(err, "cannot get Function input from %T", req)) return rsp, nil diff --git a/input/v1beta1/input.go b/input/v1alpha1/input.go similarity index 97% rename from input/v1beta1/input.go rename to input/v1alpha1/input.go index d25ed13..432b656 100644 --- a/input/v1beta1/input.go +++ b/input/v1alpha1/input.go @@ -1,8 +1,8 @@ -// Package v1beta1 contains the input type for this Function +// Package v1alpha1 contains the input type for this Function // +kubebuilder:object:generate=true -// +groupName=template.fn.crossplane.io -// +versionName=v1beta1 -package v1beta1 +// +groupName=krm.kcl.dev +// +versionName=v1alpha1 +package v1alpha1 import ( "fmt" diff --git a/input/v1beta1/zz_generated.deepcopy.go b/input/v1alpha1/zz_generated.deepcopy.go similarity index 99% rename from input/v1beta1/zz_generated.deepcopy.go rename to input/v1alpha1/zz_generated.deepcopy.go index 7e231d7..92c0ed0 100644 --- a/input/v1beta1/zz_generated.deepcopy.go +++ b/input/v1alpha1/zz_generated.deepcopy.go @@ -2,7 +2,7 @@ // Code generated by controller-gen. DO NOT EDIT. -package v1beta1 +package v1alpha1 import ( "k8s.io/apimachinery/pkg/runtime" diff --git a/package/input/template.fn.crossplane.io_kclinputs.yaml b/package/input/krm.kcl.dev_kclinputs.yaml similarity index 98% rename from package/input/template.fn.crossplane.io_kclinputs.yaml rename to package/input/krm.kcl.dev_kclinputs.yaml index a15ac1d..27427f2 100644 --- a/package/input/template.fn.crossplane.io_kclinputs.yaml +++ b/package/input/krm.kcl.dev_kclinputs.yaml @@ -4,9 +4,9 @@ kind: CustomResourceDefinition metadata: annotations: controller-gen.kubebuilder.io/version: v0.19.0 - name: kclinputs.template.fn.crossplane.io + name: kclinputs.krm.kcl.dev spec: - group: template.fn.crossplane.io + group: krm.kcl.dev names: categories: - crossplane @@ -16,7 +16,7 @@ spec: singular: kclinput scope: Namespaced versions: - - name: v1beta1 + - name: v1alpha1 schema: openAPIV3Schema: description: KCLInput can be used to provide input to this Function.