Skip to content

Commit

Permalink
Merge pull request kubernetes-retired#442 from k82cn/kb_439
Browse files Browse the repository at this point in the history
Checked allowed pod number on node.
  • Loading branch information
k8s-ci-robot authored Oct 16, 2018
2 parents be860e1 + 0a5ba77 commit a394034
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
18 changes: 10 additions & 8 deletions pkg/scheduler/api/resource_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ type Resource struct {
MilliCPU float64
Memory float64
MilliGPU float64
// MaxTaskNum is only used by predicates; it should NOT
// be accounted in other operators, e.g. Add.
MaxTaskNum int
}

const (
Expand All @@ -35,18 +38,15 @@ const (
)

func EmptyResource() *Resource {
return &Resource{
MilliCPU: 0,
Memory: 0,
MilliGPU: 0,
}
return &Resource{}
}

func (r *Resource) Clone() *Resource {
clone := &Resource{
MilliCPU: r.MilliCPU,
Memory: r.Memory,
MilliGPU: r.MilliGPU,
MilliCPU: r.MilliCPU,
Memory: r.Memory,
MilliGPU: r.MilliGPU,
MaxTaskNum: r.MaxTaskNum,
}
return clone
}
Expand All @@ -63,6 +63,8 @@ func NewResource(rl v1.ResourceList) *Resource {
r.MilliCPU += float64(rQuant.MilliValue())
case v1.ResourceMemory:
r.Memory += float64(rQuant.Value())
case v1.ResourcePods:
r.MaxTaskNum += int(rQuant.Value())
case GPUResourceName:
r.MilliGPU += float64(rQuant.MilliValue())
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/scheduler/plugins/predicates/predicates.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ func (pp *nodeAffinityPlugin) OnSessionOpen(ssn *framework.Session) {
nodeInfo := cache.NewNodeInfo(node.Pods()...)
nodeInfo.SetNode(node.Node)

if node.Allocatable.MaxTaskNum <= len(nodeInfo.Pods()) {
return fmt.Errorf("Node <%s> can not allow more task running on it.", node.Name)
}

// NodeSeletor Predicate
fit, _, err := predicates.PodMatchNodeSelector(task.Pod, nil, nodeInfo)
if err != nil {
Expand Down

0 comments on commit a394034

Please sign in to comment.