Optimize NormalizeScore for PodTopologySpread

Change-Id: I928174a220c8c0f4b69180fdfb2f075278a482be
This commit is contained in:
Aldo Culquicondor 2020-10-22 17:05:00 -04:00
parent ab7a38220f
commit e721576d55

View File

@ -30,6 +30,7 @@ import (
) )
const preScoreStateKey = "PreScore" + Name const preScoreStateKey = "PreScore" + Name
const invalidScore = -1
// preScoreState computed at PreScore and used at Score. // preScoreState computed at PreScore and used at Score.
// Fields are exported for comparison during testing. // Fields are exported for comparison during testing.
@ -219,9 +220,10 @@ func (pl *PodTopologySpread) NormalizeScore(ctx context.Context, cycleState *fra
// Calculate <minScore> and <maxScore> // Calculate <minScore> and <maxScore>
var minScore int64 = math.MaxInt64 var minScore int64 = math.MaxInt64
var maxScore int64 var maxScore int64
for _, score := range scores { for i, score := range scores {
// it's mandatory to check if <score.Name> is present in m.IgnoredNodes // it's mandatory to check if <score.Name> is present in m.IgnoredNodes
if s.IgnoredNodes.Has(score.Name) { if s.IgnoredNodes.Has(score.Name) {
scores[i].Score = invalidScore
continue continue
} }
if score.Score < minScore { if score.Score < minScore {
@ -233,22 +235,14 @@ func (pl *PodTopologySpread) NormalizeScore(ctx context.Context, cycleState *fra
} }
for i := range scores { for i := range scores {
nodeInfo, err := pl.sharedLister.NodeInfos().Get(scores[i].Name) if scores[i].Score == invalidScore {
if err != nil {
return framework.AsStatus(err)
}
node := nodeInfo.Node()
if s.IgnoredNodes.Has(node.Name) {
scores[i].Score = 0 scores[i].Score = 0
continue continue
} }
if maxScore == 0 { if maxScore == 0 {
scores[i].Score = framework.MaxNodeScore scores[i].Score = framework.MaxNodeScore
continue continue
} }
s := scores[i].Score s := scores[i].Score
scores[i].Score = framework.MaxNodeScore * (maxScore + minScore - s) / maxScore scores[i].Score = framework.MaxNodeScore * (maxScore + minScore - s) / maxScore
} }