Skip to content

Commit b63ed73

Browse files
authored
Merge pull request #137 from MisterMX/fix/skipped-composite-unready
fix: Mark composite as unready if resources are skipped
2 parents dcd985a + 988a317 commit b63ed73

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

fn.go

+11-1
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,9 @@ func (f *Function) RunFunction(ctx context.Context, req *fnv1beta1.RunFunctionRe
148148
// composed resource.
149149
existing := 0
150150

151+
// Increments this for each resource template that has been skipped
152+
skipped := 0
153+
151154
for _, t := range cts {
152155
log := log.WithValues("resource-template-name", t.Name)
153156
log.Debug("Processing resource template")
@@ -258,6 +261,7 @@ func (f *Function) RunFunction(ctx context.Context, req *fnv1beta1.RunFunctionRe
258261
// Skip adding this resource to the desired state because it doesn't
259262
// exist yet, and a required FromFieldPath was not (yet) found.
260263
if skip {
264+
skipped++
261265
continue
262266
}
263267

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

276+
if skipped > 0 {
277+
rsp.GetDesired().GetComposite().Ready = fnv1beta1.Ready_READY_FALSE
278+
}
279+
272280
if err := response.SetDesiredComposedResources(rsp, desired); err != nil {
273281
response.Fatal(rsp, errors.Wrapf(err, "cannot set desired composed resources in %T", rsp))
274282
return rsp, nil
@@ -284,7 +292,9 @@ func (f *Function) RunFunction(ctx context.Context, req *fnv1beta1.RunFunctionRe
284292
log.Info("Successfully processed patch-and-transform resources",
285293
"resource-templates", len(input.Resources),
286294
"existing-resources", existing,
287-
"warnings", warnings)
295+
"warnings", warnings,
296+
"skipped", skipped,
297+
)
288298

289299
return rsp, nil
290300
}

fn_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,7 @@ func TestRunFunction(t *testing.T) {
525525
Desired: &fnv1beta1.State{
526526
Composite: &fnv1beta1.Resource{
527527
Resource: resource.MustStructJSON(`{"apiVersion":"example.org/v1","kind":"XR","spec":{"widgets":"10"}}`),
528+
Ready: fnv1beta1.Ready_READY_FALSE,
528529
},
529530
Resources: map[string]*fnv1beta1.Resource{
530531
// Note that the first patch did work. We only

0 commit comments

Comments
 (0)