Skip to content

Commit 989735f

Browse files
authored
Merge pull request #809 from dalton-hill-0/claim-communication-examples
Claim Communication Examples
2 parents 15c896d + 412094a commit 989735f

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

content/master/guides/write-a-composition-function-in-go.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,18 @@ func (f *Function) RunFunction(_ context.Context, req *fnv1.RunFunctionRequest)
298298
// to add desired managed resources.
299299
xr, err := request.GetObservedCompositeResource(req)
300300
if err != nil {
301+
// You can set a custom status condition on the claim. This
302+
// allows you to communicate with the user.
303+
response.ConditionFalse(rsp, "FunctionSuccess", "InternalError").
304+
WithMessage("Something went wrong.").
305+
TargetCompositeAndClaim()
306+
307+
// You can emit an event regarding the claim. This allows you to
308+
// communicate with the user. Note that events should be used
309+
// sparingly and are subject to throttling
310+
response.Warning(rsp, errors.New("something went wrong")).
311+
TargetCompositeAndClaim()
312+
301313
// If the function can't read the XR, the request is malformed. This
302314
// should never happen. The function returns a fatal result. This tells
303315
// Crossplane to stop running functions and return an error.
@@ -388,6 +400,11 @@ func (f *Function) RunFunction(_ context.Context, req *fnv1.RunFunctionRequest)
388400
// Kubernetes events associated with the XR it's operating on.
389401
log.Info("Added desired buckets", "region", region, "count", len(names))
390402
403+
// You can set a custom status condition on the claim. This allows you
404+
// to communicate with the user.
405+
response.ConditionTrue(rsp, "FunctionSuccess", "Success").
406+
TargetCompositeAndClaim()
407+
391408
return rsp, nil
392409
}
393410
```

content/v1.17/guides/write-a-composition-function-in-go.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,18 @@ func (f *Function) RunFunction(_ context.Context, req *fnv1.RunFunctionRequest)
298298
// to add desired managed resources.
299299
xr, err := request.GetObservedCompositeResource(req)
300300
if err != nil {
301+
// You can set a custom status condition on the claim. This
302+
// allows you to communicate with the user.
303+
response.ConditionFalse(rsp, "FunctionSuccess", "InternalError").
304+
WithMessage("Something went wrong.").
305+
TargetCompositeAndClaim()
306+
307+
// You can emit an event regarding the claim. This allows you to
308+
// communicate with the user. Note that events should be used
309+
// sparingly and are subject to throttling
310+
response.Warning(rsp, errors.New("something went wrong")).
311+
TargetCompositeAndClaim()
312+
301313
// If the function can't read the XR, the request is malformed. This
302314
// should never happen. The function returns a fatal result. This tells
303315
// Crossplane to stop running functions and return an error.
@@ -388,6 +400,11 @@ func (f *Function) RunFunction(_ context.Context, req *fnv1.RunFunctionRequest)
388400
// Kubernetes events associated with the XR it's operating on.
389401
log.Info("Added desired buckets", "region", region, "count", len(names))
390402
403+
// You can set a custom status condition on the claim. This allows you
404+
// to communicate with the user.
405+
response.ConditionTrue(rsp, "FunctionSuccess", "Success").
406+
TargetCompositeAndClaim()
407+
391408
return rsp, nil
392409
}
393410
```

0 commit comments

Comments
 (0)