fix(scheduler): sku filter check zone if only prefer region specified

This commit is contained in:
Zexi Li
2020-12-14 16:40:09 +08:00
parent 976539f253
commit c87c2b384b
2 changed files with 23 additions and 9 deletions
@@ -55,9 +55,21 @@ func (p *InstanceTypePredicate) Execute(u *core.Unit, c core.Candidater) (bool,
reqZone := d.PreferZone
if reqRegion != "" && reqZone == "" {
sku := skuman.GetByRegion(instanceType, regionId)
if sku == nil {
skus := skuman.GetByRegion(instanceType, regionId)
if len(skus) == 0 {
h.Exclude(fmt.Sprintf("Not found server sku %s at region %s", instanceType, regionName))
} else {
zoneMatch := false
for idx := range skus {
sku := skus[idx]
if sku.ZoneId == zoneId {
zoneMatch = true
break
}
}
if !zoneMatch {
h.Exclude(fmt.Sprintf("Not found server sku %s at zone %s", instanceType, zoneName))
}
}
} else {
sku := skuman.GetByZone(instanceType, zoneId)
+9 -7
View File
@@ -56,7 +56,7 @@ func GetByZone(instanceType, zoneId string) *ServerSku {
return skuManager.GetByZone(instanceType, zoneId)
}
func GetByRegion(instanceType, regionId string) *ServerSku {
func GetByRegion(instanceType, regionId string) []*ServerSku {
return skuManager.GetByRegion(instanceType, regionId)
}
@@ -86,13 +86,15 @@ func (l skuList) DebugString() string {
return fmt.Sprintf("%s", jsonutils.Marshal(l).String())
}
func (l skuList) GetByRegion(regionId string) *ServerSku {
for _, s := range l {
if s.RegionId == regionId {
return s
func (l skuList) GetByRegion(regionId string) []*ServerSku {
ret := make([]*ServerSku, 0)
for idx := range l {
sku := l[idx]
if sku.RegionId == regionId {
ret = append(ret, sku)
}
}
return nil
return ret
}
func (l skuList) GetByZone(zoneId string) *ServerSku {
@@ -167,7 +169,7 @@ func (m *SSkuManager) GetByZone(instanceType, zoneId string) *ServerSku {
return l.GetByZone(zoneId)
}
func (m *SSkuManager) GetByRegion(instanceType, regionId string) *ServerSku {
func (m *SSkuManager) GetByRegion(instanceType, regionId string) []*ServerSku {
l := m.skuMap.Get(instanceType)
if l == nil {
return nil