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
+87-1Lines changed: 87 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -513,6 +513,8 @@ bar:
513
513
# Omitted for brevity
514
514
```
515
515
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.
516
518
```yaml
517
519
apiVersion: krm.kcl.dev/v1alpha1
518
520
kind: KCLInput
@@ -522,7 +524,8 @@ spec:
522
524
source: |
523
525
er = option("params")?.extraResources
524
526
525
-
name = er?.bar[0]?.Resource?.metadata?.name or ""
527
+
if er?.bar:
528
+
name = er?.bar[0]?.Resource?.metadata?.name or ""
526
529
# Omit other logic
527
530
```
528
531
@@ -544,6 +547,89 @@ spec:
544
547
items = [dxr] # Omit other resources
545
548
```
546
549
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
+
547
633
## Library
548
634
549
635
You can directly use [KCL standard libraries](https://kcl-lang.io/docs/reference/model/overview) such as `regex.match`, `math.log`.
0 commit comments