Skip to content

Commit abd4648

Browse files
committed
Eviction: Normalize polling time, fix RequeueAfter<=0
`RequeueAfter: 0` is not supported, `Requeue: true` is deprecated, so normalize on some default times.
1 parent a3eb7db commit abd4648

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

internal/controller/eviction_controller.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ type EvictionReconciler struct {
5353
const (
5454
evictionFinalizerName = "eviction-controller.cloud.sap/finalizer"
5555
EvictionControllerName = "eviction"
56+
shortRetryTime = 1 * time.Second
57+
defaultPollTime = 10 * time.Second
5658
)
5759

5860
// +kubebuilder:rbac:groups=kvm.cloud.sap,resources=evictions,verbs=get;list;watch;create;update;patch;delete
@@ -253,7 +255,7 @@ func (r *EvictionReconciler) evictNext(ctx context.Context, eviction *kvmv1.Evic
253255
switch vm.Status {
254256
case "MIGRATING", "RESIZE":
255257
// wait for the migration to finish
256-
return ctrl.Result{RequeueAfter: 5 * time.Second}, nil
258+
return ctrl.Result{RequeueAfter: defaultPollTime}, nil
257259
case "ERROR":
258260
// Needs manual intervention (or another operator fixes it)
259261
// put it at the end of the list (beginning of array)
@@ -290,7 +292,7 @@ func (r *EvictionReconciler) evictNext(ctx context.Context, eviction *kvmv1.Evic
290292
if gophercloud.ResponseCodeIs(err, http.StatusNotFound) {
291293
log.Info("Instance is gone")
292294
// Fall-back to beginning, which will clean it out
293-
return ctrl.Result{Requeue: true}, nil
295+
return ctrl.Result{RequeueAfter: shortRetryTime}, nil
294296
}
295297
// Retry confirm in next reconciliation
296298
return ctrl.Result{}, err
@@ -322,7 +324,7 @@ func (r *EvictionReconciler) evictNext(ctx context.Context, eviction *kvmv1.Evic
322324
if gophercloud.ResponseCodeIs(err, http.StatusNotFound) {
323325
log.Info("Instance is gone")
324326
// Fall-back to beginning, which will clean it out
325-
return ctrl.Result{RequeueAfter: 0}, nil
327+
return ctrl.Result{RequeueAfter: shortRetryTime}, nil
326328
}
327329
copy((*instances)[1:], (*instances)[:len(*instances)-1])
328330
(*instances)[0] = uuid
@@ -344,7 +346,7 @@ func (r *EvictionReconciler) evictNext(ctx context.Context, eviction *kvmv1.Evic
344346
if err := r.coldMigrate(ctx, vm.ID, eviction); err != nil {
345347
if gophercloud.ResponseCodeIs(err, http.StatusNotFound) {
346348
log.Info("Instance is gone")
347-
return ctrl.Result{RequeueAfter: 0}, nil
349+
return ctrl.Result{RequeueAfter: shortRetryTime}, nil
348350
}
349351
copy((*instances)[1:], (*instances)[:len(*instances)-1])
350352
(*instances)[0] = uuid
@@ -366,7 +368,7 @@ func (r *EvictionReconciler) evictNext(ctx context.Context, eviction *kvmv1.Evic
366368
// Triggered a migration, give it a generous time to start, so we do not
367369
// see the old state because the migration didn't start
368370
log.Info("poll")
369-
return ctrl.Result{RequeueAfter: 30 * time.Second}, err
371+
return ctrl.Result{RequeueAfter: defaultPollTime}, err
370372
}
371373

372374
func (r *EvictionReconciler) evictionReason(eviction *kvmv1.Eviction) string {

0 commit comments

Comments
 (0)