diff --git a/pkg/scaling/executor/scale_jobs.go b/pkg/scaling/executor/scale_jobs.go index 76b81dc9a60..fdd83e0fb80 100644 --- a/pkg/scaling/executor/scale_jobs.go +++ b/pkg/scaling/executor/scale_jobs.go @@ -162,7 +162,7 @@ func (e *scaleExecutor) getRunningJobCount(scaledJob *kedav1alpha1.ScaledJob) in return runningJobs } -func (e *scaleExecutor) isAnyPodRunningOrCompleted(j *batchv1.Job) bool { +func (e *scaleExecutor) isAnyPodRunningOrCompleted(j *batchv1.Job, s *kedav1alpha1.ScalingStrategy) bool { opts := []client.ListOption{ client.InNamespace(j.GetNamespace()), client.MatchingLabels(map[string]string{"job-name": j.GetName()}), @@ -176,6 +176,16 @@ func (e *scaleExecutor) isAnyPodRunningOrCompleted(j *batchv1.Job) bool { } for _, pod := range pods.Items { + if len(s.PendingPodConditions) > 0 { + for _, pendingConditionType := range s.PendingPodConditions { + for _, podCondition := range pod.Status.Conditions { + if string(podCondition.Type) == pendingConditionType && podCondition.Status == corev1.ConditionTrue { + return true + } + } + } + } + if pod.Status.Phase == corev1.PodSucceeded || pod.Status.Phase == corev1.PodRunning { return true } @@ -201,7 +211,7 @@ func (e *scaleExecutor) getPendingJobCount(scaledJob *kedav1alpha1.ScaledJob) in for _, job := range jobs.Items { job := job - if !e.isJobFinished(&job) && !e.isAnyPodRunningOrCompleted(&job) { + if !e.isJobFinished(&job) && !e.isAnyPodRunningOrCompleted(&job, &scaledJob.Spec.ScalingStrategy) { pendingJobs++ } }