Skip to content

Commit 3ee34d1

Browse files
committed
chore(readme): improve layout and fix typos
* make shorter lines for easier editing * fix typos * apply missing `spec` to KCLInput * remove redundant `metadata.name` from KCLInput * cspell config for spell checking Signed-off-by: Ievgenii Shepeliuk <eshepelyuk@gmail.com>
1 parent 8104923 commit 3ee34d1

File tree

2 files changed

+101
-85
lines changed

2 files changed

+101
-85
lines changed

README.md

Lines changed: 83 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66

77
## Introduction
88

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).
1013

1114
Check out these following blogs to learn more.
1215

@@ -32,25 +35,26 @@ spec:
3235
input:
3336
apiVersion: krm.kcl.dev/v1alpha1
3437
kind: KCLInput
35-
source: |
36-
# Read the XR
37-
oxr = option("params").oxr
38-
# Patch the XR with the status field
39-
dxr = {
40-
**option("params").dxr
41-
status.dummy = "cool-status"
42-
}
43-
# Construct a bucket
44-
bucket = {
45-
apiVersion = "s3.aws.upbound.io/v1beta1"
46-
kind = "Bucket"
47-
metadata.annotations: {
48-
"krm.kcl.dev/composition-resource-name" = "bucket"
49-
}
50-
spec.forProvider.region = option("oxr").spec.region
51-
}
52-
# Return the bucket and patched XR
53-
items = [bucket, dxr]
38+
spec:
39+
source: |
40+
# Read the XR
41+
oxr = option("params").oxr
42+
# Patch the XR with the status field
43+
dxr = {
44+
**option("params").dxr
45+
status.dummy = "cool-status"
46+
}
47+
# Construct a bucket
48+
bucket = {
49+
apiVersion = "s3.aws.upbound.io/v1beta1"
50+
kind = "Bucket"
51+
metadata.annotations: {
52+
"krm.kcl.dev/composition-resource-name" = "bucket"
53+
}
54+
spec.forProvider.region = option("oxr").spec.region
55+
}
56+
# Return the bucket and patched XR
57+
items = [bucket, dxr]
5458
- step: automatically-detect-ready-composed-resources
5559
functionRef:
5660
name: function-auto-ready
@@ -80,8 +84,6 @@ To use a `KCLInput` as the function config, the KCL source must be specified in
8084
```yaml
8185
apiVersion: krm.kcl.dev/v1alpha1
8286
kind: KCLInput
83-
metadata:
84-
name: basic
8587
spec:
8688
source: |
8789
{
@@ -99,8 +101,6 @@ spec:
99101
```yaml
100102
apiVersion: krm.kcl.dev/v1alpha1
101103
kind: KCLInput
102-
metadata:
103-
name: basic
104104
spec:
105105
source: oci://ghcr.io/kcl-lang/crossplane-xnetwork-kcl-function
106106
```
@@ -110,8 +110,6 @@ spec:
110110
```yaml
111111
apiVersion: krm.kcl.dev/v1alpha1
112112
kind: KCLInput
113-
metadata:
114-
name: basic
115113
spec:
116114
source: github.com/kcl-lang/modules/crossplane-xnetwork-kcl-function
117115
```
@@ -121,8 +119,6 @@ spec:
121119
```yaml
122120
apiVersion: krm.kcl.dev/v1alpha1
123121
kind: KCLInput
124-
metadata:
125-
name: basic
126122
spec:
127123
source: ./path/to/kcl/file.k
128124
```
@@ -136,6 +132,7 @@ kubectl create configmap templates --from-file=templates.k -n crossplane-system
136132
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.
137133

138134
```yaml
135+
---
139136
apiVersion: pkg.crossplane.io/v1beta1
140137
kind: Function
141138
metadata:
@@ -169,7 +166,8 @@ spec:
169166

170167
### Use as a Base Image
171168

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.
173171

174172
For example, if you have the following in `main.k`:
175173

@@ -217,7 +215,7 @@ Next, add a file specifying the dependencies to be added to all functions, using
217215
the syntax of the `[dependencies]` section of `kcl.mod`, for example:
218216

219217
```dockerfile
220-
ADD dependencies /dependecies
218+
ADD dependencies /dependencies
221219
```
222220
where the file `dependencies` contains:
223221

@@ -250,8 +248,6 @@ You can define your custom parameters in the `params` field and use `option("par
250248
```yaml
251249
apiVersion: krm.kcl.dev/v1alpha1
252250
kind: KCLInput
253-
metadata:
254-
name: basic
255251
spec:
256252
params:
257253
custom_key: custom_value
@@ -263,8 +259,6 @@ spec:
263259
```yaml
264260
apiVersion: krm.kcl.dev/v1alpha1
265261
kind: KCLInput
266-
metadata:
267-
name: kcl-xnetwork
268262
spec:
269263
params:
270264
annotations:
@@ -296,25 +290,26 @@ spec:
296290
input:
297291
apiVersion: krm.kcl.dev/v1alpha1
298292
kind: KCLInput
299-
source: |
300-
# Read the XR
301-
oxr = option("params").oxr
302-
# Patch the XR with the status field
303-
dxr = {
304-
**option("params").dxr
305-
status.dummy = "cool-status"
306-
}
307-
# Construct a bucket
308-
bucket = {
309-
apiVersion = "s3.aws.upbound.io/v1beta1"
310-
kind = "Bucket"
311-
metadata.annotations: {
312-
"krm.kcl.dev/composition-resource-name" = "bucket"
313-
}
314-
spec.forProvider.region = option("oxr").spec.region
315-
}
316-
# Return the bucket and patched XR
317-
items = [bucket, dxr]
293+
spec:
294+
source: |
295+
# Read the XR
296+
oxr = option("params").oxr
297+
# Patch the XR with the status field
298+
dxr = {
299+
**option("params").dxr
300+
status.dummy = "cool-status"
301+
}
302+
# Construct a bucket
303+
bucket = {
304+
apiVersion = "s3.aws.upbound.io/v1beta1"
305+
kind = "Bucket"
306+
metadata.annotations: {
307+
"krm.kcl.dev/composition-resource-name" = "bucket"
308+
}
309+
spec.forProvider.region = option("oxr").spec.region
310+
}
311+
# Return the bucket and patched XR
312+
items = [bucket, dxr]
318313
credentials: # If private OCI registry
319314
- name: kcl-registry
320315
source: Secret
@@ -330,7 +325,7 @@ apiVersion: v1
330325
kind: Secret
331326
metadata:
332327
name: default
333-
namsepace: default
328+
namespace: default
334329
data:
335330
username: dXNlcm5hbWU=
336331
password: cGFzc3dvcmQ=
@@ -384,8 +379,6 @@ A KRM YAML list means that each document must have an `apiVersion`, `kind` throu
384379
```yaml
385380
apiVersion: krm.kcl.dev/v1alpha1
386381
kind: KCLInput
387-
metadata:
388-
name: basic
389382
spec:
390383
source: |
391384
items = [{
@@ -406,8 +399,6 @@ spec:
406399
```yaml
407400
apiVersion: krm.kcl.dev/v1alpha1
408401
kind: KCLInput
409-
metadata:
410-
name: basic
411402
spec:
412403
source: |
413404
{
@@ -420,7 +411,9 @@ spec:
420411
}
421412
```
422413

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.
424417

425418
### Target Support
426419

@@ -437,8 +430,6 @@ This is controlled by fields on the `KCInput`
437430
```yaml
438431
apiVersion: krm.kcl.dev/v1alpha1
439432
kind: KCLInput
440-
metadata:
441-
name: basic
442433
spec:
443434
# default: Default
444435
target: Default | PatchDesired | PatchResources | Resources | XR
@@ -449,13 +440,14 @@ spec:
449440

450441
### Extract Data from a Specific Composed Resource
451442

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).
453447

454448
```yaml
455449
apiVersion: krm.kcl.dev/v1alpha1
456450
kind: KCLInput
457-
metadata:
458-
name: show-ocds
459451
spec:
460452
source: |
461453
{
@@ -469,7 +461,8 @@ spec:
469461

470462
### Composite Resource Connection Details
471463

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):
473466

474467
```yaml
475468
apiVersion: krm.kcl.dev/v1alpha1
@@ -493,13 +486,14 @@ spec:
493486
]
494487
```
495488

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:
497493

498494
```yaml
499495
apiVersion: krm.kcl.dev/v1alpha1
500496
kind: KCLInput
501-
metadata:
502-
name: basic
503497
spec:
504498
source: |
505499
import base64
@@ -520,8 +514,6 @@ To mark a desired composed resource as ready, use the `krm.kcl.dev/ready` annota
520514
```yaml
521515
apiVersion: krm.kcl.dev/v1alpha1
522516
kind: KCLInput
523-
metadata:
524-
name: basic
525517
spec:
526518
source: |
527519
# Omit other logic
@@ -536,18 +528,19 @@ spec:
536528
```
537529

538530
### 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.
540534

535+
> [!NOTE]
541536
> With ExtraResources, you can fetch cluster-scoped resources, but not namespaced resources such as claims.
542537
> 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.
545540

546541
```yaml
547542
apiVersion: krm.kcl.dev/v1alpha1
548543
kind: KCLInput
549-
metadata:
550-
name: basic
551544
spec:
552545
source: |
553546
# Omit other logic
@@ -593,6 +586,7 @@ spec:
593586
You can retrieve the extra resources either via labels with `matchLabels` or via name with `matchName: somename`.
594587

595588
This will result in Crossplane receiving the requested resources and make them available with the following format.
589+
596590
```yaml
597591
foo:
598592
- Resource:
@@ -617,14 +611,17 @@ bar:
617611
name: my-bar
618612
# Omitted for brevity
619613
```
614+
620615
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+
623622
```yaml
624623
apiVersion: krm.kcl.dev/v1alpha1
625624
kind: KCLInput
626-
metadata:
627-
name: basic
628625
spec:
629626
source: |
630627
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
641638
```yaml
642639
apiVersion: krm.kcl.dev/v1alpha1
643640
kind: KCLInput
644-
metadata:
645-
name: basic
646641
spec:
647642
source: |
648643
# Read the XR
@@ -654,17 +649,18 @@ spec:
654649

655650
### Settings conditions and events
656651

652+
> [!NOTE]
657653
> This feature requires Crossplane v1.17 or newer.
658654

659655
You can set conditions and events directly from KCL, either in the composite resource or both the composite and claim resources.
660656
To set one or more conditions, use the following approach:
657+
661658
```yaml
662659
apiVersion: krm.kcl.dev/v1alpha1
663660
kind: KCLInput
664661
metadata:
665662
annotations:
666663
"krm.kcl.dev/default_ready": "True"
667-
name: basic
668664
spec:
669665
source: |
670666
oxr = option("params").oxr
@@ -696,17 +692,19 @@ spec:
696692
]
697693
```
698694

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.
701699

702700
You can also set events as follows:
701+
703702
```yaml
704703
apiVersion: krm.kcl.dev/v1alpha1
705704
kind: KCLInput
706705
metadata:
707706
annotations:
708707
"krm.kcl.dev/default_ready": "True"
709-
name: basic
710708
spec:
711709
source: |
712710
oxr = option("params").oxr

0 commit comments

Comments
 (0)