Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scheduler: permit other plugin to set numaAffinity #2182

Merged
merged 1 commit into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions pkg/scheduler/frameworkext/topologymanager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,16 @@ func (m *topologyManager) Admit(ctx context.Context, cycleState *framework.Cycle
store := s.(*Store)

policy := createNUMATopologyPolicy(policyType, numaNodes)

bestHint, admit := m.calculateAffinity(ctx, cycleState, policy, pod, nodeName, exclusivePolicy, allNUMANodeStatus)
klog.V(5).Infof("Best TopologyHint for (pod: %v): %v on node: %v", klog.KObj(pod), bestHint, nodeName)
if !admit {
return framework.NewStatus(framework.Unschedulable, "node(s) NUMA Topology affinity error")
bestHint, ok := store.GetAffinity(nodeName)
if !ok {
var admit bool
bestHint, admit = m.calculateAffinity(ctx, cycleState, policy, pod, nodeName, exclusivePolicy, allNUMANodeStatus)
klog.V(5).Infof("Best TopologyHint for (pod: %v): %v on node: %v", klog.KObj(pod), bestHint, nodeName)
if !admit {
return framework.NewStatus(framework.Unschedulable, "node(s) NUMA Topology affinity error")
}
store.SetAffinity(nodeName, bestHint)
}

store.SetAffinity(nodeName, bestHint)

status := m.allocateResources(ctx, cycleState, bestHint, pod, nodeName)
if !status.IsSuccess() {
return status
Expand Down
6 changes: 3 additions & 3 deletions pkg/scheduler/frameworkext/topologymanager/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ func (s *Store) SetAffinity(nodeName string, affinity NUMATopologyHint) {
s.affinityMap.Store(nodeName, &affinity)
}

func (s *Store) GetAffinity(nodeName string) NUMATopologyHint {
func (s *Store) GetAffinity(nodeName string) (NUMATopologyHint, bool) {
val, ok := s.affinityMap.Load(nodeName)
if !ok {
return NUMATopologyHint{}
return NUMATopologyHint{}, false
}
hint := val.(*NUMATopologyHint)
return *hint
return *hint, true
}
6 changes: 3 additions & 3 deletions pkg/scheduler/plugins/deviceshare/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ func (p *Plugin) Filter(ctx context.Context, cycleState *framework.CycleState, p
var affinity topologymanager.NUMATopologyHint
if !p.disableDeviceNUMATopologyAlignment {
store := topologymanager.GetStore(cycleState)
affinity = store.GetAffinity(nodeInfo.Node().Name)
affinity, _ = store.GetAffinity(nodeInfo.Node().Name)
}

allocator := &AutopilotAllocator{
Expand Down Expand Up @@ -369,7 +369,7 @@ func (p *Plugin) FilterReservation(ctx context.Context, cycleState *framework.Cy
var affinity topologymanager.NUMATopologyHint
if !p.disableDeviceNUMATopologyAlignment {
store := topologymanager.GetStore(cycleState)
affinity = store.GetAffinity(nodeInfo.Node().Name)
affinity, _ = store.GetAffinity(nodeInfo.Node().Name)
}

allocator := &AutopilotAllocator{
Expand Down Expand Up @@ -417,7 +417,7 @@ func (p *Plugin) Reserve(ctx context.Context, cycleState *framework.CycleState,
var affinity topologymanager.NUMATopologyHint
if !p.disableDeviceNUMATopologyAlignment {
store := topologymanager.GetStore(cycleState)
affinity = store.GetAffinity(nodeInfo.Node().Name)
affinity, _ = store.GetAffinity(nodeInfo.Node().Name)
}

allocator := &AutopilotAllocator{
Expand Down
4 changes: 2 additions & 2 deletions pkg/scheduler/plugins/deviceshare/scoring.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (p *Plugin) Score(ctx context.Context, cycleState *framework.CycleState, po
}

store := topologymanager.GetStore(cycleState)
affinity := store.GetAffinity(nodeName)
affinity, _ := store.GetAffinity(nodeName)

allocator := &AutopilotAllocator{
state: state,
Expand Down Expand Up @@ -130,7 +130,7 @@ func (p *Plugin) ScoreReservation(ctx context.Context, cycleState *framework.Cyc
}

store := topologymanager.GetStore(cycleState)
affinity := store.GetAffinity(nodeInfo.Node().Name)
affinity, _ := store.GetAffinity(nodeInfo.Node().Name)

allocator := &AutopilotAllocator{
state: state,
Expand Down
4 changes: 2 additions & 2 deletions pkg/scheduler/plugins/nodenumaresource/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ func (p *Plugin) FilterReservation(ctx context.Context, cycleState *framework.Cy
restoreState := reservationRestoreState.getNodeState(nodeName)

store := topologymanager.GetStore(cycleState)
affinity := store.GetAffinity(nodeName)
affinity, _ := store.GetAffinity(nodeName)
resourceOptions, err := p.getResourceOptions(state, node, pod, requestCPUBind, affinity, topologyOptions)
if err != nil {
return framework.NewStatus(framework.UnschedulableAndUnresolvable, err.Error())
Expand Down Expand Up @@ -508,7 +508,7 @@ func (p *Plugin) Reserve(ctx context.Context, cycleState *framework.CycleState,
}

store := topologymanager.GetStore(cycleState)
affinity := store.GetAffinity(nodeName)
affinity, _ := store.GetAffinity(nodeName)
resourceOptions, err := p.getResourceOptions(state, node, pod, requestCPUBind, affinity, topologyOptions)
if err != nil {
return framework.AsStatus(err)
Expand Down
2 changes: 1 addition & 1 deletion pkg/scheduler/plugins/nodenumaresource/plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2085,7 +2085,7 @@ func TestFilterWithNUMANodeScoring(t *testing.T) {
assert.NoError(t, err)
status = pl.Filter(context.TODO(), cycleState, tt.requestedPod, nodeInfo)
assert.True(t, status.IsSuccess())
hint := topologymanager.GetStore(cycleState).GetAffinity(tt.node.Name)
hint, _ := topologymanager.GetStore(cycleState).GetAffinity(tt.node.Name)
assert.Equal(t, tt.wantAffinity.GetBits(), hint.NUMANodeAffinity.GetBits())
})
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/scheduler/plugins/nodenumaresource/scoring.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func (p *Plugin) Score(ctx context.Context, cycleState *framework.CycleState, po
}

store := topologymanager.GetStore(cycleState)
affinity := store.GetAffinity(nodeName)
affinity, _ := store.GetAffinity(nodeName)
resourceOptions, err := p.getResourceOptions(state, node, pod, requestCPUBind, affinity, topologyOptions)
if err != nil {
return 0, nil
Expand Down