Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactors operator requeues #1967

Merged
merged 1 commit into from
Feb 21, 2022
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
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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case - err is always nil as we return above when err is not nil.

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