Skip to content

Expose composite ready state in function response #218

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions resource/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ type ConnectionDetails map[string][]byte
type Composite struct {
Resource *composite.Unstructured
ConnectionDetails ConnectionDetails

Ready Ready
Copy link
Author

@tenitski tenitski Jul 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Empty line here for consistency with DesiredComposed below

}

// A Name uniquely identifies a composed resource within a Composition Function
Expand Down
16 changes: 14 additions & 2 deletions response/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,20 @@ func SetDesiredCompositeResource(rsp *v1.RunFunctionResponse, xr *resource.Compo
rsp.Desired = &v1.State{}
}
s, err := resource.AsStruct(xr.Resource)
rsp.Desired.Composite = &v1.Resource{Resource: s, ConnectionDetails: xr.ConnectionDetails}
return errors.Wrapf(err, "cannot convert %T to desired composite resource", xr.Resource)
r := &v1.Resource{Resource: s, ConnectionDetails: xr.ConnectionDetails}
if err != nil {
return errors.Wrapf(err, "cannot convert %T to desired composite resource", xr.Resource)
}
switch xr.Ready {
case resource.ReadyUnspecified:
r.Ready = v1.Ready_READY_UNSPECIFIED
case resource.ReadyFalse:
r.Ready = v1.Ready_READY_FALSE
case resource.ReadyTrue:
r.Ready = v1.Ready_READY_TRUE
}
Copy link
Author

@tenitski tenitski Jul 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bit of code duplication introduced with a switch (see SetDesiredComposedResources below).
It is minimal, moving it to a separate function does not really make the code tidier...

rsp.Desired.Composite = r
return nil
}

// SetDesiredComposedResources sets the desired composed resources in the
Expand Down