diff --git a/cluster-autoscaler/core/static_autoscaler.go b/cluster-autoscaler/core/static_autoscaler.go index 60ac1fe9d5aa..32b9251e677d 100644 --- a/cluster-autoscaler/core/static_autoscaler.go +++ b/cluster-autoscaler/core/static_autoscaler.go @@ -984,7 +984,10 @@ func (a *StaticAutoscaler) filterOutYoungPods(allUnschedulablePods []*apiv1.Pod, } } - if podAge > podScaleUpDelay { + // newPodScaleUpDelay <= 0 means that young pod filtering out is disabled. + // As pod age is calculated from CA loop start time, it is technically possible that some pods will have negative + // age and would be unnecessarily skipped by the current loop. + if podScaleUpDelay <= 0 || podAge > podScaleUpDelay { oldUnschedulablePods = append(oldUnschedulablePods, pod) } else { klog.V(3).Infof("Pod %s is %.3f seconds old, too new to consider unschedulable", pod.Name, podAge.Seconds()) diff --git a/cluster-autoscaler/core/static_autoscaler_test.go b/cluster-autoscaler/core/static_autoscaler_test.go index 7f76b5c481a5..9719e3f3334b 100644 --- a/cluster-autoscaler/core/static_autoscaler_test.go +++ b/cluster-autoscaler/core/static_autoscaler_test.go @@ -2836,6 +2836,8 @@ func TestFilterOutYoungPods(t *testing.T) { p4.Annotations = map[string]string{ annotations.PodScaleUpDelayAnnotationKey: "error", } + p5 := BuildTestPod("p5", 500, 1000) + p5.CreationTimestamp = metav1.NewTime(now) tests := []struct { name string @@ -2882,6 +2884,20 @@ func TestFilterOutYoungPods(t *testing.T) { expectedPods: []*apiv1.Pod{p1, p4}, expectedError: "Failed to parse pod", }, + { + name: "future pods included when podScaleUpDelay is 0", + newPodScaleUpDelay: 0, + runTime: now, + pods: []*apiv1.Pod{p1, p5}, + expectedPods: []*apiv1.Pod{p1, p5}, + }, + { + name: "future pods excluded when podScaleUpDelay is above 0", + newPodScaleUpDelay: 1 * time.Second, + runTime: now, + pods: []*apiv1.Pod{p1, p5}, + expectedPods: []*apiv1.Pod{p1}, + }, } for _, tt := range tests {