From f201e5585692917f1856c5d2614792b95d321bb9 Mon Sep 17 00:00:00 2001 From: Yaron Yarimi Date: Wed, 21 Jul 2021 00:53:36 +0300 Subject: [PATCH] Treat PendingPodConditions configuration when determining whether pod is running Signed-off-by: yaronya --- pkg/scaling/executor/scale_jobs.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) 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++ } }