This is an automated email from the ASF dual-hosted git repository.
wilfreds pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/yunikorn-core.git
The following commit(s) were added to refs/heads/master by this push:
new 3d240e1d [YUNIKORN-2826] Prune zero-values from node capacity
3d240e1d is described below
commit 3d240e1d172157eabc48708710257f1537bf60a1
Author: hhcs9527 <[email protected]>
AuthorDate: Tue Mar 24 15:02:24 2026 +1100
[YUNIKORN-2826] Prune zero-values from node capacity
Prune the zero-values in node capacity (total resource)
Signed-off-by: pohanhuang <[email protected]>
Closes: #1062
Signed-off-by: Wilfred Spiegelenburg <[email protected]>
---
pkg/scheduler/objects/node.go | 2 ++
pkg/scheduler/objects/node_test.go | 37 ++++++++++++++++++++++++++++++++++++-
2 files changed, 38 insertions(+), 1 deletion(-)
diff --git a/pkg/scheduler/objects/node.go b/pkg/scheduler/objects/node.go
index 2047ff44..abb5d4c4 100644
--- a/pkg/scheduler/objects/node.go
+++ b/pkg/scheduler/objects/node.go
@@ -81,6 +81,7 @@ func NewNode(proto *si.NodeInfo) *Node {
sn.nodeEvents = schedEvt.NewNodeEvents(events.GetEventSystem())
// initialise available resources
var err error
+ sn.totalResource.Prune()
sn.availableResource, err =
resources.SubErrorNegative(sn.totalResource, sn.occupiedResource)
if err != nil {
log.Log(log.SchedNode).Error("New node created with no
available resources",
@@ -172,6 +173,7 @@ func (sn *Node) SetCapacity(newCapacity
*resources.Resource) *resources.Resource
}
delta = resources.Sub(newCapacity, sn.totalResource)
sn.totalResource = newCapacity
+ sn.totalResource.Prune()
sn.refreshAvailableResource()
sn.nodeEvents.SendNodeCapacityChangedEvent(sn.NodeID,
sn.totalResource.Clone())
return delta
diff --git a/pkg/scheduler/objects/node_test.go
b/pkg/scheduler/objects/node_test.go
index 6a725ac8..93fb6147 100644
--- a/pkg/scheduler/objects/node_test.go
+++ b/pkg/scheduler/objects/node_test.go
@@ -757,7 +757,8 @@ func TestUpdateResources(t *testing.T) {
}
// reset and check with allocated
- total =
resources.NewResourceFromMap(map[string]resources.Quantity{"first": 10,
"second": 10})
+ total =
resources.NewResourceFromMap(map[string]resources.Quantity{"first": 10,
"second": 10, "unknown": 0})
+ prunedTotal :=
resources.NewResourceFromMap(map[string]resources.Quantity{"first": 10,
"second": 10})
node = newNodeRes("node-123", total)
if !resources.IsZero(node.occupiedResource) ||
!resources.IsZero(node.allocatedResource) || !resources.Equals(total,
node.GetCapacity()) {
t.Fatalf("node not initialised correctly")
@@ -767,6 +768,9 @@ func TestUpdateResources(t *testing.T) {
available = resources.Sub(total, alloc)
// fake the update to recalculate available
node.refreshAvailableResource()
+ assert.Assert(t, resources.Equals(node.GetCapacity(), prunedTotal),
"total resource should be equal to the pruned total")
+ assert.Assert(t, resources.Equals(available,
node.GetAvailableResource()), "available resources should have been updated to:
%s, got %s", available, node.GetAvailableResource())
+
if !resources.Equals(available, node.GetAvailableResource()) {
t.Errorf("available resources should have been updated to: %s,
got %s", available, node.GetAvailableResource())
}
@@ -1001,3 +1005,34 @@ func TestUpdateForeignAllocation(t *testing.T) {
assert.Assert(t, prev == nil, "unexpected previous allocation returned")
assert.Assert(t, node.GetAllocation(foreignAlloc2) == alloc2, "foreign
allocation not found")
}
+
+func TestTotalResourcePrune(t *testing.T) {
+ total :=
resources.NewResourceFromMap(map[string]resources.Quantity{"cpu": 10, "memory":
10, "gpu": 0})
+ prunedTotal :=
resources.NewResourceFromMap(map[string]resources.Quantity{"cpu": 10, "memory":
10})
+ t.Run("NewNode prunes during initialization", func(t *testing.T) {
+ proto := newProto("node-with-zero-gpu", total,
map[string]string{
+ "ready": "true",
+ })
+ node := NewNode(proto)
+ assert.Assert(t, !resources.DeepEquals(node.totalResource,
total), "total resource should not be equal to the input")
+ assert.Assert(t, resources.DeepEquals(node.totalResource,
prunedTotal), "total resource should be equal to the input")
+ })
+
+ t.Run("NewNode will not prune if no zero values", func(t *testing.T) {
+ proto := newProto("node-with-zero-gpu", prunedTotal,
map[string]string{
+ "ready": "true",
+ })
+ node := NewNode(proto)
+ assert.Assert(t, resources.DeepEquals(node.totalResource,
prunedTotal), "total resource should be equal to the input")
+ })
+ t.Run("SetCapacity prunes zero values", func(t *testing.T) {
+ setTotal :=
resources.NewResourceFromMap(map[string]resources.Quantity{"cpu": 1, "memory":
10, "gpu": 0})
+ setPrunedTotal :=
resources.NewResourceFromMap(map[string]resources.Quantity{"cpu": 1, "memory":
10})
+ proto := newProto("node-with-zero-gpu", total,
map[string]string{
+ "ready": "true",
+ })
+ node := NewNode(proto)
+ node.SetCapacity(setTotal)
+ assert.Assert(t, resources.DeepEquals(node.GetCapacity(),
setPrunedTotal), "total resource should be equal to the input")
+ })
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]