Skip to content
This repository was archived by the owner on May 25, 2023. It is now read-only.

Commit d7de2ff

Browse files
authored
Merge pull request #442 from k82cn/kb_439
Checked allowed pod number on node.
2 parents a26c70e + 05b8462 commit d7de2ff

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

pkg/scheduler/api/resource_info.go

+10-8
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ type Resource struct {
2727
MilliCPU float64
2828
Memory float64
2929
MilliGPU float64
30+
// MaxTaskNum is only used by predicates; it should NOT
31+
// be accounted in other operators, e.g. Add.
32+
MaxTaskNum int
3033
}
3134

3235
const (
@@ -35,18 +38,15 @@ const (
3538
)
3639

3740
func EmptyResource() *Resource {
38-
return &Resource{
39-
MilliCPU: 0,
40-
Memory: 0,
41-
MilliGPU: 0,
42-
}
41+
return &Resource{}
4342
}
4443

4544
func (r *Resource) Clone() *Resource {
4645
clone := &Resource{
47-
MilliCPU: r.MilliCPU,
48-
Memory: r.Memory,
49-
MilliGPU: r.MilliGPU,
46+
MilliCPU: r.MilliCPU,
47+
Memory: r.Memory,
48+
MilliGPU: r.MilliGPU,
49+
MaxTaskNum: r.MaxTaskNum,
5050
}
5151
return clone
5252
}
@@ -63,6 +63,8 @@ func NewResource(rl v1.ResourceList) *Resource {
6363
r.MilliCPU += float64(rQuant.MilliValue())
6464
case v1.ResourceMemory:
6565
r.Memory += float64(rQuant.Value())
66+
case v1.ResourcePods:
67+
r.MaxTaskNum += int(rQuant.Value())
6668
case GPUResourceName:
6769
r.MilliGPU += float64(rQuant.MilliValue())
6870
}

pkg/scheduler/plugins/predicates/predicates.go

+4
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ func (pp *nodeAffinityPlugin) OnSessionOpen(ssn *framework.Session) {
112112
nodeInfo := cache.NewNodeInfo(node.Pods()...)
113113
nodeInfo.SetNode(node.Node)
114114

115+
if node.Allocatable.MaxTaskNum <= len(nodeInfo.Pods()) {
116+
return fmt.Errorf("Node <%s> can not allow more task running on it.", node.Name)
117+
}
118+
115119
// NodeSeletor Predicate
116120
fit, _, err := predicates.PodMatchNodeSelector(task.Pod, nil, nodeInfo)
117121
if err != nil {

0 commit comments

Comments
 (0)