Skip to content
Merged
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
9 changes: 5 additions & 4 deletions pkg/controller/status_updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,22 +177,23 @@ func defaultPhaseUpdateFunc[Obj client.Object, PhType ~string, ConType comparabl
// The object is expected to be a pointer to a struct with the status field.
// If the 'Object' field in the ReconcileResult is nil, the status update becomes a no-op.
func (s *statusUpdater[Obj, PhType, ConType]) UpdateStatus(ctx context.Context, c client.Client, rr ReconcileResult[Obj, ConType]) (ctrl.Result, error) {
errs := errors.NewReasonableErrorList(rr.ReconcileError)
if IsNil(rr.Object) {
return rr.Result, nil
return rr.Result, errs.Aggregate()
}
if s.fieldNames[STATUS_FIELD] == "" {
return rr.Result, nil
return rr.Result, errs.Aggregate()
}
if IsNil(rr.OldObject) || IsSameObject(rr.OldObject, rr.Object) {
// create old object based on given one
rr.OldObject = rr.Object.DeepCopyObject().(Obj)
}
status := GetField(rr.Object, s.fieldNames[STATUS_FIELD], true)
if IsNil(status) {
return rr.Result, fmt.Errorf("unable to get pointer to status field '%s' of object %T", s.fieldNames[STATUS_FIELD], rr.Object)
errs.Append(errors.WithReason(fmt.Errorf("unable to get pointer to status field '%s' of object %T", s.fieldNames[STATUS_FIELD], rr.Object), "InternalError"))
return rr.Result, errs.Aggregate()
}

errs := errors.NewReasonableErrorList(rr.ReconcileError)
now := time.Now()
if s.fieldNames[STATUS_FIELD_LAST_RECONCILE_TIME] != "" {
SetField(status, s.fieldNames[STATUS_FIELD_LAST_RECONCILE_TIME], metav1.NewTime(now))
Expand Down
10 changes: 10 additions & 0 deletions pkg/controller/status_updater_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@ var _ = Describe("Status Updater", func() {
))
})

It("should not hide a reconciliation error if the object is nil", func() {
env := testutils.NewEnvironmentBuilder().WithFakeClient(coScheme).WithInitObjectPath("testdata", "test-02").WithDynamicObjectsWithStatus(&CustomObject{}).Build()
rr := controller.ReconcileResult[*CustomObject, ConditionStatus]{
ReconcileError: errors.WithReason(fmt.Errorf("test error"), "TestError"),
}
su := preconfiguredStatusUpdaterBuilder().Build()
_, err := su.UpdateStatus(env.Ctx, env.Client(), rr)
Expect(err).To(HaveOccurred())
})

It("should update an existing status", func() {
env := testutils.NewEnvironmentBuilder().WithFakeClient(coScheme).WithInitObjectPath("testdata", "test-02").WithDynamicObjectsWithStatus(&CustomObject{}).Build()
obj := &CustomObject{}
Expand Down