From 412094a45e137f9a1df8b94dc306ea2046aa2343 Mon Sep 17 00:00:00 2001 From: dalton hill Date: Tue, 3 Sep 2024 13:38:48 -0500 Subject: [PATCH] Adding examples of communicating with the user via events and conditions. Signed-off-by: dalton hill --- .../write-a-composition-function-in-go.md | 17 +++++++++++++++++ .../write-a-composition-function-in-go.md | 17 +++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/content/master/guides/write-a-composition-function-in-go.md b/content/master/guides/write-a-composition-function-in-go.md index c55d171c..bcf6e587 100644 --- a/content/master/guides/write-a-composition-function-in-go.md +++ b/content/master/guides/write-a-composition-function-in-go.md @@ -298,6 +298,18 @@ func (f *Function) RunFunction(_ context.Context, req *fnv1.RunFunctionRequest) // to add desired managed resources. xr, err := request.GetObservedCompositeResource(req) if err != nil { + // You can set a custom status condition on the claim. This + // allows you to communicate with the user. + response.ConditionFalse(rsp, "FunctionSuccess", "InternalError"). + WithMessage("Something went wrong."). + TargetCompositeAndClaim() + + // You can emit an event regarding the claim. This allows you to + // communicate with the user. Note that events should be used + // sparingly and are subject to throttling + response.Warning(rsp, errors.New("something went wrong")). + TargetCompositeAndClaim() + // If the function can't read the XR, the request is malformed. This // should never happen. The function returns a fatal result. This tells // Crossplane to stop running functions and return an error. @@ -388,6 +400,11 @@ func (f *Function) RunFunction(_ context.Context, req *fnv1.RunFunctionRequest) // Kubernetes events associated with the XR it's operating on. log.Info("Added desired buckets", "region", region, "count", len(names)) + // You can set a custom status condition on the claim. This allows you + // to communicate with the user. + response.ConditionTrue(rsp, "FunctionSuccess", "Success"). + TargetCompositeAndClaim() + return rsp, nil } ``` diff --git a/content/v1.17/guides/write-a-composition-function-in-go.md b/content/v1.17/guides/write-a-composition-function-in-go.md index c55d171c..bcf6e587 100644 --- a/content/v1.17/guides/write-a-composition-function-in-go.md +++ b/content/v1.17/guides/write-a-composition-function-in-go.md @@ -298,6 +298,18 @@ func (f *Function) RunFunction(_ context.Context, req *fnv1.RunFunctionRequest) // to add desired managed resources. xr, err := request.GetObservedCompositeResource(req) if err != nil { + // You can set a custom status condition on the claim. This + // allows you to communicate with the user. + response.ConditionFalse(rsp, "FunctionSuccess", "InternalError"). + WithMessage("Something went wrong."). + TargetCompositeAndClaim() + + // You can emit an event regarding the claim. This allows you to + // communicate with the user. Note that events should be used + // sparingly and are subject to throttling + response.Warning(rsp, errors.New("something went wrong")). + TargetCompositeAndClaim() + // If the function can't read the XR, the request is malformed. This // should never happen. The function returns a fatal result. This tells // Crossplane to stop running functions and return an error. @@ -388,6 +400,11 @@ func (f *Function) RunFunction(_ context.Context, req *fnv1.RunFunctionRequest) // Kubernetes events associated with the XR it's operating on. log.Info("Added desired buckets", "region", region, "count", len(names)) + // You can set a custom status condition on the claim. This allows you + // to communicate with the user. + response.ConditionTrue(rsp, "FunctionSuccess", "Success"). + TargetCompositeAndClaim() + return rsp, nil } ```