Skip to content

Commit

Permalink
Merge pull request #160 from dalton-hill-0/example-claim-communication
Browse files Browse the repository at this point in the history
Adding claim communication examples
  • Loading branch information
negz authored Sep 6, 2024
2 parents 8b561e6 + 51848c4 commit 718e949
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ on:
env:
# Common versions
GO_VERSION: '1.21.6'
GOLANGCI_VERSION: 'v1.55.2'
GOLANGCI_VERSION: 'v1.60.3'

jobs:
check-diff:
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ GO_TEST_PARALLEL := $(shell echo $$(( $(NPROCS) / 2 )))
GO_LDFLAGS += -X $(GO_PROJECT)/pkg/version.Version=$(VERSION)
GO_SUBDIRS += errors proto resource response request
GO111MODULE = on
GOLANGCILINT_VERSION = 1.55.2
GOLANGCILINT_VERSION = 1.60.3
GO_LINT_ARGS ?= "--fix"
-include build/makelib/golang.mk

Expand Down
1 change: 0 additions & 1 deletion errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ func Cause(err error) error {
}

for err != nil {
//nolint:errorlint // We actually do want to check the outermost error.
w, ok := err.(wrapped)
if !ok {
return err
Expand Down
22 changes: 20 additions & 2 deletions sdk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,31 @@ func Example() {
}

// Set our updated desired composed resource in the response we'll return.
_ = response.SetDesiredComposedResources(rsp, desired)
if err := response.SetDesiredComposedResources(rsp, desired); err != nil {
// You can set a custom status condition on the claim. This allows you to
// communicate with the user. See the link below for status condition
// guidance.
// https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#typical-status-properties
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; see the issue below for more information.
// https://github.com/crossplane/crossplane/issues/5802
response.Warning(rsp, errors.New("something went wrong")).
TargetCompositeAndClaim()
} else {
response.ConditionTrue(rsp, "FunctionSuccess", "Success").
TargetCompositeAndClaim()
}

j, _ := protojson.Marshal(rsp)
fmt.Println(string(j))

// Output:
// {"meta":{"ttl":"60s"},"desired":{"resources":{"new":{"resource":{"apiVersion":"example.org/v1","kind":"CoolResource","metadata":{"labels":{"coolness":"high"}},"spec":{"widgets":9001}}}}}}
// {"meta":{"ttl":"60s"},"desired":{"resources":{"new":{"resource":{"apiVersion":"example.org/v1","kind":"CoolResource","metadata":{"labels":{"coolness":"high"}},"spec":{"widgets":9001}}}}},"conditions":[{"type":"FunctionSuccess","status":"STATUS_CONDITION_TRUE","reason":"Success","target":"TARGET_COMPOSITE_AND_CLAIM"}]}
}

func TestBetaServer(t *testing.T) {
Expand Down

0 comments on commit 718e949

Please sign in to comment.