Skip to content

Commit

Permalink
fix: Mark composite as unready if resources are skipped
Browse files Browse the repository at this point in the history
Signed-off-by: Maximilian Blatt <[email protected]>
  • Loading branch information
MisterMX committed Jul 26, 2024
1 parent 4476a5b commit 988a317
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
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
}

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

0 comments on commit 988a317

Please sign in to comment.