From 953d77cc8ee95bfeb44cd4ffc53bbd7136ecad09 Mon Sep 17 00:00:00 2001 From: Zexi Li Date: Tue, 7 Aug 2018 12:09:20 +0800 Subject: [PATCH] scheduler: allow run container in kubelet host --- .../predicates/guest/hypervisor_predicate.go | 16 ++++++++++++++-- pkg/scheduler/api/types.go | 1 + 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/pkg/scheduler/algorithm/predicates/guest/hypervisor_predicate.go b/pkg/scheduler/algorithm/predicates/guest/hypervisor_predicate.go index 1b56b68fc2..db9c62f898 100644 --- a/pkg/scheduler/algorithm/predicates/guest/hypervisor_predicate.go +++ b/pkg/scheduler/algorithm/predicates/guest/hypervisor_predicate.go @@ -2,6 +2,7 @@ package guest import ( "github.com/yunionio/log" + "github.com/yunionio/onecloud/pkg/scheduler/algorithm/predicates" "github.com/yunionio/onecloud/pkg/scheduler/api" "github.com/yunionio/onecloud/pkg/scheduler/core" @@ -35,6 +36,18 @@ func hostHasContainerTag(c core.Candidater) bool { return false } +func hostAllowRunContainer(c core.Candidater) bool { + hostType := c.Get("HostType") + if hostType == api.HostTypeKubelet { + return true + } + if hostHasContainerTag(c) { + log.Debugf("Host %q has %q tag, allow it run container", c.IndexKey(), CONTAINER_ALLOWED_TAG) + return true + } + return false +} + func (f *HypervisorPredicate) Execute(u *core.Unit, c core.Candidater) (bool, []core.PredicateFailureReason, error) { h := predicates.NewPredicateHelper(f, u, c) @@ -42,8 +55,7 @@ func (f *HypervisorPredicate) Execute(u *core.Unit, c core.Candidater) (bool, [] guestNeedType := u.SchedData().Hypervisor if guestNeedType != hostType { - if guestNeedType == api.SchedTypeContainer && hostHasContainerTag(c) { - log.Debugf("Host %q has %q tag, allow it run container", c.IndexKey(), CONTAINER_ALLOWED_TAG) + if guestNeedType == api.SchedTypeContainer && hostAllowRunContainer(c) { return h.GetResult() } h.Exclude2(f.Name(), hostType, guestNeedType) diff --git a/pkg/scheduler/api/types.go b/pkg/scheduler/api/types.go index cc7780981d..3cc71798db 100644 --- a/pkg/scheduler/api/types.go +++ b/pkg/scheduler/api/types.go @@ -17,6 +17,7 @@ const ( SchedTypeKvm = "kvm" HostHypervisorForKvm = "hypervisor" HostTypeAliyun = "aliyun" + HostTypeKubelet = "kubelet" AggregateStrategyRequire = "require" AggregateStrategyExclude = "exclude"