Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: crossplane-contrib/function-kcl
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.11.0
Choose a base ref
...
head repository: crossplane-contrib/function-kcl
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v0.11.1
Choose a head ref

Commits on Dec 31, 2024

  1. Copy the full SHA
    da02811 View commit details
  2. Merge pull request #220 from crossplane-contrib/renovate/sigs.k8s.io-…

    …controller-tools-0.x
    
    fix(deps): update module sigs.k8s.io/controller-tools to v0.17.0
    Peefy authored Dec 31, 2024
    Copy the full SHA
    2b186b5 View commit details

Commits on Jan 3, 2025

  1. feat: add event and condition handling in resource processing

    Signed-off-by: Mark Altmann <markaltmann@googlemail.com>
    Mark Altmann authored and Wompipomp committed Jan 3, 2025
    Copy the full SHA
    ebf221d View commit details
  2. fix: writing tests for conditions and events

    Signed-off-by: Mark Altmann <markaltmann@googlemail.com>
    Mark Altmann authored and Wompipomp committed Jan 3, 2025
    Copy the full SHA
    a7f4ad4 View commit details
  3. fix: minor fixes and tests

    Signed-off-by: Mark Altmann <markaltmann@googlemail.com>
    Wompipomp committed Jan 3, 2025
    Copy the full SHA
    ac5e210 View commit details
  4. chore: docs

    Signed-off-by: Mark Altmann <markaltmann@googlemail.com>
    Wompipomp committed Jan 3, 2025
    Copy the full SHA
    467dd83 View commit details
  5. fix: improve error handling

    Signed-off-by: Mark Altmann <markaltmann@googlemail.com>
    Wompipomp committed Jan 3, 2025
    Copy the full SHA
    1bb6428 View commit details
  6. fix: improve docs

    Signed-off-by: Mark Altmann <markaltmann@googlemail.com>
    Wompipomp committed Jan 3, 2025
    Copy the full SHA
    a7bc48b View commit details
  7. Merge pull request #222 from Wompipomp/add-conditions-and-events

    Add conditions and events
    Peefy authored Jan 3, 2025
    Copy the full SHA
    813f284 View commit details
  8. Copy the full SHA
    f09c2bc View commit details
  9. Merge pull request #223 from crossplane-contrib/renovate/k8s.io-utils…

    …-digest
    
    fix(deps): update k8s.io/utils digest to 24370be
    Peefy authored Jan 3, 2025
    Copy the full SHA
    d854ae8 View commit details
  10. modified Dockerfile source images to use smaller base images

    Signed-off-by: Brad Wadsworth <brad.wadsworth@eviden.com>
    bradkwadsworth-mw committed Jan 3, 2025
    Copy the full SHA
    bf328a5 View commit details
  11. only shrink Go binary

    Signed-off-by: Brad Wadsworth <brad.wadsworth@eviden.com>
    bradkwadsworth-mw committed Jan 3, 2025
    Copy the full SHA
    7bc992f View commit details

Commits on Jan 4, 2025

  1. Merge pull request #218 from bradkwadsworth-mw/feature/smaller-image

    modified Dockerfile source images to use smaller base images
    Peefy authored Jan 4, 2025
    Copy the full SHA
    837f319 View commit details

Commits on Jan 7, 2025

  1. Copy the full SHA
    849f85b View commit details
  2. Merge pull request #224 from crossplane-contrib/renovate/github.com-a…

    …lecthomas-kong-1.x
    
    fix(deps): update module github.com/alecthomas/kong to v1.6.1
    Peefy authored Jan 7, 2025
    Copy the full SHA
    07f5ef5 View commit details

Commits on Jan 8, 2025

  1. Copy the full SHA
    25b9009 View commit details

Commits on Jan 9, 2025

  1. Merge pull request #225 from crossplane-contrib/renovate/google.golan…

    …g.org-protobuf-1.x
    
    fix(deps): update module google.golang.org/protobuf to v1.36.2
    Peefy authored Jan 9, 2025
    Copy the full SHA
    2027d35 View commit details

Commits on Jan 14, 2025

  1. Copy the full SHA
    97fb33a View commit details
  2. Merge pull request #227 from crossplane-contrib/renovate/sigs.k8s.io-…

    …controller-tools-0.x
    
    fix(deps): update module sigs.k8s.io/controller-tools to v0.17.1
    Peefy authored Jan 14, 2025
    Copy the full SHA
    5888db3 View commit details

Commits on Jan 15, 2025

  1. Copy the full SHA
    b937654 View commit details

Commits on Jan 16, 2025

  1. Copy the full SHA
    f1c2dfc View commit details
  2. Implement context writing

    Signed-off-by: Yury Tsarev <yury@upbound.io>
    ytsarev committed Jan 16, 2025
    Copy the full SHA
    9630f0d View commit details
  3. Add context merge capabilities

    Signed-off-by: Yury Tsarev <yury@upbound.io>
    ytsarev committed Jan 16, 2025
    Copy the full SHA
    d291255 View commit details
  4. Refactor merge context to match current common function layout

    Signed-off-by: Yury Tsarev <yury@upbound.io>
    ytsarev committed Jan 16, 2025
    Copy the full SHA
    63ab271 View commit details
  5. Merge pull request #231 from ytsarev/write-to-context

    Implement writing to Context
    Peefy authored Jan 16, 2025
    Copy the full SHA
    e67112c View commit details
  6. Copy the full SHA
    5b7ad04 View commit details

Commits on Jan 17, 2025

  1. Merge pull request #232 from crossplane-contrib/renovate/go-1.x

    chore(deps): update dependency go to v1.23.5
    zong-zhe authored Jan 17, 2025
    Copy the full SHA
    c85bffd View commit details
  2. Merge pull request #229 from crossplane-contrib/renovate/kubernetes-go

    fix(deps): update module k8s.io/apimachinery to v0.32.1
    zong-zhe authored Jan 17, 2025
    Copy the full SHA
    77a7ec7 View commit details
  3. Merge pull request #228 from crossplane-contrib/renovate/google.golan…

    …g.org-protobuf-1.x
    
    fix(deps): update module google.golang.org/protobuf to v1.36.3
    zong-zhe authored Jan 17, 2025
    Copy the full SHA
    b09969e View commit details

Commits on Jan 24, 2025

  1. Copy the full SHA
    b3a688e View commit details
  2. Merge pull request #233 from crossplane-contrib/renovate/google.golan…

    …g.org-protobuf-1.x
    
    fix(deps): update module google.golang.org/protobuf to v1.36.4
    Peefy authored Jan 24, 2025
    Copy the full SHA
    eacf7e9 View commit details
  3. Update ci.yaml

    Peefy authored Jan 24, 2025
    Copy the full SHA
    bea0691 View commit details
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -35,7 +35,7 @@ env:
XPKG: xpkg.upbound.io/${{ github.repository}}

# The package version to push. The default is 0.0.0-gitsha.
XPKG_VERSION: v0.11.0
XPKG_VERSION: v0.11.1

jobs:
lint:
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -16,3 +16,6 @@ vendor/
.kclvm
.DS_store
package/*.xpkg

.idea
.vscode
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -33,7 +33,7 @@ ARG TARGETARCH
RUN --mount=target=. \
--mount=type=cache,target=/go/pkg/mod \
--mount=type=cache,target=/root/.cache/go-build \
GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -o /function .
GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -ldflags "-w -s" -o /function .

# Produce the Function image. We use a very lightweight 'distroless' image that
# does not include any of the build tools used in previous stages.
88 changes: 87 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -513,6 +513,8 @@ bar:
# Omitted for brevity
```
You can access the retrieved resources in your code like this:
> Note that Crossplane performs an additional reconciliation pass for extra resources.
> Consequently, during the initial execution, these resources may be uninitialized. It is essential to implement checks to handle this scenario.
```yaml
apiVersion: krm.kcl.dev/v1alpha1
kind: KCLInput
@@ -522,7 +524,8 @@ spec:
source: |
er = option("params")?.extraResources
name = er?.bar[0]?.Resource?.metadata?.name or ""
if er?.bar:
name = er?.bar[0]?.Resource?.metadata?.name or ""
# Omit other logic
```

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

### Settings conditions and events

> This feature requires Crossplane v1.17 or newer.

You can set conditions and events directly from KCL, either in the composite resource or both the composite and claim resources.
To set one or more conditions, use the following approach:
```yaml
apiVersion: krm.kcl.dev/v1alpha1
kind: KCLInput
metadata:
annotations:
"krm.kcl.dev/default_ready": "True"
name: basic
spec:
source: |
oxr = option("params").oxr
dxr = {
**oxr
}
conditions = {
apiVersion: "meta.krm.kcl.dev/v1alpha1"
kind: "Conditions"
conditions = [
{
target: "CompositeAndClaim"
force: False
condition = {
type: "DatabaseReady"
status: "False"
reason: "FailedToCreate"
message: "Encountered an error creating the database"
}
}
]
}
items = [
conditions
dxr
]
```

- **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`
- **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.

You can also set events as follows:
```yaml
apiVersion: krm.kcl.dev/v1alpha1
kind: KCLInput
metadata:
annotations:
"krm.kcl.dev/default_ready": "True"
name: basic
spec:
source: |
oxr = option("params").oxr
dxr = {
**oxr
}
events = {
apiVersion: "meta.krm.kcl.dev/v1alpha1"
kind: "Events"
events = [
{
target: "CompositeAndClaim"
event = {
type: "Warning"
reason: "ResourceLimitExceeded"
message: "The resource limit has been exceeded"
}
}
]
}
items = [
events
dxr
]
```

## Library

You can directly use [KCL standard libraries](https://kcl-lang.io/docs/reference/model/overview) such as `regex.match`, `math.log`.
2 changes: 2 additions & 0 deletions examples/default/conditions/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
run:
crossplane render --verbose xr.yaml composition.yaml functions.yaml -r
62 changes: 62 additions & 0 deletions examples/default/conditions/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Example Manifests

You can run your function locally and test it using `crossplane render`
with these example manifests.

```shell
# Run the function locally
$ go run . --insecure --debug
```

```shell
# Then, in another terminal, call it with these example manifests
$ crossplane render --verbose xr.yaml composition.yaml functions.yaml -r --extra-resources extra_resources.yaml
---
---
apiVersion: example.crossplane.io/v1beta1
kind: XR
metadata:
name: example
status:
conditions:
- lastTransitionTime: "2024-01-01T00:00:00Z"
message: 'Unready resources: another-awesome-dev-bucket, my-awesome-dev-bucket'
reason: Creating
status: "False"
type: Ready
---
apiVersion: example/v1alpha1
kind: Foo
metadata:
annotations:
crossplane.io/composition-resource-name: another-awesome-dev-bucket
generateName: example-
labels:
crossplane.io/composite: example
name: another-awesome-dev-bucket
ownerReferences:
- apiVersion: example.crossplane.io/v1beta1
blockOwnerDeletion: true
controller: true
kind: XR
name: example
uid: ""
---
apiVersion: example/v1alpha1
kind: Foo
metadata:
annotations:
crossplane.io/composition-resource-name: my-awesome-dev-bucket
generateName: example-
labels:
crossplane.io/composite: example
name: my-awesome-dev-bucket
ownerReferences:
- apiVersion: example.crossplane.io/v1beta1
blockOwnerDeletion: true
controller: true
kind: XR
name: example
uid: ""

```
49 changes: 49 additions & 0 deletions examples/default/conditions/composition.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
apiVersion: apiextensions.crossplane.io/v1
kind: Composition
metadata:
name: function-template-go
spec:
compositeTypeRef:
apiVersion: example.crossplane.io/v1beta1
kind: XR
mode: Pipeline
pipeline:
- step: normal
functionRef:
name: kcl-function
input:
apiVersion: krm.kcl.dev/v1alpha1
kind: KCLInput
metadata:
annotations:
"krm.kcl.dev/default_ready": "True"
name: basic
spec:
source: |
oxr = option("params").oxr
dxr = {
**oxr
}
conditions = {
apiVersion: "meta.krm.kcl.dev/v1alpha1"
kind: "Conditions"
conditions = [
{
target: "CompositeAndClaim"
force: False
condition = {
type: "DatabaseReady"
status: "False"
reason: "FailedToCreate"
message: "Encountered an error creating the database"
}
}
]
}
items = [
conditions
dxr
]
9 changes: 9 additions & 0 deletions examples/default/conditions/functions.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: pkg.crossplane.io/v1beta1
kind: Function
metadata:
name: kcl-function
annotations:
# This tells crossplane render to connect to the function locally.
render.crossplane.io/runtime: Development
spec:
package: xpkg.upbound.io/crossplane-contrib/function-kcl:latest
6 changes: 6 additions & 0 deletions examples/default/conditions/xr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: example.crossplane.io/v1beta1
kind: XR
metadata:
name: example
spec:
count: 1
2 changes: 2 additions & 0 deletions examples/default/context/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
run:
crossplane render --verbose xr.yaml composition.yaml functions.yaml -rc
32 changes: 32 additions & 0 deletions examples/default/context/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Example Manifests

You can run your function locally and test it using `crossplane render`
with these example manifests.

```shell
# Run the function locally
$ go run . --insecure --debug
```

```shell
# Then, in another terminal, call it with these example manifests
$ crossplane render --verbose xr.yaml composition.yaml functions.yaml -rc
---
apiVersion: example.crossplane.io/v1beta1
kind: XR
metadata:
name: example
status:
conditions:
- lastTransitionTime: "2024-01-01T00:00:00Z"
reason: Available
status: "True"
type: Ready
---
apiVersion: render.crossplane.io/v1beta1
fields:
contextField: contextValue
moreComplexField:
test: field
kind: Context
```
42 changes: 42 additions & 0 deletions examples/default/context/composition.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
apiVersion: apiextensions.crossplane.io/v1
kind: Composition
metadata:
name: function-template-go
spec:
compositeTypeRef:
apiVersion: example.crossplane.io/v1beta1
kind: XR
mode: Pipeline
pipeline:
- step: normal
functionRef:
name: kcl-function
input:
apiVersion: krm.kcl.dev/v1alpha1
kind: KCLInput
metadata:
annotations:
"krm.kcl.dev/default_ready": "True"
name: basic
spec:
source: |
oxr = option("params").oxr
dxr = {
**oxr
}
context = {
apiVersion: "meta.krm.kcl.dev/v1alpha1"
kind: "Context"
data = {
contextField = "contextValue"
moreComplexField = {
test: "field"
}
}
}
items = [
context
dxr
]
9 changes: 9 additions & 0 deletions examples/default/context/functions.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: pkg.crossplane.io/v1beta1
kind: Function
metadata:
name: kcl-function
annotations:
# This tells crossplane render to connect to the function locally.
render.crossplane.io/runtime: Development
spec:
package: xpkg.upbound.io/crossplane-contrib/function-kcl:latest
6 changes: 6 additions & 0 deletions examples/default/context/xr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: example.crossplane.io/v1beta1
kind: XR
metadata:
name: example
spec:
count: 1
2 changes: 2 additions & 0 deletions examples/default/events/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
run:
crossplane render --verbose xr.yaml composition.yaml functions.yaml -r
Loading