Skip to content

Commit

Permalink
fix: requeue interval change (#357)
Browse files Browse the repository at this point in the history
* fix: requeue interval chanage

Signed-off-by: Derek Wang <[email protected]>

* test case

Signed-off-by: Derek Wang <[email protected]>
  • Loading branch information
whynowy authored Sep 20, 2021
1 parent aa36855 commit 6cd0639
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
22 changes: 11 additions & 11 deletions manager/controllers/scaling/scaling.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,16 @@ func evalAsDuration(input string, env map[string]interface{}) (time.Duration, er
}
}

func RequeueAfter(step dfv1.Step, currentReplicas, desiredReplicas int) (time.Duration, error) {
if currentReplicas <= 0 && desiredReplicas == 0 {
scale := step.Spec.Scale
if scalingDelay, err := evalAsDuration(scale.ScalingDelay, map[string]interface{}{
"defaultScalingDelay": defaultScalingDelay,
}); err != nil {
return 0, fmt.Errorf("failed to evaluate %q: %w", scale.ScalingDelay, err)
} else {
return scalingDelay, nil
}
func RequeueAfter(step dfv1.Step) (time.Duration, error) {
scale := step.Spec.Scale
if scale.DesiredReplicas == "" {
return 0, nil
}
if scalingDelay, err := evalAsDuration(scale.ScalingDelay, map[string]interface{}{
"defaultScalingDelay": defaultScalingDelay,
}); err != nil {
return 0, fmt.Errorf("failed to evaluate %q: %w", scale.ScalingDelay, err)
} else {
return scalingDelay, nil
}
return 0, nil
}
8 changes: 4 additions & 4 deletions manager/controllers/scaling/scaling_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func TestGetDesiredReplicas(t *testing.T) {

func TestRequeueAfter(t *testing.T) {
t.Run("ScaledUp", func(t *testing.T) {
requeueAfter, err := RequeueAfter(dfv1.Step{}, 1, 0)
requeueAfter, err := RequeueAfter(dfv1.Step{})
assert.NoError(t, err)
assert.Equal(t, time.Duration(0), requeueAfter)
})
Expand All @@ -79,16 +79,16 @@ func TestRequeueAfter(t *testing.T) {
Spec: dfv1.StepSpec{
Scale: dfv1.Scale{ScalingDelay: `"4m"`},
},
}, 0, 1)
})
assert.NoError(t, err)
assert.Equal(t, time.Duration(0), requeueAfter)
})
t.Run("NoPeek", func(t *testing.T) {
requeueAfter, err := RequeueAfter(dfv1.Step{
Spec: dfv1.StepSpec{
Scale: dfv1.Scale{ScalingDelay: `"4m"`},
Scale: dfv1.Scale{ScalingDelay: `"4m"`, DesiredReplicas: `limit(pending / (10 * 60 * 1000), 0, 1, 1)`},
},
}, 0, 0)
})
assert.NoError(t, err)
assert.Equal(t, 4*time.Minute, requeueAfter)
})
Expand Down
2 changes: 1 addition & 1 deletion manager/controllers/step_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ func (r *StepReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.
}
}

requeueAfter, err := scaling.RequeueAfter(*step, currentReplicas, desiredReplicas)
requeueAfter, err := scaling.RequeueAfter(*step)
if err != nil {
return ctrl.Result{}, err
}
Expand Down

0 comments on commit 6cd0639

Please sign in to comment.