Skip to content

Commit

Permalink
should filter nodes that do not have enough cpu when cross numa nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
ruimingxie committed Dec 19, 2023
1 parent f8be475 commit 8814d07
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
5 changes: 4 additions & 1 deletion pkg/plugins/noderesourcetopology/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ func (tm *TopologyMatch) Filter(
return status
}
}
assignTopologyResult(nw, s.targetContainerResource.Clone())

if status := assignTopologyResult(nw, s.targetContainerResource.Clone()); status != nil {
return status
}

s.Lock()
defer s.Unlock()
Expand Down
21 changes: 19 additions & 2 deletions pkg/plugins/noderesourcetopology/filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ func TestTopologyMatch_Filter(t *testing.T) {
want: framework.NewStatus(framework.Unschedulable, ErrReasonNUMAResourceNotEnough),
},
{
name: "enough cpu resource in node with default none topology manager policy",
name: "not enough cpu resource in node with default none topology manager policy",
args: args{
pod: newResourcePod(false, nil, framework.Resource{MilliCPU: 2 * CPUTestUnit, Memory: MemTestUnit}),
nodeInfo: framework.NewNodeInfo(
Expand All @@ -310,7 +310,7 @@ func TestTopologyMatch_Filter(t *testing.T) {
}(),
topologyAwareResources: sets.NewString(string(corev1.ResourceCPU)),
},
want: nil,
want: framework.NewStatus(framework.Unschedulable, ErrReasonNUMAResourceNotEnough),
},
{
name: "no enough cpu resource in one NUMA node with default single numa topology manager policy",
Expand Down Expand Up @@ -357,6 +357,23 @@ func TestTopologyMatch_Filter(t *testing.T) {
},
want: framework.NewStatus(framework.Unschedulable, ErrReasonNUMAResourceNotEnough),
},
{
name: "no enough cpu resource in one NUMA node, but enough with cross numa pods",
args: args{
pod: newResourcePod(false, nil, framework.Resource{MilliCPU: 4 * CPUTestUnit}),
nodeInfo: framework.NewNodeInfo(
newResourcePod(true, newZoneList([]zone{{name: "node1", cpu: 1 * CPUTestUnit}}),
framework.Resource{MilliCPU: 1 * CPUTestUnit, Memory: 2 * MemTestUnit}),
),
nrt: func() *topologyv1alpha1.NodeResourceTopology {
nrtCopy := nrt.DeepCopy()
nrtCopy.CraneManagerPolicy.TopologyManagerPolicy = topologyv1alpha1.TopologyManagerPolicyNone
return nrtCopy
}(),
topologyAwareResources: sets.NewString(string(corev1.ResourceCPU)),
},
want: nil,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
12 changes: 9 additions & 3 deletions pkg/plugins/noderesourcetopology/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func (nw *nodeWrapper) addNUMAResources(numaNodeResult topologyv1alpha1.ZoneList
}
}

func assignTopologyResult(nw *nodeWrapper, request *framework.Resource) {
func assignTopologyResult(nw *nodeWrapper, request *framework.Resource) *framework.Status {
// sort by free CPU resource
sort.Slice(nw.numaNodes, func(i, j int) bool {
nodeI, nodeJ := nw.numaNodes[i], nw.numaNodes[j]
Expand All @@ -187,10 +187,10 @@ func assignTopologyResult(nw *nodeWrapper, request *framework.Resource) {
},
},
}
return
return nil
}

for _, node := range nw.numaNodes {
for i, node := range nw.numaNodes {
node.allocatable.MilliCPU = node.allocatable.MilliCPU / 1000 * 1000
res, finished := assignRequestForNUMANode(request, node)
if capacity := ResourceListIgnoreZeroResources(res); len(capacity) != 0 {
Expand All @@ -205,10 +205,16 @@ func assignTopologyResult(nw *nodeWrapper, request *framework.Resource) {
if finished {
break
}
// if we reach the last numa node and still not finished,
// then we are done for this node.
if i == len(nw.numaNodes)-1 {
return framework.NewStatus(framework.Unschedulable, ErrReasonNUMAResourceNotEnough)
}
}
sort.Slice(nw.result, func(i, j int) bool {
return nw.result[i].Name < nw.result[j].Name
})
return nil
}

func computeContainerSpecifiedResourceRequest(pod *corev1.Pod, indices []int, names sets.String) *framework.Resource {
Expand Down

0 comments on commit 8814d07

Please sign in to comment.