Skip to content

Commit

Permalink
Refactors operator requeues
Browse files Browse the repository at this point in the history
* Adds the clarifying comment on requeues into the checker controller
* Removes `Requeue: true` in places where we use `RequeueAfter`
  as it is has no effect.
  • Loading branch information
m1kola committed Feb 15, 2022
1 parent 7ffb8d3 commit 3ba8363
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
6 changes: 5 additions & 1 deletion pkg/operator/controllers/checker/checker_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,11 @@ func (r *Reconciler) Reconcile(ctx context.Context, request ctrl.Request) (ctrl.
}
}

return reconcile.Result{RequeueAfter: time.Hour, Requeue: true}, err
// We always requeue here:
// * Either immediately (with rate limiting) based on the error
// when err != nil.
// * Or based on RequeueAfter when err == nil.
return reconcile.Result{RequeueAfter: time.Hour}, err
}

// SetupWithManager setup our manager
Expand Down
4 changes: 1 addition & 3 deletions pkg/operator/controllers/node/node_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, request ctrl.Request) (ctrl.
deadline := t.Add(gracePeriod)
now := time.Now()
if deadline.After(now) {
return reconcile.Result{
RequeueAfter: deadline.Sub(now),
}, err
return reconcile.Result{RequeueAfter: deadline.Sub(now)}, nil
}

// drain the node disabling eviction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, request ctrl.Request) (ctrl.
return reconcile.Result{}, err
}
}
return reconcile.Result{RequeueAfter: time.Hour, Requeue: true}, nil
return reconcile.Result{RequeueAfter: time.Hour}, nil
}

// SetupWithManager setup our manager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,15 @@ func TestWorkaroundReconciler(t *testing.T) {
c := mw.EXPECT().IsRequired(gomock.Any()).Return(true)
mw.EXPECT().Ensure(gomock.Any()).After(c).Return(nil)
},
want: ctrl.Result{Requeue: true, RequeueAfter: time.Hour},
want: ctrl.Result{RequeueAfter: time.Hour},
},
{
name: "is not required",
mocker: func(mw *mock_workaround.MockWorkaround) {
c := mw.EXPECT().IsRequired(gomock.Any()).Return(false)
mw.EXPECT().Remove(gomock.Any()).After(c).Return(nil)
},
want: ctrl.Result{Requeue: true, RequeueAfter: time.Hour},
want: ctrl.Result{RequeueAfter: time.Hour},
},
{
name: "has error",
Expand Down

0 comments on commit 3ba8363

Please sign in to comment.