Skip to content

Commit 467dd83

Browse files
committed
chore: docs
Signed-off-by: Mark Altmann <[email protected]>
1 parent ac5e210 commit 467dd83

File tree

1 file changed

+87
-1
lines changed

1 file changed

+87
-1
lines changed

README.md

Lines changed: 87 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,8 @@ bar:
513513
# Omitted for brevity
514514
```
515515
You can access the retrieved resources in your code like this:
516+
> Note that Crossplane performs an additional reconciliation pass for extra resources.
517+
> Consequently, during the initial execution, these resources may be uninitialized. It is essential to implement checks to handle this scenario.
516518
```yaml
517519
apiVersion: krm.kcl.dev/v1alpha1
518520
kind: KCLInput
@@ -522,7 +524,8 @@ spec:
522524
source: |
523525
er = option("params")?.extraResources
524526
525-
name = er?.bar[0]?.Resource?.metadata?.name or ""
527+
if er?.bar:
528+
name = er?.bar[0]?.Resource?.metadata?.name or ""
526529
# Omit other logic
527530
```
528531

@@ -544,6 +547,89 @@ spec:
544547
items = [dxr] # Omit other resources
545548
```
546549

550+
### Settings conditions and events
551+
552+
> This feature requires Crossplane v1.17 or newer.
553+
554+
You can set conditions and events directly from KCL, either in the composite resource or both the composite and claim resources.
555+
To set one or more conditions, use the following approach:
556+
```yaml
557+
apiVersion: krm.kcl.dev/v1alpha1
558+
kind: KCLInput
559+
metadata:
560+
annotations:
561+
"krm.kcl.dev/default_ready": "True"
562+
name: basic
563+
spec:
564+
source: |
565+
oxr = option("params").oxr
566+
567+
dxr = {
568+
**oxr
569+
}
570+
571+
conditions = {
572+
apiVersion: "meta.krm.kcl.dev/v1alpha1"
573+
kind: "Conditions"
574+
conditions = [
575+
{
576+
target: "CompositeAndClaim"
577+
force: False
578+
condition = {
579+
type: "DatabaseReady"
580+
status: "False"
581+
reason: "FailedToCreate"
582+
message: "Encountered an error creating the database"
583+
}
584+
}
585+
]
586+
}
587+
588+
items = [
589+
conditions
590+
dxr
591+
]
592+
```
593+
594+
- **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`
595+
- **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.
596+
597+
You can also set events as follows:
598+
```yaml
599+
apiVersion: krm.kcl.dev/v1alpha1
600+
kind: KCLInput
601+
metadata:
602+
annotations:
603+
"krm.kcl.dev/default_ready": "True"
604+
name: basic
605+
spec:
606+
source: |
607+
oxr = option("params").oxr
608+
609+
dxr = {
610+
**oxr
611+
}
612+
613+
events = {
614+
apiVersion: "meta.krm.kcl.dev/v1alpha1"
615+
kind: "Events"
616+
events = [
617+
{
618+
target: "CompositeAndClaim"
619+
event = {
620+
type: "Warning"
621+
reason: "ResourceLimitExceeded"
622+
message: "The resource limit has been exceeded"
623+
}
624+
}
625+
]
626+
}
627+
items = [
628+
events
629+
dxr
630+
]
631+
```
632+
547633
## Library
548634

549635
You can directly use [KCL standard libraries](https://kcl-lang.io/docs/reference/model/overview) such as `regex.match`, `math.log`.

0 commit comments

Comments
 (0)