Skip to content

Commit 41d33a6

Browse files
committed
feat: add crossplane function KCL utilities package
Signed-off-by: suin <[email protected]>
1 parent 8c6a372 commit 41d33a6

File tree

4 files changed

+126
-0
lines changed

4 files changed

+126
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# crossplane_function_kcl_utils
2+
3+
A KCL package that provides schemas and utility functions for writing safer and more productive Crossplane Functions in KCL. This module enhances type safety and IDE support when working with function-kcl.
4+
5+
## Installation
6+
7+
To install this package, run the following command:
8+
9+
```bash
10+
kcl mod add oci://ghcr.io/appthrust/kcl/crossplane_function_kcl_utils
11+
```
12+
13+
## Usage
14+
15+
### get_params()
16+
17+
The `get_params()` function provides type-safe access to the function pipeline's parameters. While `option("params")` returns `any` type, this function returns a strongly-typed `Params` schema.
18+
19+
```python kcl
20+
import crossplane_function_kcl_utils as utils
21+
22+
# Get type-safe params
23+
params = utils.get_params()
24+
25+
# Access params with IDE support
26+
print(params.oxr) # Observed composite resource
27+
print(params.ocds) # Observed composed resources
28+
print(params.dxr) # Desired composite resource
29+
print(params.dcds) # Desired composed resources
30+
print(params.ctx) # Pipeline context
31+
print(params.extraResources) # Extra resources
32+
```
33+
34+
### Params Schema
35+
36+
The `Params` schema provides a type-safe structure for function pipeline parameters:
37+
38+
```python kcl
39+
schema Params:
40+
"""
41+
Params are the input parameters for the function pipeline.
42+
"""
43+
oxr: Resource # Observed composite resource (XR)
44+
ocds: {str:Composite} # Observed composed resources
45+
dxr: Resource # Desired composite resource (XR)
46+
dcds: {str:Composite} # Desired composed resources
47+
ctx: any # Function pipeline's context
48+
extraResources: {str:[Composite]} # Extra resources
49+
```
50+
51+
Note: A composed resource can be a managed resource, ProviderConfig, composite resource, or any other Crossplane resource.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[package]
2+
name = "crossplane_function_kcl_utils"
3+
edition = "v0.10.0"
4+
version = "0.0.1"

crossplane_function_kcl_utils/kcl.mod.lock

Whitespace-only changes.
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
"""
2+
This module provides schemas and utility functions for writing safer and more productive Crossplane Functions in KCL.
3+
"""
4+
type Resource = any
5+
6+
schema Composite:
7+
"""A composed resource in Crossplane."""
8+
Resource: Resource
9+
10+
schema Params:
11+
"""
12+
Params are the input parameters for the function pipeline.
13+
14+
Attributes
15+
----------
16+
oxr : Resource, default is None
17+
Observed composite resource (XR).
18+
ocds : {str:Composite}, default is None
19+
Key-value of the observed state of a composed resource. The key is the name of the composed resource.
20+
Note: A composed resource is not just a managed resource - it can also be a ProviderConfig, another composite resource, or any other Crossplane resource.
21+
dxr : Resource, default is None
22+
Desired composite resource (XR).
23+
dcds : {str:Composite}, default is None
24+
Key-value of the desired state of a composed resource. The key is the name of the composed resource.
25+
Note: A composed resource is not just a managed resource - it can also be a ProviderConfig, another composite resource, or any other Crossplane resource.
26+
ctx : any, default is None
27+
Function pipeline's context
28+
extraResources : {str:[Composite]}, default is None
29+
Extra resources. The key is the name of the resource and the value is a list of resources.
30+
31+
Examples
32+
--------
33+
params = get_params()
34+
print(params.oxr)
35+
print(params.ocds)
36+
print(params.dxr)
37+
print(params.dcds)
38+
print(params.ctx)
39+
print(params.extraResources)
40+
"""
41+
oxr: Resource
42+
ocds: {str:Composite}
43+
dxr: Resource
44+
dcds: {str:Composite}
45+
ctx: any
46+
extraResources: {str:[Composite]}
47+
48+
get_params = lambda -> Params {
49+
"""
50+
Get type-safe access to the function pipeline's parameters.
51+
52+
Returns
53+
-------
54+
Params
55+
A strongly-typed Params schema containing the function pipeline's parameters.
56+
57+
Examples
58+
--------
59+
params = get_params()
60+
xr = params.oxr # Type-safe access to observed XR
61+
"""
62+
params = option("params")
63+
Params {
64+
oxr = params.oxr
65+
ocds = params.ocds
66+
dxr = params.dxr
67+
dcds = params.dcds
68+
ctx = params.ctx
69+
extraResources = params.extraResources
70+
}
71+
}

0 commit comments

Comments
 (0)