You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+83-85Lines changed: 83 additions & 85 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,10 @@
6
6
7
7
## Introduction
8
8
9
-
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).
9
+
Crossplane KCL function allows developers to use [KCL](https://kcl-lang.io/) (a DSL)
10
+
to write composite logic without the need for repeated packaging of crossplane functions,
11
+
and we support package management and the [KRM KCL specification](https://github.com/kcl-lang/krm-kcl),
12
+
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).
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.
137
133
138
134
```yaml
135
+
---
139
136
apiVersion: pkg.crossplane.io/v1beta1
140
137
kind: Function
141
138
metadata:
@@ -169,7 +166,8 @@ spec:
169
166
170
167
### Use as a Base Image
171
168
172
-
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.
169
+
This function can also be used as a base image to build complex functions in KCL.
170
+
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.
173
171
174
172
For example, if you have the following in `main.k`:
175
173
@@ -217,7 +215,7 @@ Next, add a file specifying the dependencies to be added to all functions, using
217
215
the syntax of the `[dependencies]` section of `kcl.mod`, for example:
218
216
219
217
```dockerfile
220
-
ADD dependencies /dependecies
218
+
ADD dependencies /dependencies
221
219
```
222
220
where the file `dependencies` contains:
223
221
@@ -250,8 +248,6 @@ You can define your custom parameters in the `params` field and use `option("par
@@ -384,8 +379,6 @@ A KRM YAML list means that each document must have an `apiVersion`, `kind` throu
384
379
```yaml
385
380
apiVersion: krm.kcl.dev/v1alpha1
386
381
kind: KCLInput
387
-
metadata:
388
-
name: basic
389
382
spec:
390
383
source: |
391
384
items = [{
@@ -406,8 +399,6 @@ spec:
406
399
```yaml
407
400
apiVersion: krm.kcl.dev/v1alpha1
408
401
kind: KCLInput
409
-
metadata:
410
-
name: basic
411
402
spec:
412
403
source: |
413
404
{
@@ -420,7 +411,9 @@ spec:
420
411
}
421
412
```
422
413
423
-
> 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.
414
+
> [!NOTE]
415
+
> When returning multiple resources, we need to set different `metadata.name` or `metadata.annotations."krm.kcl.dev/composition-resource-name" `
416
+
> to distinguish between different resources in the composition functions.
424
417
425
418
### Target Support
426
419
@@ -437,8 +430,6 @@ This is controlled by fields on the `KCInput`
### Extract Data from a Specific Composed Resource
451
442
452
-
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).
443
+
To extract data from a specific composed resource by using the resource name, we can use the `option("params").ocds` variable,
444
+
`ocds`is a mapping that its key is the resource name and its value is
445
+
the [`observed composed resource`](https://pkg.go.dev/github.com/crossplane/function-sdk-go@v0.2.0/resource#ObservedComposed)
446
+
like [the example](./examples/default/read_ocds_resource/composition.yaml).
453
447
454
448
```yaml
455
449
apiVersion: krm.kcl.dev/v1alpha1
456
450
kind: KCLInput
457
-
metadata:
458
-
name: show-ocds
459
451
spec:
460
452
source: |
461
453
{
@@ -469,7 +461,8 @@ spec:
469
461
470
462
### Composite Resource Connection Details
471
463
472
-
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):
464
+
To return desired composite resource connection details, include a KCL config that produces the special CompositeConnectionDetails resource
465
+
like [the example](./examples/default/connection_details/composition.yaml):
473
466
474
467
```yaml
475
468
apiVersion: krm.kcl.dev/v1alpha1
@@ -493,13 +486,14 @@ spec:
493
486
]
494
487
```
495
488
496
-
> 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:
489
+
> [!NOTE]
490
+
> The value of the connection secret value must be base64 encoded.
491
+
> This is already the case if you are referencing a key from a managed resource's connectionDetails field.
492
+
> However, if you want to include a connection secret value from somewhere else, you will need to use the `base64.encode` function:
497
493
498
494
```yaml
499
495
apiVersion: krm.kcl.dev/v1alpha1
500
496
kind: KCLInput
501
-
metadata:
502
-
name: basic
503
497
spec:
504
498
source: |
505
499
import base64
@@ -520,8 +514,6 @@ To mark a desired composed resource as ready, use the `krm.kcl.dev/ready` annota
520
514
```yaml
521
515
apiVersion: krm.kcl.dev/v1alpha1
522
516
kind: KCLInput
523
-
metadata:
524
-
name: basic
525
517
spec:
526
518
source: |
527
519
# Omit other logic
@@ -536,18 +528,19 @@ spec:
536
528
```
537
529
538
530
### Extra resources
539
-
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.
531
+
By defining one or more special `ExtraResources`, you can ask Crossplane to retrieve additional resources from the local cluster
532
+
and make them available to your templates.
533
+
See the [docs](https://github.com/crossplane/crossplane/blob/main/design/design-doc-composition-functions-extra-resources.md) for more information.
540
534
535
+
> [!NOTE]
541
536
> With ExtraResources, you can fetch cluster-scoped resources, but not namespaced resources such as claims.
542
537
> If you need to get a composite resource via its claim name you can use `matchLabels` with `crossplane.io/claim-name: <claimname>`.
543
-
544
-
> 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.
538
+
> Namespace scoped resources can be queried with the `matchNamespace` field.
539
+
> Leaving the `matchNamespace` field empty or not defining it will query a cluster scoped resource.
545
540
546
541
```yaml
547
542
apiVersion: krm.kcl.dev/v1alpha1
548
543
kind: KCLInput
549
-
metadata:
550
-
name: basic
551
544
spec:
552
545
source: |
553
546
# Omit other logic
@@ -593,6 +586,7 @@ spec:
593
586
You can retrieve the extra resources either via labels with `matchLabels` or via name with `matchName: somename`.
594
587
595
588
This will result in Crossplane receiving the requested resources and make them available with the following format.
589
+
596
590
```yaml
597
591
foo:
598
592
- Resource:
@@ -617,14 +611,17 @@ bar:
617
611
name: my-bar
618
612
# Omitted for brevity
619
613
```
614
+
620
615
You can access the retrieved resources in your code like this:
621
-
> Note that Crossplane performs an additional reconciliation pass for extra resources.
622
-
> Consequently, during the initial execution, these resources may be uninitialized. It is essential to implement checks to handle this scenario.
616
+
617
+
> [!NOTE]
618
+
> Crossplane performs an additional reconciliation pass for extra resources.
619
+
> Consequently, during the initial execution, these resources may be uninitialized.
620
+
> It is essential to implement checks to handle this scenario.
621
+
623
622
```yaml
624
623
apiVersion: krm.kcl.dev/v1alpha1
625
624
kind: KCLInput
626
-
metadata:
627
-
name: basic
628
625
spec:
629
626
source: |
630
627
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
641
638
```yaml
642
639
apiVersion: krm.kcl.dev/v1alpha1
643
640
kind: KCLInput
644
-
metadata:
645
-
name: basic
646
641
spec:
647
642
source: |
648
643
# Read the XR
@@ -654,17 +649,18 @@ spec:
654
649
655
650
### Settings conditions and events
656
651
652
+
> [!NOTE]
657
653
> This feature requires Crossplane v1.17 or newer.
658
654
659
655
You can set conditions and events directly from KCL, either in the composite resource or both the composite and claim resources.
660
656
To set one or more conditions, use the following approach:
657
+
661
658
```yaml
662
659
apiVersion: krm.kcl.dev/v1alpha1
663
660
kind: KCLInput
664
661
metadata:
665
662
annotations:
666
663
"krm.kcl.dev/default_ready": "True"
667
-
name: basic
668
664
spec:
669
665
source: |
670
666
oxr = option("params").oxr
@@ -696,17 +692,19 @@ spec:
696
692
]
697
693
```
698
694
699
-
- **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`
700
-
- **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.
695
+
- **target**: Specifies whether the condition should be present in the composite resource or both the composite and claim resources.
696
+
Possible values are `CompositeAndClaim` and `Composite`
697
+
- **force**: Forces the overwrite of existing conditions. If a condition with the same `type` already exists, it will not be overwritten by default.
698
+
Setting force to `True` will overwrite the first condition.
0 commit comments