From d5ef3c130787485fc143c8c5c7b7da2feacc6a79 Mon Sep 17 00:00:00 2001 From: Zexi Li Date: Wed, 15 Sep 2021 14:47:24 +0800 Subject: [PATCH] fix(scheduler): cpu arch match --- .../predicates/guest/cpu_predicate.go | 20 +++++++++++++++---- pkg/scheduler/cache/candidate/base.go | 8 ++++++++ pkg/scheduler/core/types.go | 2 ++ pkg/scheduler/test/mock/core.go | 8 ++++++++ 4 files changed, 34 insertions(+), 4 deletions(-) diff --git a/pkg/scheduler/algorithm/predicates/guest/cpu_predicate.go b/pkg/scheduler/algorithm/predicates/guest/cpu_predicate.go index ef7b7ab075..2b45c473af 100644 --- a/pkg/scheduler/algorithm/predicates/guest/cpu_predicate.go +++ b/pkg/scheduler/algorithm/predicates/guest/cpu_predicate.go @@ -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 { diff --git a/pkg/scheduler/cache/candidate/base.go b/pkg/scheduler/cache/candidate/base.go index b9ee27d483..77585dda7c 100644 --- a/pkg/scheduler/cache/candidate/base.go +++ b/pkg/scheduler/cache/candidate/base.go @@ -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 } diff --git a/pkg/scheduler/core/types.go b/pkg/scheduler/core/types.go index 905671eab4..56adfc6683 100644 --- a/pkg/scheduler/core/types.go +++ b/pkg/scheduler/core/types.go @@ -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 diff --git a/pkg/scheduler/test/mock/core.go b/pkg/scheduler/test/mock/core.go index 7f3c418232..7330e93a87 100644 --- a/pkg/scheduler/test/mock/core.go +++ b/pkg/scheduler/test/mock/core.go @@ -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()