Skip to content

Commit

Permalink
Don't requeue successful writes in ReconcileObject
Browse files Browse the repository at this point in the history
  • Loading branch information
olim7t committed Dec 3, 2024
1 parent 5838166 commit 5bbd6af
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
6 changes: 2 additions & 4 deletions pkg/reconciliation/generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,9 @@ func ReconcileObject[U any, T Reconcileable[U]](ctx context.Context, kClient cli
}
return result.Error(err)
}
return result.RequeueSoon(requeueDelay)
} else {
return result.Error(err)
return result.Continue()
}
return result.Error(err)
}

if !annotations.CompareHashAnnotations(T(currentCm), T(&desiredObject)) {
Expand All @@ -52,7 +51,6 @@ func ReconcileObject[U any, T Reconcileable[U]](ctx context.Context, kClient cli
if err := kClient.Update(ctx, T(currentCm)); err != nil {
return result.Error(err)
}
return result.RequeueSoon(requeueDelay)
}
return result.Continue()
}
11 changes: 5 additions & 6 deletions pkg/reconciliation/generic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ func Test_ReconcileObject_UpdateDone(t *testing.T) {
kClient := testutils.NewFakeClientWRestMapper() // Reset the Client
// Launch reconciliation.
recRes := ReconcileObject(ctx, kClient, requeueDelay, desiredObject)
assert.True(t, recRes.IsRequeue())
// Should update immediately and signal we can continue
assert.False(t, recRes.Completed())
// After the update we should see the expected ConfigMap
afterUpdateCM := &corev1.ConfigMap{}
err := kClient.Get(ctx,
Expand All @@ -42,15 +43,13 @@ func Test_ReconcileObject_UpdateDone(t *testing.T) {
},
afterUpdateCM)
assert.NoError(t, err)
// If we reconcile again, we should move into the Done state.
recRes = ReconcileObject(ctx, kClient, requeueDelay, desiredObject)
assert.False(t, recRes.Completed())
}

func Test_ReconcileObject_CreateSuccess(t *testing.T) {
kClient := testutils.NewFakeClientWRestMapper() // Reset the Client
recRes := ReconcileObject(ctx, kClient, requeueDelay, desiredObject)
assert.True(t, recRes.IsRequeue())
// Should create immediately and signal we can continue
assert.False(t, recRes.Completed())
actualCm := &corev1.ConfigMap{}
err := kClient.Get(ctx, types.NamespacedName{Name: desiredObject.Name, Namespace: desiredObject.Namespace}, actualCm)
assert.NoError(t, err)
Expand All @@ -75,7 +74,7 @@ func Test_ReconcileObject_UpdateSuccess(t *testing.T) {
}
// Launch reconciliation.
recRes := ReconcileObject(ctx, kClient, requeueDelay, desiredObject)
assert.True(t, recRes.IsRequeue())
assert.False(t, recRes.Completed())
annotations.AddHashAnnotation(&desiredObject)
// After the update we should see the expected ConfigMap
afterUpdateCM := &corev1.ConfigMap{}
Expand Down

0 comments on commit 5bbd6af

Please sign in to comment.