Skip to content

Commit 8584048

Browse files
authored
Merge pull request #79 from Peefy/fix-database-on-field-dump
fix: database on field dump and add more tests
2 parents fb5929c + 1c9a6a4 commit 8584048

File tree

10 files changed

+170
-22
lines changed

10 files changed

+170
-22
lines changed

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ env:
3333
XPKG: xpkg.upbound.io/${{ github.repository}}
3434

3535
# The package version to push. The default is 0.0.0-gitsha.
36-
XPKG_VERSION: v0.5.3
36+
XPKG_VERSION: v0.5.4
3737

3838
jobs:
3939
unit-test:
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
run:
2+
crossplane beta render xr.yaml composition.yaml functions.yaml -r
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Example Manifests
2+
3+
You can run your function locally and test it using `crossplane beta render`
4+
with these example manifests.
5+
6+
```shell
7+
# Run the function locally
8+
$ go run . --insecure --debug
9+
```
10+
11+
```shell
12+
# Then, in another terminal, call it with these example manifests
13+
$ crossplane beta render xr.yaml composition.yaml functions.yaml -r
14+
---
15+
apiVersion: fn-demo.crossplane.io/v1alpha1
16+
kind: Database
17+
metadata:
18+
name: database-test-functions
19+
---
20+
apiVersion: sql.gcp.upbound.io/v1beta1
21+
kind: DatabaseInstance
22+
metadata:
23+
annotations:
24+
crossplane.io/composition-resource-name: ""
25+
generateName: database-test-functions-
26+
labels:
27+
crossplane.io/composite: database-test-functions
28+
ownerReferences:
29+
- apiVersion: fn-demo.crossplane.io/v1alpha1
30+
blockOwnerDeletion: true
31+
controller: true
32+
kind: Database
33+
name: database-test-functions
34+
uid: ""
35+
spec:
36+
forProvider:
37+
project: test-project
38+
settings:
39+
- databaseFlags:
40+
- name: log_checkpoints
41+
value: "on"
42+
```
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
items = [{
2+
apiVersion: "sql.gcp.upbound.io/v1beta1"
3+
kind: "DatabaseInstance"
4+
spec: {
5+
forProvider: {
6+
project: "test-project"
7+
settings: [{databaseFlags: [{
8+
name: "log_checkpoints"
9+
value: "on"
10+
}]}]
11+
}
12+
}
13+
}]
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
apiVersion: apiextensions.crossplane.io/v1
2+
kind: Composition
3+
metadata:
4+
name: xlabels.fn-demo.crossplane.io
5+
labels:
6+
provider: aws
7+
spec:
8+
writeConnectionSecretsToNamespace: crossplane-system
9+
compositeTypeRef:
10+
apiVersion: fn-demo.crossplane.io/v1alpha1
11+
kind: XNetwork
12+
mode: Pipeline
13+
pipeline:
14+
- step: normal
15+
functionRef:
16+
name: kcl-function
17+
input:
18+
apiVersion: krm.kcl.dev/v1alpha1
19+
kind: KCLRun
20+
metadata:
21+
name: basic
22+
spec:
23+
target: Resources
24+
source: |
25+
items = [{
26+
apiVersion: "sql.gcp.upbound.io/v1beta1"
27+
kind: "DatabaseInstance"
28+
spec: {
29+
forProvider: {
30+
project: "test-project"
31+
settings: [{databaseFlags: [{
32+
name: "log_checkpoints"
33+
value: "on"
34+
}]}]
35+
}
36+
}
37+
}]
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
apiVersion: pkg.crossplane.io/v1beta1
2+
kind: Function
3+
metadata:
4+
name: kcl-function
5+
annotations:
6+
# This tells crossplane beta render to connect to the function locally.
7+
render.crossplane.io/runtime: Development
8+
spec:
9+
package: xpkg.upbound.io/crossplane-contrib/function-kcl:latest
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
apiVersion: fn-demo.crossplane.io/v1alpha1
2+
kind: Database
3+
metadata:
4+
name: database-test-functions
5+
namespace: default
6+
spec:
7+
id: database-test-functions

fn_test.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,44 @@ func TestRunFunction(t *testing.T) {
7171
},
7272
},
7373
},
74+
"DatabaseInstance": {
75+
reason: "The Function should return a fatal result if no input was specified",
76+
args: args{
77+
req: &fnv1beta1.RunFunctionRequest{
78+
Meta: &fnv1beta1.RequestMeta{Tag: "database-instance"},
79+
Input: resource.MustStructJSON(`{
80+
"apiVersion": "krm.kcl.dev/v1alpha1",
81+
"kind": "KCLRun",
82+
"metadata": {
83+
"name": "basic"
84+
},
85+
"spec": {
86+
"source": "items = [{ \n apiVersion: \"sql.gcp.upbound.io/v1beta1\"\n kind: \"DatabaseInstance\"\n spec: {\n forProvider: {\n project: \"test-project\"\n settings: [{databaseFlags: [{\n name: \"log_checkpoints\"\n value: \"on\"\n }]}]\n }\n }\n}]\n"
87+
}
88+
}`),
89+
Observed: &fnv1beta1.State{
90+
Composite: &fnv1beta1.Resource{
91+
Resource: resource.MustStructJSON(`{"apiVersion":"example.org/v1","kind":"XR"}`),
92+
},
93+
},
94+
},
95+
},
96+
want: want{
97+
rsp: &fnv1beta1.RunFunctionResponse{
98+
Meta: &fnv1beta1.ResponseMeta{Tag: "database-instance", Ttl: durationpb.New(response.DefaultTTL)},
99+
Desired: &fnv1beta1.State{
100+
Composite: &fnv1beta1.Resource{
101+
Resource: resource.MustStructJSON(`{"apiVersion":"example.org/v1","kind":"XR"}`),
102+
},
103+
Resources: map[string]*fnv1beta1.Resource{
104+
"": {
105+
Resource: resource.MustStructJSON(`{"apiVersion": "sql.gcp.upbound.io/v1beta1", "kind": "DatabaseInstance", "spec": {"forProvider": {"project": "test-project", "settings": [{"databaseFlags": [{"name": "log_checkpoints", "value": "on"}]}]}}}`),
106+
},
107+
},
108+
},
109+
},
110+
},
111+
},
74112
}
75113

76114
for name, tc := range cases {

go.mod

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ require (
1212
google.golang.org/protobuf v1.33.0
1313
gopkg.in/yaml.v2 v2.4.0
1414
k8s.io/apimachinery v0.30.0
15-
kcl-lang.io/krm-kcl v0.8.3-0.20240415150603-203d07fcebf6
15+
kcl-lang.io/krm-kcl v0.8.5
1616
sigs.k8s.io/controller-tools v0.14.0
1717
sigs.k8s.io/yaml v1.4.0
1818
)
@@ -25,7 +25,7 @@ require (
2525
cloud.google.com/go/storage v1.36.0 // indirect
2626
github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24 // indirect
2727
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 // indirect
28-
github.com/BurntSushi/toml v1.2.1 // indirect
28+
github.com/BurntSushi/toml v1.3.2 // indirect
2929
github.com/GoogleContainerTools/kpt-functions-sdk/go/api v0.0.0-20220720212527-133180134b93 // indirect
3030
github.com/GoogleContainerTools/kpt-functions-sdk/go/fn v0.0.0-20230427202446-3255accc518d // indirect
3131
github.com/Microsoft/go-winio v0.6.1 // indirect
@@ -179,7 +179,7 @@ require (
179179
google.golang.org/genproto v0.0.0-20240227224415-6ceb2ff114de // indirect
180180
google.golang.org/genproto/googleapis/api v0.0.0-20240227224415-6ceb2ff114de // indirect
181181
google.golang.org/genproto/googleapis/rpc v0.0.0-20240227224415-6ceb2ff114de // indirect
182-
google.golang.org/grpc v1.63.0 // indirect
182+
google.golang.org/grpc v1.63.2 // indirect
183183
gopkg.in/inf.v0 v0.9.1 // indirect
184184
gopkg.in/warnings.v0 v0.1.2 // indirect
185185
gopkg.in/yaml.v3 v3.0.1 // indirect
@@ -191,11 +191,11 @@ require (
191191
k8s.io/klog/v2 v2.120.1 // indirect
192192
k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340 // indirect
193193
k8s.io/utils v0.0.0-20240102154912-e7106e64919e // indirect
194-
kcl-lang.io/cli v0.8.5 // indirect
195-
kcl-lang.io/kcl-go v0.8.4 // indirect
194+
kcl-lang.io/cli v0.8.6 // indirect
195+
kcl-lang.io/kcl-go v0.8.5 // indirect
196196
kcl-lang.io/kcl-openapi v0.6.1 // indirect
197-
kcl-lang.io/kpm v0.8.5-0.20240401071819-7a69be511c95 // indirect
198-
kcl-lang.io/lib v0.8.4 // indirect
197+
kcl-lang.io/kpm v0.8.5 // indirect
198+
kcl-lang.io/lib v0.8.5 // indirect
199199
oras.land/oras-go v1.2.3 // indirect
200200
oras.land/oras-go/v2 v2.3.0 // indirect
201201
sigs.k8s.io/controller-runtime v0.17.0 // indirect

go.sum

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,8 @@ github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24/go.mod h
192192
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 h1:L/gRVlceqvL25UVaW/CKtUDjefjrs0SPonmDGUVOYP0=
193193
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E=
194194
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
195-
github.com/BurntSushi/toml v1.2.1 h1:9F2/+DoOYIOksmaJFPw1tGFy1eDnIJXg+UHjuD8lTak=
196-
github.com/BurntSushi/toml v1.2.1/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
195+
github.com/BurntSushi/toml v1.3.2 h1:o7IhLm0Msx3BaB+n3Ag7L8EVlByGnpq14C4YWiu/gL8=
196+
github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
197197
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
198198
github.com/GoogleContainerTools/kpt-functions-sdk/go/api v0.0.0-20220720212527-133180134b93 h1:c1GhPzYzU2a3E+/2WB9OxoljK2pNYfsBF5Fz9GkdYXs=
199199
github.com/GoogleContainerTools/kpt-functions-sdk/go/api v0.0.0-20220720212527-133180134b93/go.mod h1:gkK43tTaPXFNASpbIbQImzhmt1hdcdin++kvzTblykc=
@@ -1482,8 +1482,8 @@ google.golang.org/grpc v1.48.0/go.mod h1:vN9eftEi1UMyUsIF80+uQXhHjbXYbm0uXoFCACu
14821482
google.golang.org/grpc v1.49.0/go.mod h1:ZgQEeidpAuNRZ8iRrlBKXZQP1ghovWIVhdJRyCDK+GI=
14831483
google.golang.org/grpc v1.50.0/go.mod h1:ZgQEeidpAuNRZ8iRrlBKXZQP1ghovWIVhdJRyCDK+GI=
14841484
google.golang.org/grpc v1.50.1/go.mod h1:ZgQEeidpAuNRZ8iRrlBKXZQP1ghovWIVhdJRyCDK+GI=
1485-
google.golang.org/grpc v1.63.0 h1:WjKe+dnvABXyPJMD7KDNLxtoGk5tgk+YFWN6cBWjZE8=
1486-
google.golang.org/grpc v1.63.0/go.mod h1:WAX/8DgncnokcFUldAxq7GeB5DXHDbMF+lLvDomNkRA=
1485+
google.golang.org/grpc v1.63.2 h1:MUeiw1B2maTVZthpU5xvASfTh3LDbxHd6IJ6QQVU+xM=
1486+
google.golang.org/grpc v1.63.2/go.mod h1:WAX/8DgncnokcFUldAxq7GeB5DXHDbMF+lLvDomNkRA=
14871487
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0/go.mod h1:6Kw0yEErY5E/yWrBtf03jp27GLLJujG4z/JK95pnjjw=
14881488
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
14891489
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
@@ -1558,18 +1558,18 @@ k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340 h1:BZqlfIlq5YbRMFko6/PM7F
15581558
k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340/go.mod h1:yD4MZYeKMBwQKVht279WycxKyM84kkAx2DPrTXaeb98=
15591559
k8s.io/utils v0.0.0-20240102154912-e7106e64919e h1:eQ/4ljkx21sObifjzXwlPKpdGLrCfRziVtos3ofG/sQ=
15601560
k8s.io/utils v0.0.0-20240102154912-e7106e64919e/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
1561-
kcl-lang.io/cli v0.8.5 h1:6xo1Zb+c34n9qYIEsAAnWafuNEOqo+QnNyFUQLZfgtk=
1562-
kcl-lang.io/cli v0.8.5/go.mod h1:Q/yQbud6IMaWjSiKMnB2sQdB9HWTPQrMWzvCWNVAWW4=
1563-
kcl-lang.io/kcl-go v0.8.4 h1:DIzrZTopuqQaBXM6+y100Bi0m+oH7rt1BpDwdHQBng4=
1564-
kcl-lang.io/kcl-go v0.8.4/go.mod h1:vmZ/g247eOcvlZhIWgXWMVkIpyDi1BCsLPDkIdMWglY=
1561+
kcl-lang.io/cli v0.8.6 h1:m0VIbLqiUULM6qGhCr1dvV+lOJfK/TVyeuOq7XcEFTo=
1562+
kcl-lang.io/cli v0.8.6/go.mod h1:shs86nJcmHs1m9ucWZksAiX5j6d9EGl9DHsOxlwtmVo=
1563+
kcl-lang.io/kcl-go v0.8.5 h1:YuaZju34cclGVB8Z1O1hhxZx6lYF4cW3x6yDqK6l3iI=
1564+
kcl-lang.io/kcl-go v0.8.5/go.mod h1:CkXBerH9YchN2mP7fTfq5DXdmhXHH2lrbg5TFVT4KL8=
15651565
kcl-lang.io/kcl-openapi v0.6.1 h1:iPH0EvPgDGZS5Lk00/Su5Av6AQP5IBG8f7gAUyevkHE=
15661566
kcl-lang.io/kcl-openapi v0.6.1/go.mod h1:Ai9mFztCVKkRSFabczO/r5hCNdqaNtAc2ZIRxTeV0Mk=
1567-
kcl-lang.io/kpm v0.8.5-0.20240401071819-7a69be511c95 h1:grwv/MI/n+kQUMxrvyM5qGTGooa3LBxBKq3lNr9wdFg=
1568-
kcl-lang.io/kpm v0.8.5-0.20240401071819-7a69be511c95/go.mod h1:3atE1tEbsSPaAuKslkADH1HTDi7SMWlDWllmuk2XsBA=
1569-
kcl-lang.io/krm-kcl v0.8.3-0.20240415150603-203d07fcebf6 h1:YK1+W3xFiOyNnJ31Hl0ASOCnXjiCqNFdmQYOh5pOD4Y=
1570-
kcl-lang.io/krm-kcl v0.8.3-0.20240415150603-203d07fcebf6/go.mod h1:0RUVOL78Ngy6o3frRcvVIWL45wJdxtbSHPZOBVmv3Uc=
1571-
kcl-lang.io/lib v0.8.4 h1:uQPNLqZe3abaW++90kYhCSEmTEi2DE0yf/xLM/Q9S2c=
1572-
kcl-lang.io/lib v0.8.4/go.mod h1:ubsalGXxJaa5II/EsHmsI/tL2EluYHIcW+BwzQPt+uY=
1567+
kcl-lang.io/kpm v0.8.5 h1:I5P64YHwzLoBKppoC//nVF6rR6zbXd1iAIU8pH4tJ3A=
1568+
kcl-lang.io/kpm v0.8.5/go.mod h1:3atE1tEbsSPaAuKslkADH1HTDi7SMWlDWllmuk2XsBA=
1569+
kcl-lang.io/krm-kcl v0.8.5 h1:eJDFPgabdJSqbeqUtYY8baqNjRLmK706SLfhpnrm+nM=
1570+
kcl-lang.io/krm-kcl v0.8.5/go.mod h1:RayZA+1UUhLVCN4e3Ia4m1fk73b7Q7dRL7e+0oAopAQ=
1571+
kcl-lang.io/lib v0.8.5 h1:9GsGcJlanBKw/B6jxe6imdv4lbfdiDsNW4bByA1TGUY=
1572+
kcl-lang.io/lib v0.8.5/go.mod h1:ubsalGXxJaa5II/EsHmsI/tL2EluYHIcW+BwzQPt+uY=
15731573
oras.land/oras-go v1.2.5 h1:XpYuAwAb0DfQsunIyMfeET92emK8km3W4yEzZvUbsTo=
15741574
oras.land/oras-go v1.2.5/go.mod h1:PuAwRShRZCsZb7g8Ar3jKKQR/2A/qN+pkYxIOd/FAoo=
15751575
oras.land/oras-go/v2 v2.5.0 h1:o8Me9kLY74Vp5uw07QXPiitjsw7qNXi8Twd+19Zf02c=

0 commit comments

Comments
 (0)