Skip to content

Commit 4e9fde1

Browse files
authored
Merge pull request #197 from adamwg/awg/readme-base-image
Document use as a base image in the README
2 parents 39a276e + ee7f0b8 commit 4e9fde1

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,44 @@ spec:
167167
name: templates
168168
```
169169

170+
### Use as a Base Image
171+
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.
173+
174+
For example, if you have the following in `main.k`:
175+
176+
```kcl
177+
# Read the XR
178+
oxr = option("params").oxr
179+
# Patch the XR with the status field
180+
dxr = {
181+
**option("params").dxr
182+
status.dummy = "cool-status"
183+
}
184+
# Construct a bucket
185+
bucket = {
186+
apiVersion = "s3.aws.upbound.io/v1beta1"
187+
kind = "Bucket"
188+
metadata.annotations: {
189+
"krm.kcl.dev/composition-resource-name" = "bucket"
190+
}
191+
spec.forProvider.region = option("oxr").spec.region
192+
}
193+
# Return the bucket and patched XR
194+
items = [bucket, dxr]
195+
```
196+
197+
You can use the following Dockerfile to build a function that runs the code above and does not require any input:
198+
199+
```dockerfile
200+
FROM xpkg.upbound.io/crossplane-contrib/function-kcl:latest
201+
202+
ADD main.k /src/main.k
203+
ENV FUNCTION_KCL_DEFAULT_SOURCE=/src/main.k
204+
```
205+
206+
You may also wish to replace the `/package.yaml` metadata file to give your new function a unique name and remove or replace the input CRD.
207+
170208
### Read the Function Requests and Values through the `option` Function
171209

172210
+ Read the [`ObservedCompositeResource`](https://docs.crossplane.io/latest/concepts/composition-functions/#observed-state) from `option("params").oxr`.

0 commit comments

Comments
 (0)