Skip to content

Commit

Permalink
[YUNIKORN-2780] Remove references to SI ExistingAllocations
Browse files Browse the repository at this point in the history
Now that node registration has been simplified, we no longer need to
send ExistingAllocations via the SI. Remove references so these can
be removed from the interface.
  • Loading branch information
craigcondit committed Jul 31, 2024
1 parent a95c356 commit 169a4f0
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 63 deletions.
1 change: 0 additions & 1 deletion pkg/cache/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -1558,7 +1558,6 @@ func (ctx *Context) registerNodes(nodes []*v1.Node) ([]*v1.Node, error) {
},
SchedulableResource: common.GetNodeResource(&nodeStatus),
OccupiedResource: common.NewResourceBuilder().Build(),
ExistingAllocations: make([]*si.Allocation, 0),
})
pendingNodes[node.Name] = node
}
Expand Down
33 changes: 0 additions & 33 deletions pkg/common/si_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,39 +153,6 @@ func CreateReleaseRequestForTask(appID, taskID, allocationKey, partition, termin
}
}

// CreateUpdateRequestForNewNode builds a NodeRequest for new node addition and restoring existing node
func CreateUpdateRequestForNewNode(nodeID string, nodeLabels map[string]string, capacity *si.Resource, occupied *si.Resource,
existingAllocations []*si.Allocation) *si.NodeRequest {
// Use node's name as the NodeID, this is because when bind pod to node,
// name of node is required but uid is optional.
nodeInfo := &si.NodeInfo{
NodeID: nodeID,
SchedulableResource: capacity,
OccupiedResource: occupied,
Attributes: map[string]string{
constants.DefaultNodeAttributeHostNameKey: nodeID,
constants.DefaultNodeAttributeRackNameKey: constants.DefaultRackName,
},
ExistingAllocations: existingAllocations,
Action: si.NodeInfo_CREATE,
}

// Add nodeLabels key value to Attributes map
for k, v := range nodeLabels {
nodeInfo.Attributes[k] = v
}

// Add instanceType to Attributes map
nodeInfo.Attributes[common.InstanceType] = nodeLabels[conf.GetSchedulerConf().InstanceTypeNodeLabelKey]

nodes := make([]*si.NodeInfo, 1)
nodes[0] = nodeInfo
return &si.NodeRequest{
Nodes: nodes,
RmID: conf.GetSchedulerConf().ClusterID,
}
}

// CreateUpdateRequestForUpdatedNode builds a NodeRequest for capacity and occupied resource updates
func CreateUpdateRequestForUpdatedNode(nodeID string, capacity *si.Resource, occupied *si.Resource) *si.NodeRequest {
nodeInfo := &si.NodeInfo{
Expand Down
28 changes: 0 additions & 28 deletions pkg/common/si_helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
v1 "k8s.io/api/core/v1"
apis "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/apache/yunikorn-k8shim/pkg/common/constants"
"github.com/apache/yunikorn-scheduler-interface/lib/go/common"
"github.com/apache/yunikorn-scheduler-interface/lib/go/si"
)
Expand Down Expand Up @@ -230,33 +229,6 @@ func TestCreateTagsForTask(t *testing.T) {
assert.Equal(t, len(result4), 4)
}

func TestCreateUpdateRequestForNewNode(t *testing.T) {
capacity := NewResourceBuilder().AddResource(common.Memory, 200).AddResource(common.CPU, 2).Build()
occupied := NewResourceBuilder().AddResource(common.Memory, 50).AddResource(common.CPU, 1).Build()
var existingAllocations []*si.Allocation
nodeLabels := map[string]string{
"label1": "key1",
"label2": "key2",
"node.kubernetes.io/instance-type": "HighMem",
}
request := CreateUpdateRequestForNewNode(nodeID, nodeLabels, capacity, occupied, existingAllocations)
assert.Equal(t, len(request.Nodes), 1)
assert.Equal(t, request.Nodes[0].NodeID, nodeID)
assert.Equal(t, request.Nodes[0].SchedulableResource, capacity)
assert.Equal(t, request.Nodes[0].OccupiedResource, occupied)
assert.Equal(t, len(request.Nodes[0].Attributes), 6)
assert.Equal(t, request.Nodes[0].Attributes[constants.DefaultNodeAttributeHostNameKey], nodeID)
assert.Equal(t, request.Nodes[0].Attributes[constants.DefaultNodeAttributeRackNameKey], constants.DefaultRackName)

// Make sure include nodeLabel
assert.Equal(t, request.Nodes[0].Attributes["label1"], "key1")
assert.Equal(t, request.Nodes[0].Attributes["label2"], "key2")
assert.Equal(t, request.Nodes[0].Attributes["node.kubernetes.io/instance-type"], "HighMem")

// Make sure include the instanceType
assert.Equal(t, request.Nodes[0].Attributes[common.InstanceType], "HighMem")
}

func TestCreateUpdateRequestForUpdatedNode(t *testing.T) {
capacity := NewResourceBuilder().AddResource(common.Memory, 200).AddResource(common.CPU, 2).Build()
occupied := NewResourceBuilder().AddResource(common.Memory, 50).AddResource(common.CPU, 1).Build()
Expand Down
32 changes: 31 additions & 1 deletion pkg/shim/scheduler_mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
"github.com/apache/yunikorn-k8shim/pkg/cache"
"github.com/apache/yunikorn-k8shim/pkg/client"
"github.com/apache/yunikorn-k8shim/pkg/common"
"github.com/apache/yunikorn-k8shim/pkg/common/constants"
"github.com/apache/yunikorn-k8shim/pkg/common/events"
"github.com/apache/yunikorn-k8shim/pkg/common/utils"
"github.com/apache/yunikorn-k8shim/pkg/conf"
Expand Down Expand Up @@ -124,7 +125,7 @@ func (fc *MockScheduler) addNode(nodeName string, nodeLabels map[string]string,
AddResource(siCommon.CPU, cpu).
AddResource("pods", pods).
Build()
request := common.CreateUpdateRequestForNewNode(nodeName, nodeLabels, nodeResource, nil, nil)
request := createUpdateRequestForNewNode(nodeName, nodeLabels, nodeResource, nil)
fmt.Printf("report new nodes to scheduler, request: %s", request.String())
return fc.apiProvider.GetAPIs().SchedulerAPI.UpdateNode(request)
}
Expand Down Expand Up @@ -335,3 +336,32 @@ func (fc *MockScheduler) ensureStarted() {
panic("mock scheduler is not started - call start() first")
}
}
func createUpdateRequestForNewNode(nodeID string, nodeLabels map[string]string, capacity *si.Resource, occupied *si.Resource) *si.NodeRequest {
// Use node's name as the NodeID, this is because when bind pod to node,
// name of node is required but uid is optional.
nodeInfo := &si.NodeInfo{
NodeID: nodeID,
SchedulableResource: capacity,
OccupiedResource: occupied,
Attributes: map[string]string{
constants.DefaultNodeAttributeHostNameKey: nodeID,
constants.DefaultNodeAttributeRackNameKey: constants.DefaultRackName,
},
Action: si.NodeInfo_CREATE,
}

// Add nodeLabels key value to Attributes map
for k, v := range nodeLabels {
nodeInfo.Attributes[k] = v
}

// Add instanceType to Attributes map
nodeInfo.Attributes[siCommon.InstanceType] = nodeLabels[conf.GetSchedulerConf().InstanceTypeNodeLabelKey]

nodes := make([]*si.NodeInfo, 1)
nodes[0] = nodeInfo
return &si.NodeRequest{
Nodes: nodes,
RmID: conf.GetSchedulerConf().ClusterID,
}
}

0 comments on commit 169a4f0

Please sign in to comment.