Skip to content

Commit aca8e07

Browse files
committed
- Check for nils in list of available pods in main scoring function of ScoreMng
- If some specific scorer failed to score pods - just log the problem, skip it and continue to the next scorer
1 parent a05a573 commit aca8e07

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

pkg/epp/scheduling/scorer.go

+20-9
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package scheduling
1818

1919
import (
20+
"fmt"
2021
"math/rand/v2"
2122

2223
"sigs.k8s.io/controller-runtime/pkg/log"
@@ -52,22 +53,32 @@ func (sm *ScorerMng) scoreTargets(ctx *types.Context, pods []*types.PodMetrics)
5253
logger := log.FromContext(ctx)
5354

5455
podsTotalScore := make(map[*types.PodMetrics]float64)
56+
validPods := make([]*types.PodMetrics, 0)
5557

56-
// initialize zero score for all pods
58+
// initialize zero score for all pods + check that pods are valid
5759
for _, pod := range pods {
58-
podsTotalScore[pod] = 0.0
60+
if pod == nil || pod.Pod == nil || pod.Metrics == nil {
61+
logger.Info("Invalid/empty pod skipped in scoring process")
62+
} else {
63+
validPods = append(validPods, pod)
64+
podsTotalScore[pod] = 0.0
65+
}
66+
}
67+
68+
if len(validPods) == 0 {
69+
return nil, fmt.Errorf("Empty list of valid pods to score")
5970
}
6071

6172
// add scores from all scorers
6273
for _, scorer := range sm.scorers {
63-
scoredPods, err := scorer.ScoreTargets(ctx, pods)
74+
scoredPods, err := scorer.ScoreTargets(ctx, validPods)
6475
if err != nil {
65-
logger.Info(">>> In scoreTargets, score targets returned error", "error", err)
66-
return nil, err
67-
}
68-
69-
for _, scoredPod := range scoredPods {
70-
podsTotalScore[scoredPod.Pod] += scoredPod.Score
76+
// in case scorer failed - don't use it in the total score, but continue to other scorers
77+
logger.Error(err, "Score targets returned error in scorer")
78+
} else {
79+
for _, scoredPod := range scoredPods {
80+
podsTotalScore[scoredPod.Pod] += scoredPod.Score
81+
}
7182
}
7283
}
7384

0 commit comments

Comments
 (0)