Skip to content

Commit

Permalink
scheduler: skip uncessary Filter&Score plugin (#2138)
Browse files Browse the repository at this point in the history
Signed-off-by: wangjianyu.wjy <[email protected]>
Co-authored-by: wangjianyu.wjy <[email protected]>
  • Loading branch information
ZiMengSheng and wangjianyu.wjy authored Jul 26, 2024
1 parent 08f63a4 commit 70e4bac
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 2 deletions.
4 changes: 4 additions & 0 deletions pkg/scheduler/plugins/deviceshare/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ var (

_ framework.PreFilterPlugin = &Plugin{}
_ framework.FilterPlugin = &Plugin{}
_ framework.PreScorePlugin = &Plugin{}
_ framework.ScorePlugin = &Plugin{}
_ framework.ScoreExtensions = &Plugin{}
_ framework.ReservePlugin = &Plugin{}
Expand Down Expand Up @@ -154,6 +155,9 @@ func (p *Plugin) PreFilter(ctx context.Context, cycleState *framework.CycleState
return nil, status
}
cycleState.Write(stateKey, state)
if state.skip {
return nil, framework.NewStatus(framework.Skip)
}
return nil, nil
}

Expand Down
2 changes: 2 additions & 0 deletions pkg/scheduler/plugins/deviceshare/plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,7 @@ func Test_Plugin_PreFilter(t *testing.T) {
preemptibleDevices: map[string]map[schedulingv1alpha1.DeviceType]deviceResources{},
preemptibleInRRs: map[string]map[types.UID]map[schedulingv1alpha1.DeviceType]deviceResources{},
},
wantStatus: framework.NewStatus(framework.Skip),
},
{
name: "pod has invalid fpga request",
Expand Down Expand Up @@ -867,6 +868,7 @@ func Test_Plugin_PreFilter(t *testing.T) {
preemptibleDevices: map[string]map[schedulingv1alpha1.DeviceType]deviceResources{},
preemptibleInRRs: map[string]map[types.UID]map[schedulingv1alpha1.DeviceType]deviceResources{},
},
wantStatus: framework.NewStatus(framework.Skip),
},
}
for _, tt := range tests {
Expand Down
11 changes: 11 additions & 0 deletions pkg/scheduler/plugins/deviceshare/scoring.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,17 @@ import (
"github.com/koordinator-sh/koordinator/pkg/scheduler/frameworkext/topologymanager"
)

func (p *Plugin) PreScore(ctx context.Context, cycleState *framework.CycleState, pod *corev1.Pod, nodes []*corev1.Node) *framework.Status {
state, status := getPreFilterState(cycleState)
if !status.IsSuccess() {
return status
}
if state.skip {
return framework.NewStatus(framework.Skip)
}
return nil
}

func (p *Plugin) Score(ctx context.Context, cycleState *framework.CycleState, pod *corev1.Pod, nodeName string) (int64, *framework.Status) {
state, status := getPreFilterState(cycleState)
if !status.IsSuccess() {
Expand Down
3 changes: 2 additions & 1 deletion pkg/scheduler/plugins/nodenumaresource/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ var (

_ framework.PreFilterPlugin = &Plugin{}
_ framework.FilterPlugin = &Plugin{}
_ framework.PreScorePlugin = &Plugin{}
_ framework.ScorePlugin = &Plugin{}
_ framework.ReservePlugin = &Plugin{}
_ framework.PreBindPlugin = &Plugin{}
Expand Down Expand Up @@ -239,7 +240,7 @@ func (p *Plugin) PreFilter(ctx context.Context, cycleState *framework.CycleState
cycleState.Write(stateKey, &preFilterState{
skip: true,
})
return nil, nil
return nil, framework.NewStatus(framework.Skip)
}
reservationAffinity, err := reservationutil.GetRequiredReservationAffinity(pod)
if err != nil {
Expand Down
4 changes: 3 additions & 1 deletion pkg/scheduler/plugins/nodenumaresource/plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,7 @@ func TestPlugin_PreFilter(t *testing.T) {
wantState: &preFilterState{
skip: true,
},
want: framework.NewStatus(framework.Skip),
},
{
name: "skip BE Pod",
Expand Down Expand Up @@ -472,6 +473,7 @@ func TestPlugin_PreFilter(t *testing.T) {
wantState: &preFilterState{
skip: true,
},
want: framework.NewStatus(framework.Skip),
},
{
name: "error with non-integer pod",
Expand Down Expand Up @@ -1012,7 +1014,7 @@ func TestFilterWithAmplifiedCPUs(t *testing.T) {

cycleState := framework.NewCycleState()
_, preFilterStatus := pl.PreFilter(context.TODO(), cycleState, tt.pod)
assert.True(t, preFilterStatus.IsSuccess())
assert.True(t, preFilterStatus.IsSuccess() || preFilterStatus.IsSkip())

nodeInfo, err := suit.Handle.SnapshotSharedLister().NodeInfos().Get("node-1")
assert.NoError(t, err)
Expand Down
11 changes: 11 additions & 0 deletions pkg/scheduler/plugins/nodenumaresource/scoring.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,17 @@ var resourceStrategyTypeMap = map[schedulingconfig.ScoringStrategyType]scorer{
},
}

func (p *Plugin) PreScore(ctx context.Context, cycleState *framework.CycleState, pod *corev1.Pod, nodes []*corev1.Node) *framework.Status {
state, status := getPreFilterState(cycleState)
if !status.IsSuccess() {
return status
}
if state.skip {
return framework.NewStatus(framework.Skip)
}
return nil
}

func (p *Plugin) Score(ctx context.Context, cycleState *framework.CycleState, pod *corev1.Pod, nodeName string) (int64, *framework.Status) {
state, status := getPreFilterState(cycleState)
if !status.IsSuccess() {
Expand Down

0 comments on commit 70e4bac

Please sign in to comment.