Skip to content

Commit

Permalink
feat: dfdaemon match scheduler with case insensitive (#1181)
Browse files Browse the repository at this point in the history
Signed-off-by: Gaius <[email protected]>
  • Loading branch information
gaius-qi committed Jun 28, 2023
1 parent e77acb0 commit ce85054
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 5 deletions.
10 changes: 5 additions & 5 deletions manager/searcher/searcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func FilterSchedulerClusters(conditions map[string]string, schedulerClusters []m
// scheduler cluster SecurityRules also exists,
// then security_domain and SecurityRules are equal to match.
for _, securityRule := range schedulerCluster.SecurityGroup.SecurityRules {
if securityRule.Domain == securityDomain {
if strings.EqualFold(securityRule.Domain, securityDomain) {
clusters = append(clusters, schedulerCluster)
}
}
Expand Down Expand Up @@ -203,7 +203,7 @@ func calculateIDCAffinityScore(dst, src string) float64 {
return minScore
}

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

Expand All @@ -212,7 +212,7 @@ func calculateIDCAffinityScore(dst, src string) float64 {
// it gets the max score of idc.
srcElements := strings.Split(src, "|")
for _, srcElement := range srcElements {
if dst == srcElement {
if strings.EqualFold(dst, srcElement) {
return maxScore
}
}
Expand All @@ -226,7 +226,7 @@ func calculateMultiElementAffinityScore(dst, src string) float64 {
return minScore
}

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

Expand All @@ -242,7 +242,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
}
score++
Expand Down
109 changes: 109 additions & 0 deletions manager/searcher/searcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,115 @@ func TestSchedulerCluster(t *testing.T) {
assert.Equal(len(data), 4)
},
},
{
name: "match according to all conditions with the case insensitive",
schedulerClusters: []model.SchedulerCluster{
{
Name: "foo",
Scopes: map[string]interface{}{
"idc": "IDC-1",
"location": "LOCATION-2",
},
SecurityGroup: model.SecurityGroup{
SecurityRules: []model.SecurityRule{
{
Domain: "DOMAIN-1",
},
},
},
Schedulers: []model.Scheduler{
{
HostName: "foo",
State: "active",
},
},
},
{
Name: "bar",
Scopes: map[string]interface{}{
"idc": "IDC-1",
"location": "LOCATION-1",
},
SecurityGroup: model.SecurityGroup{
SecurityRules: []model.SecurityRule{
{
Domain: "DOMAIN-1",
},
},
},
Schedulers: []model.Scheduler{
{
HostName: "bar",
State: "active",
},
},
},
{
Name: "baz",
Scopes: map[string]interface{}{
"idc": "IDC-1",
"location": "LOCATION-1|LOCATION-2",
"net_topology": "NET_TOPOLOGY-1",
},
Schedulers: []model.Scheduler{
{
HostName: "baz",
State: "active",
},
},
},
{
Name: "bax",
Scopes: map[string]interface{}{
"idc": "IDC-1",
"location": "LOCATION-2",
"net_topology": "NET_TOPOLOGY-1|NET_TOPOLOGY-2",
},
Schedulers: []model.Scheduler{
{
HostName: "bax",
State: "active",
},
},
IsDefault: true,
},
{
Name: "bac",
Scopes: map[string]interface{}{
"idc": "IDC-1",
"location": "LOCATION-2",
"net_topology": "NET_TOPOLOGY-1|NET_TOPOLOGY-2",
},
SecurityGroup: model.SecurityGroup{
SecurityRules: []model.SecurityRule{
{
Domain: "DOMAIN-2",
},
},
},
Schedulers: []model.Scheduler{
{
HostName: "bac",
State: "active",
},
},
},
},
conditions: map[string]string{
"security_domain": "domain-1",
"idc": "idc-1|idc-2",
"location": "location-1|location-2",
"net_topology": "net_topology-1|net_topology-1",
},
expect: func(t *testing.T, data []model.SchedulerCluster, err error) {
assert := assert.New(t)
assert.Equal(data[0].Name, "bar")
assert.Equal(data[1].Name, "foo")
assert.Equal(data[2].Name, "baz")
assert.Equal(data[3].Name, "bax")
assert.Equal(len(data), 4)
},
},
}

for _, tc := range tests {
Expand Down

0 comments on commit ce85054

Please sign in to comment.