From 988a3179dfa1ba0aa42434d0facb9b5fdf5aae1c Mon Sep 17 00:00:00 2001 From: Maximilian Blatt Date: Fri, 26 Jul 2024 05:33:48 +0200 Subject: [PATCH] fix: Mark composite as unready if resources are skipped Signed-off-by: Maximilian Blatt --- fn.go | 12 +++++++++++- fn_test.go | 1 + 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/fn.go b/fn.go index 65ec639..dcb4118 100644 --- a/fn.go +++ b/fn.go @@ -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") @@ -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 } @@ -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 @@ -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 } diff --git a/fn_test.go b/fn_test.go index 565c801..a44d13e 100644 --- a/fn_test.go +++ b/fn_test.go @@ -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