Skip to content

Commit

Permalink
Merge pull request #809 from dalton-hill-0/claim-communication-examples
Browse files Browse the repository at this point in the history
Claim Communication Examples
  • Loading branch information
jbw976 authored Sep 11, 2024
2 parents 15c896d + 412094a commit 989735f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
17 changes: 17 additions & 0 deletions content/master/guides/write-a-composition-function-in-go.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
}
```
Expand Down
17 changes: 17 additions & 0 deletions content/v1.17/guides/write-a-composition-function-in-go.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
}
```
Expand Down

0 comments on commit 989735f

Please sign in to comment.