Merge pull request #111047 from SataQiu/fix-scheduler-20220709

scheduler: improve the comment and add more unit test cases for DefaultNormalizeScore
This commit is contained in:
Kubernetes Prow Robot 2022-07-18 15:36:17 -07:00 committed by GitHub
commit e56cda48d3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 2 deletions

View File

@ -21,8 +21,9 @@ import (
) )
// DefaultNormalizeScore generates a Normalize Score function that can normalize the // DefaultNormalizeScore generates a Normalize Score function that can normalize the
// scores to [0, maxPriority]. If reverse is set to true, it reverses the scores by // scores from [0, max(scores)] to [0, maxPriority]. If reverse is set to true, it
// subtracting it from maxPriority. // reverses the scores by subtracting it from maxPriority.
// Note: The input scores are always assumed to be non-negative integers.
func DefaultNormalizeScore(maxPriority int64, reverse bool, scores framework.NodeScoreList) *framework.Status { func DefaultNormalizeScore(maxPriority int64, reverse bool, scores framework.NodeScoreList) *framework.Status {
var maxCount int64 var maxCount int64
for i := range scores { for i := range scores {

View File

@ -61,6 +61,15 @@ func TestDefaultNormalizeScore(t *testing.T) {
scores: []int64{0, 1, 1, 1}, scores: []int64{0, 1, 1, 1},
expectedScores: []int64{100, 0, 0, 0}, expectedScores: []int64{100, 0, 0, 0},
}, },
{
scores: []int64{0, 0, 0, 0},
expectedScores: []int64{0, 0, 0, 0},
},
{
reverse: true,
scores: []int64{0, 0, 0, 0},
expectedScores: []int64{100, 100, 100, 100},
},
} }
for i, test := range tests { for i, test := range tests {