@@ -17,6 +17,7 @@ limitations under the License.
17
17
package scheduling
18
18
19
19
import (
20
+ "fmt"
20
21
"math/rand/v2"
21
22
22
23
"sigs.k8s.io/controller-runtime/pkg/log"
@@ -52,22 +53,32 @@ func (sm *ScorerMng) scoreTargets(ctx *types.Context, pods []*types.PodMetrics)
52
53
logger := log .FromContext (ctx )
53
54
54
55
podsTotalScore := make (map [* types.PodMetrics ]float64 )
56
+ validPods := make ([]* types.PodMetrics , 0 )
55
57
56
- // initialize zero score for all pods
58
+ // initialize zero score for all pods + check that pods are valid
57
59
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" )
59
70
}
60
71
61
72
// add scores from all scorers
62
73
for _ , scorer := range sm .scorers {
63
- scoredPods , err := scorer .ScoreTargets (ctx , pods )
74
+ scoredPods , err := scorer .ScoreTargets (ctx , validPods )
64
75
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
+ }
71
82
}
72
83
}
73
84
0 commit comments