Skip to content

Commit

Permalink
feat: case insensitive string comparison in evaluater package of the …
Browse files Browse the repository at this point in the history
…manager (#2632)

Signed-off-by: Gaius <[email protected]>
  • Loading branch information
gaius-qi authored Aug 15, 2023
1 parent 47807bd commit 732819b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
8 changes: 4 additions & 4 deletions manager/searcher/searcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ func calculateIDCAffinityScore(dst, src string) float64 {
return minScore
}

if dst == src {
if strings.EqualFold(dst, src) {
return maxScore
}

Expand All @@ -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
}
}
Expand All @@ -215,7 +215,7 @@ func calculateMultiElementAffinityScore(dst, src string) float64 {
return minScore
}

if dst == src {
if strings.EqualFold(dst, src) {
return maxScore
}

Expand All @@ -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
}

Expand Down
10 changes: 5 additions & 5 deletions manager/searcher/searcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 8 additions & 3 deletions scheduler/scheduling/evaluator/evaluator_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -165,7 +169,7 @@ func calculateMultiElementAffinityScore(dst, src string) float64 {
return minScore
}

if dst == src {
if strings.EqualFold(dst, src) {
return maxScore
}

Expand All @@ -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++
}

Expand Down

0 comments on commit 732819b

Please sign in to comment.