diff --git a/manager/controllers/scaling/scaling.go b/manager/controllers/scaling/scaling.go index 4470acf8..6614f4f9 100644 --- a/manager/controllers/scaling/scaling.go +++ b/manager/controllers/scaling/scaling.go @@ -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 } diff --git a/manager/controllers/scaling/scaling_test.go b/manager/controllers/scaling/scaling_test.go index 643736e5..22f8a335 100644 --- a/manager/controllers/scaling/scaling_test.go +++ b/manager/controllers/scaling/scaling_test.go @@ -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) }) @@ -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) }) diff --git a/manager/controllers/step_controller.go b/manager/controllers/step_controller.go index f828e680..a1832b87 100644 --- a/manager/controllers/step_controller.go +++ b/manager/controllers/step_controller.go @@ -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 }