Skip to content

Commit 09d3659

Browse files
authored
Merge pull request #78 from dalton-hill-0/adding-condition-example
Add Status Condition Example
2 parents c09b736 + 8adddeb commit 09d3659

File tree

4 files changed

+135
-606
lines changed

4 files changed

+135
-606
lines changed

fn.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,21 @@ func (f *Function) RunFunction(_ context.Context, req *fnv1beta1.RunFunctionRequ
2626

2727
in := &v1beta1.Input{}
2828
if err := request.GetInput(req, in); err != nil {
29+
// You can set a custom status condition on the claim. This allows you to
30+
// communicate with the user. See the link below for status condition
31+
// guidance.
32+
// https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#typical-status-properties
33+
response.ConditionFalse(rsp, "FunctionSuccess", "InternalError").
34+
WithMessage("Something went wrong.").
35+
TargetCompositeAndClaim()
36+
37+
// You can emit an event regarding the claim. This allows you to communicate
38+
// with the user. Note that events should be used sparingly and are subject
39+
// to throttling; see the issue below for more information.
40+
// https://github.com/crossplane/crossplane/issues/5802
41+
response.Warning(rsp, errors.New("something went wrong")).
42+
TargetCompositeAndClaim()
43+
2944
response.Fatal(rsp, errors.Wrapf(err, "cannot get Function input from %T", req))
3045
return rsp, nil
3146
}
@@ -34,5 +49,12 @@ func (f *Function) RunFunction(_ context.Context, req *fnv1beta1.RunFunctionRequ
3449
response.Normalf(rsp, "I was run with input %q!", in.Example)
3550
f.log.Info("I was run!", "input", in.Example)
3651

52+
// You can set a custom status condition on the claim. This allows you to
53+
// communicate with the user. See the link below for status condition
54+
// guidance.
55+
// https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#typical-status-properties
56+
response.ConditionTrue(rsp, "FunctionSuccess", "Success").
57+
TargetCompositeAndClaim()
58+
3759
return rsp, nil
3860
}

fn_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,15 @@ func TestRunFunction(t *testing.T) {
5050
{
5151
Severity: fnv1beta1.Severity_SEVERITY_NORMAL,
5252
Message: "I was run with input \"Hello, world\"!",
53+
Target: fnv1beta1.Target_TARGET_COMPOSITE.Enum(),
54+
},
55+
},
56+
Conditions: []*fnv1beta1.Condition{
57+
{
58+
Type: "FunctionSuccess",
59+
Status: fnv1beta1.Status_STATUS_CONDITION_TRUE,
60+
Reason: "Success",
61+
Target: fnv1beta1.Target_TARGET_COMPOSITE_AND_CLAIM.Enum(),
5362
},
5463
},
5564
},

go.mod

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ toolchain go1.22.3
66

77
require (
88
github.com/alecthomas/kong v0.9.0
9-
github.com/crossplane/crossplane-runtime v1.15.1
10-
github.com/crossplane/function-sdk-go v0.2.0
9+
github.com/crossplane/crossplane-runtime v1.16.0
10+
github.com/crossplane/function-sdk-go v0.3.0-rc.0.0.20240816202013-2da86c5eb7d1
1111
github.com/google/go-cmp v0.6.0
1212
google.golang.org/protobuf v1.34.1
1313
k8s.io/apimachinery v0.29.3
@@ -20,7 +20,7 @@ require (
2020
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
2121
github.com/evanphx/json-patch/v5 v5.8.0 // indirect
2222
github.com/fatih/color v1.16.0 // indirect
23-
github.com/go-json-experiment/json v0.0.0-20231013223334-54c864be5b8d // indirect
23+
github.com/go-json-experiment/json v0.0.0-20231102232822-2e55bd4e08b0 // indirect
2424
github.com/go-logr/logr v1.4.1 // indirect
2525
github.com/go-logr/zapr v1.3.0 // indirect
2626
github.com/go-openapi/jsonpointer v0.19.6 // indirect
@@ -31,7 +31,7 @@ require (
3131
github.com/golang/protobuf v1.5.4 // indirect
3232
github.com/google/gnostic-models v0.6.8 // indirect
3333
github.com/google/gofuzz v1.2.0 // indirect
34-
github.com/google/uuid v1.4.0 // indirect
34+
github.com/google/uuid v1.6.0 // indirect
3535
github.com/inconshreveable/mousetrap v1.1.0 // indirect
3636
github.com/josharian/intern v1.0.0 // indirect
3737
github.com/json-iterator/go v1.1.12 // indirect
@@ -45,20 +45,19 @@ require (
4545
github.com/spf13/afero v1.11.0 // indirect
4646
github.com/spf13/cobra v1.8.0 // indirect
4747
github.com/spf13/pflag v1.0.5 // indirect
48-
github.com/stretchr/testify v1.8.4 // indirect
4948
go.uber.org/multierr v1.11.0 // indirect
50-
go.uber.org/zap v1.26.0 // indirect
51-
golang.org/x/mod v0.14.0 // indirect
52-
golang.org/x/net v0.20.0 // indirect
53-
golang.org/x/oauth2 v0.15.0 // indirect
54-
golang.org/x/sys v0.16.0 // indirect
55-
golang.org/x/term v0.16.0 // indirect
49+
go.uber.org/zap v1.27.0 // indirect
50+
golang.org/x/mod v0.16.0 // indirect
51+
golang.org/x/net v0.23.0 // indirect
52+
golang.org/x/oauth2 v0.16.0 // indirect
53+
golang.org/x/sys v0.18.0 // indirect
54+
golang.org/x/term v0.18.0 // indirect
5655
golang.org/x/text v0.14.0 // indirect
5756
golang.org/x/time v0.5.0 // indirect
58-
golang.org/x/tools v0.17.0 // indirect
57+
golang.org/x/tools v0.19.0 // indirect
5958
google.golang.org/appengine v1.6.8 // indirect
60-
google.golang.org/genproto/googleapis/rpc v0.0.0-20240116215550-a9fa1716bcac // indirect
61-
google.golang.org/grpc v1.61.0 // indirect
59+
google.golang.org/genproto/googleapis/rpc v0.0.0-20240304212257-790db918fca8 // indirect
60+
google.golang.org/grpc v1.62.0 // indirect
6261
gopkg.in/inf.v0 v0.9.1 // indirect
6362
gopkg.in/yaml.v2 v2.4.0 // indirect
6463
gopkg.in/yaml.v3 v3.0.1 // indirect

0 commit comments

Comments
 (0)