fix(scheduler): cpu arch match

This commit is contained in:
Zexi Li
2021-09-15 14:47:24 +08:00
parent 9f4fc77bd2
commit 22e2896afc
4 changed files with 34 additions and 4 deletions
@@ -54,13 +54,25 @@ func (f *CPUPredicate) Execute(u *core.Unit, c core.Candidater) (bool, []core.Pr
useRsvd := h.UseReserved()
getter := c.Getter()
archMatch := true
isArmHost := getter.IsArmHost()
if apis.IsARM(d.OsArch) {
host := getter.Host()
if !host.IsArmHost() {
h.Exclude(predicates.ErrHostCpuArchitectureNotMatch)
return h.GetResult()
// process arm64 host
if !isArmHost {
archMatch = false
}
} else {
// process x86_64 host
if isArmHost {
archMatch = false
}
}
if !archMatch {
h.Exclude2(predicates.ErrHostCpuArchitectureNotMatch, getter.CPUArch(), d.OsArch)
return h.GetResult()
}
freeCPUCount := getter.FreeCPUCount(useRsvd)
reqCPUCount := int64(d.Ncpu)
if freeCPUCount < reqCPUCount {
+8
View File
@@ -82,6 +82,14 @@ func (b baseHostGetter) Host() *computemodels.SHost {
return b.h.SHost
}
func (b baseHostGetter) IsArmHost() bool {
return b.h.IsArmHost()
}
func (b baseHostGetter) CPUArch() string {
return b.h.CpuArchitecture
}
func (b baseHostGetter) Cloudprovider() *computemodels.SCloudprovider {
return b.h.Cloudprovider
}
+2
View File
@@ -88,6 +88,8 @@ type CandidatePropertyGetter interface {
ProjectGuests() map[string]int64
CreatingGuestCount() int
CPUArch() string
IsArmHost() bool
RunningCPUCount() int64
TotalCPUCount(useRsvd bool) int64
FreeCPUCount(useRsvd bool) int64
+8
View File
@@ -285,6 +285,14 @@ func (m *MockCandidatePropertyGetter) Host() *models.SHost {
return ret0
}
func (m *MockCandidatePropertyGetter) IsArmHost() bool {
return false
}
func (m *MockCandidatePropertyGetter) CPUArch() string {
return ""
}
// Host indicates an expected call of Host
func (mr *MockCandidatePropertyGetterMockRecorder) Host() *gomock.Call {
mr.mock.ctrl.T.Helper()