diff --git a/manager/searcher/searcher.go b/manager/searcher/searcher.go index bbb243c5c71..17592706379 100644 --- a/manager/searcher/searcher.go +++ b/manager/searcher/searcher.go @@ -192,7 +192,7 @@ func calculateIDCAffinityScore(dst, src string) float64 { return minScore } - if dst == src { + if strings.EqualFold(dst, src) { return maxScore } @@ -201,7 +201,7 @@ func calculateIDCAffinityScore(dst, src string) float64 { // it gets the max score of idc. srcElements := strings.Split(src, types.AffinitySeparator) for _, srcElement := range srcElements { - if dst == srcElement { + if strings.EqualFold(dst, srcElement) { return maxScore } } @@ -215,7 +215,7 @@ func calculateMultiElementAffinityScore(dst, src string) float64 { return minScore } - if dst == src { + if strings.EqualFold(dst, src) { return maxScore } @@ -231,7 +231,7 @@ func calculateMultiElementAffinityScore(dst, src string) float64 { } for i := 0; i < elementLen; i++ { - if dstElements[i] != srcElements[i] { + if !strings.EqualFold(dstElements[i], srcElements[i]) { break } diff --git a/manager/searcher/searcher_test.go b/manager/searcher/searcher_test.go index 2297794a3b9..e5b00bd75d8 100644 --- a/manager/searcher/searcher_test.go +++ b/manager/searcher/searcher_test.go @@ -371,11 +371,11 @@ func TestSearcher_FindSchedulerClusters(t *testing.T) { }, expect: func(t *testing.T, data []models.SchedulerCluster, err error) { assert := assert.New(t) - assert.Equal(data[0].Name, "bax") - assert.Equal(data[1].Name, "bae") - assert.Equal(data[2].Name, "foo") - assert.Equal(data[3].Name, "bar") - assert.Equal(data[4].Name, "baz") + assert.Equal(data[0].Name, "baz") + assert.Equal(data[1].Name, "bar") + assert.Equal(data[2].Name, "bax") + assert.Equal(data[3].Name, "bae") + assert.Equal(data[4].Name, "foo") assert.Equal(data[5].Name, "bac") assert.Equal(data[6].Name, "bat") assert.Equal(len(data), 7) diff --git a/scheduler/scheduling/evaluator/evaluator_base.go b/scheduler/scheduling/evaluator/evaluator_base.go index f6a72efd542..9016cdb4900 100644 --- a/scheduler/scheduling/evaluator/evaluator_base.go +++ b/scheduler/scheduling/evaluator/evaluator_base.go @@ -152,7 +152,11 @@ func calculateHostTypeScore(peer *resource.Peer) float64 { // calculateIDCAffinityScore 0.0~1.0 larger and better. func calculateIDCAffinityScore(dst, src string) float64 { - if dst != "" && src != "" && dst == src { + if dst == "" || src == "" { + return minScore + } + + if strings.EqualFold(dst, src) { return maxScore } @@ -165,7 +169,7 @@ func calculateMultiElementAffinityScore(dst, src string) float64 { return minScore } - if dst == src { + if strings.EqualFold(dst, src) { return maxScore } @@ -181,9 +185,10 @@ func calculateMultiElementAffinityScore(dst, src string) float64 { } for i := 0; i < elementLen; i++ { - if dstElements[i] != srcElements[i] { + if !strings.EqualFold(dstElements[i], srcElements[i]) { break } + score++ }