Skip to content

Commit 645ac5d

Browse files
committed
fix: ensure resource status is patched before checking for updates on
1 parent 27b3c92 commit 645ac5d

File tree

2 files changed

+10
-15
lines changed

2 files changed

+10
-15
lines changed

pkg/runtime/reconciler.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,12 @@ func (r *resourceReconciler) Sync(
615615
return latest, err
616616
}
617617
r.rd.MarkAdopted(latest)
618+
// ensure status is patched before checking for updates
619+
err = r.patchResourceStatus(ctx, desired, latest)
620+
if err != nil {
621+
return latest, err
622+
}
623+
return latest, requeue.Needed(fmt.Errorf("requeuing to check for updates"))
618624
}
619625
if latest, err = r.updateResource(ctx, rm, resolved, latest); err != nil {
620626
return latest, err

pkg/runtime/reconciler_test.go

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ func TestReconcilerAdoptOrCreateResource_Adopt(t *testing.T) {
532532
ackv1alpha1.AnnotationAdoptionPolicy: "adopt-or-create",
533533
ackv1alpha1.AnnotationAdoptionFields: adoptionFieldsString,
534534
})
535-
updated, updatedRTObj, _ := resourceMocks()
535+
updated, _, _ := resourceMocks()
536536
updated.On("Identifiers").Return(ids)
537537
updated.On("Conditions").Return([]*ackv1alpha1.Condition{})
538538
updated.On("MetaObject").Return(metav1.ObjectMeta{
@@ -572,28 +572,17 @@ func TestReconcilerAdoptOrCreateResource_Adopt(t *testing.T) {
572572
ackv1alpha1.AnnotationAdoptionFields: adoptionFieldsString,
573573
ackv1alpha1.AnnotationAdopted: "true",
574574
})
575-
// setManaged
576-
rd.On("Delta", latest, latest).Return(ackcompare.NewDelta()).Once()
577-
// update
578-
rd.On("Delta", desired, latest).Return(delta).Once()
579-
//
580-
rd.On("Delta", desired, updated).Return(ackcompare.NewDelta())
581-
rd.On("Delta", updated, updated).Return(ackcompare.NewDelta())
582-
rd.On("MarkAdopted", updated).Return().Once()
583575

584576
r, kc, scmd := reconcilerMocks(rmf)
585577
rm.On("EnsureTags", ctx, desired, scmd).Return(nil)
586578
statusWriter := &ctrlrtclientmock.SubResourceWriter{}
587579
kc.On("Status").Return(statusWriter)
588580
kc.On("Patch", withoutCancelContextMatcher, latestRTObj, mock.AnythingOfType("*client.mergeFromPatch")).Return(nil)
589-
kc.On("Patch", withoutCancelContextMatcher, updatedRTObj, mock.AnythingOfType("*client.mergeFromPatch")).Return(nil)
590-
statusWriter.On("Patch", withoutCancelContextMatcher, updatedRTObj, mock.AnythingOfType("*client.mergeFromPatch")).Return(nil)
581+
statusWriter.On("Patch", withoutCancelContextMatcher, latestRTObj, mock.AnythingOfType("*client.mergeFromPatch")).Return(nil)
591582
_, err := r.Sync(ctx, rm, desired)
592-
require.Nil(err)
583+
require.NotNil(err)
593584
rm.AssertNumberOfCalls(t, "ReadOne", 1)
594-
rm.AssertCalled(t, "Update", ctx, desired, latest, delta)
595-
rd.AssertCalled(t, "Delta", desired, latest)
596-
rd.AssertNumberOfCalls(t, "MarkAdopted", 2)
585+
rd.AssertNumberOfCalls(t, "MarkAdopted", 1)
597586
// Assert that the resource is not created or updated
598587
rm.AssertNumberOfCalls(t, "Create", 0)
599588
}

0 commit comments

Comments
 (0)