Skip to content
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

fix: Mark composite as unready if resources are skipped #137

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
12 changes: 11 additions & 1 deletion fn.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ func (f *Function) RunFunction(ctx context.Context, req *fnv1beta1.RunFunctionRe
// composed resource.
existing := 0

// Increments this for each resource template that has been skipped
skipped := 0

for _, t := range cts {
log := log.WithValues("resource-template-name", t.Name)
log.Debug("Processing resource template")
Expand Down Expand Up @@ -258,6 +261,7 @@ func (f *Function) RunFunction(ctx context.Context, req *fnv1beta1.RunFunctionRe
// Skip adding this resource to the desired state because it doesn't
// exist yet, and a required FromFieldPath was not (yet) found.
if skip {
skipped++
continue
}

Expand All @@ -269,6 +273,10 @@ func (f *Function) RunFunction(ctx context.Context, req *fnv1beta1.RunFunctionRe
return rsp, nil
}

if skipped > 0 {
rsp.GetDesired().GetComposite().Ready = fnv1beta1.Ready_READY_FALSE
}
Comment on lines +276 to +278
Copy link
Member

Choose a reason for hiding this comment

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

Unfortunately I don't think this'll work. Functions can't directly specify the readiness of the XR, they're supposed to influence it by specifying the readiness of composed resources.

https://github.com/crossplane/function-sdk-go/blob/29ea8ddbfa554ede602e4ca7f13c5883112159a3/proto/v1beta1/run_function.proto#L230-L231

Obviously that makes this tricky, given Crossplane wouldn't even know the composed resource exists in this case. 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, tests turned out, that it is not working as expected since the ready state of the composite is hardcoded in crossplane to be determined by the ready state of the composed resources.

We have implemented a workaround that sets an arbitrary composed resource to unready until a set of dependent resources is available. Its more like a hack than an actual solution but it seems to be the only way to prevent this issue at the moment.

@negz are there any plans to change this behaviour in the implementation of the function renderer of Crossplane? It is very confusing that the ready field exists but is not recognized at all.


if err := response.SetDesiredComposedResources(rsp, desired); err != nil {
response.Fatal(rsp, errors.Wrapf(err, "cannot set desired composed resources in %T", rsp))
return rsp, nil
Expand All @@ -284,7 +292,9 @@ func (f *Function) RunFunction(ctx context.Context, req *fnv1beta1.RunFunctionRe
log.Info("Successfully processed patch-and-transform resources",
"resource-templates", len(input.Resources),
"existing-resources", existing,
"warnings", warnings)
"warnings", warnings,
"skipped", skipped,
)

return rsp, nil
}
1 change: 1 addition & 0 deletions fn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,7 @@ func TestRunFunction(t *testing.T) {
Desired: &fnv1beta1.State{
Composite: &fnv1beta1.Resource{
Resource: resource.MustStructJSON(`{"apiVersion":"example.org/v1","kind":"XR","spec":{"widgets":"10"}}`),
Ready: fnv1beta1.Ready_READY_FALSE,
},
Resources: map[string]*fnv1beta1.Resource{
// Note that the first patch did work. We only
Expand Down