Skip to content

Commit

Permalink
Avoid repeating max wait duration computation
Browse files Browse the repository at this point in the history
  • Loading branch information
IrvingMg committed May 23, 2024
1 parent e97917b commit ce6ef21
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pkg/controller/core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func waitForPodsReady(cfg *configapi.WaitForPodsReady) *waitForPodsReadyConfig {
if cfg.RequeuingStrategy != nil {
result.requeuingBackoffBaseSeconds = *cfg.RequeuingStrategy.BackoffBaseSeconds
result.requeuingBackoffLimitCount = cfg.RequeuingStrategy.BackoffLimitCount
result.requeuingBackoffMaxSeconds = *cfg.RequeuingStrategy.BackoffMaxSeconds
result.requeuingBackoffMaxDuration = time.Duration(*cfg.RequeuingStrategy.BackoffMaxSeconds) * time.Second
result.requeuingBackoffJitter = 0.0001
}
return &result
Expand Down
7 changes: 3 additions & 4 deletions pkg/controller/core/workload_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ type waitForPodsReadyConfig struct {
timeout time.Duration
requeuingBackoffLimitCount *int32
requeuingBackoffBaseSeconds int32
requeuingBackoffMaxSeconds int32
requeuingBackoffMaxDuration time.Duration
requeuingBackoffJitter float64
}

Expand Down Expand Up @@ -468,9 +468,8 @@ func (r *WorkloadReconciler) triggerDeactivationOrBackoffRequeue(ctx context.Con
Steps: int(requeuingCount),
}
var waitDuration time.Duration
maxWaitDuration := time.Duration(r.waitForPodsReady.requeuingBackoffMaxSeconds) * time.Second
for backoff.Steps > 0 && waitDuration < maxWaitDuration {
waitDuration = min(backoff.Step(), maxWaitDuration)
for backoff.Steps > 0 && waitDuration < r.waitForPodsReady.requeuingBackoffMaxDuration {
waitDuration = min(backoff.Step(), r.waitForPodsReady.requeuingBackoffMaxDuration)
}

wl.Status.RequeueState.RequeueAt = ptr.To(metav1.NewTime(r.clock.Now().Add(waitDuration)))
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/core/workload_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ func TestReconcile(t *testing.T) {
requeuingBackoffLimitCount: ptr.To[int32](100),
requeuingBackoffBaseSeconds: 10,
requeuingBackoffJitter: 0,
requeuingBackoffMaxSeconds: 3600,
requeuingBackoffMaxDuration: time.Duration(3600) * time.Second,
}),
},
workload: utiltesting.MakeWorkload("wl", "ns").
Expand Down Expand Up @@ -598,7 +598,7 @@ func TestReconcile(t *testing.T) {
requeuingBackoffLimitCount: ptr.To[int32](100),
requeuingBackoffBaseSeconds: 10,
requeuingBackoffJitter: 0,
requeuingBackoffMaxSeconds: 7200,
requeuingBackoffMaxDuration: time.Duration(7200) * time.Second,
}),
},
workload: utiltesting.MakeWorkload("wl", "ns").
Expand Down

0 comments on commit ce6ef21

Please sign in to comment.