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: expose Run[Pre]ScorePlugins functions to PreemptionHandle(through PluginRunner) #93534
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -407,10 +407,17 @@ func (pp *PostFilterPlugin) PostFilter(ctx context.Context, state *framework.Cyc | |
if err != nil { | ||
return nil, framework.NewStatus(framework.Error, err.Error()) | ||
} | ||
|
||
ph := pp.fh.PreemptHandle() | ||
for _, nodeInfo := range nodeInfos { | ||
ph.RunFilterPlugins(ctx, state, pod, nodeInfo) | ||
} | ||
var nodes []*v1.Node | ||
for _, nodeInfo := range nodeInfos { | ||
nodes = append(nodes, nodeInfo.Node()) | ||
} | ||
ph.RunScorePlugins(ctx, state, pod, nodes) | ||
|
||
if pp.failPostFilter { | ||
return nil, framework.NewStatus(framework.Error, fmt.Sprintf("injecting failure for pod %v", pod.Name)) | ||
} | ||
|
@@ -578,30 +585,52 @@ func TestPostFilterPlugin(t *testing.T) { | |
numNodes := 1 | ||
tests := []struct { | ||
name string | ||
numNodes int | ||
rejectFilter bool | ||
failScore bool | ||
rejectPostFilter bool | ||
expectFilterNumCalled int | ||
expectScoreNumCalled int32 | ||
expectPostFilterNumCalled int | ||
}{ | ||
{ | ||
name: "Filter passed", | ||
name: "Filter passed and Score success", | ||
numNodes: 3, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ref: #93534 (comment) |
||
rejectFilter: false, | ||
failScore: false, | ||
rejectPostFilter: false, | ||
expectFilterNumCalled: numNodes, | ||
expectFilterNumCalled: 3, | ||
expectScoreNumCalled: 3, | ||
expectPostFilterNumCalled: 0, | ||
}, | ||
{ | ||
name: "Filter failed and PostFilter passed", | ||
numNodes: numNodes, | ||
rejectFilter: true, | ||
failScore: false, | ||
rejectPostFilter: false, | ||
expectFilterNumCalled: numNodes * 2, | ||
expectScoreNumCalled: 1, | ||
expectPostFilterNumCalled: 1, | ||
}, | ||
{ | ||
name: "Filter failed and PostFilter failed", | ||
numNodes: numNodes, | ||
rejectFilter: true, | ||
failScore: false, | ||
rejectPostFilter: true, | ||
expectFilterNumCalled: numNodes * 2, | ||
expectScoreNumCalled: 1, | ||
expectPostFilterNumCalled: 1, | ||
}, | ||
{ | ||
name: "Score failed and PostFilter failed", | ||
numNodes: numNodes, | ||
rejectFilter: true, | ||
failScore: true, | ||
rejectPostFilter: true, | ||
expectFilterNumCalled: numNodes * 2, | ||
expectScoreNumCalled: 1, | ||
expectPostFilterNumCalled: 1, | ||
}, | ||
} | ||
|
@@ -611,12 +640,15 @@ func TestPostFilterPlugin(t *testing.T) { | |
// Create a plugin registry for testing. Register a combination of filter and postFilter plugin. | ||
var ( | ||
filterPlugin = &FilterPlugin{} | ||
scorePlugin = &ScorePlugin{} | ||
postFilterPlugin = &PostFilterPlugin{} | ||
) | ||
filterPlugin.rejectFilter = tt.rejectFilter | ||
scorePlugin.failScore = tt.failScore | ||
postFilterPlugin.rejectPostFilter = tt.rejectPostFilter | ||
registry := frameworkruntime.Registry{ | ||
filterPluginName: newPlugin(filterPlugin), | ||
scorePluginName: newPlugin(scorePlugin), | ||
postfilterPluginName: newPostFilterPlugin(postFilterPlugin), | ||
} | ||
|
||
|
@@ -629,6 +661,16 @@ func TestPostFilterPlugin(t *testing.T) { | |
{Name: filterPluginName}, | ||
}, | ||
}, | ||
Score: &schedulerconfig.PluginSet{ | ||
Enabled: []schedulerconfig.Plugin{ | ||
{Name: scorePluginName}, | ||
}, | ||
// disable default in-tree Score plugins | ||
// to make it easy to control configured ScorePlugins failure | ||
Disabled: []schedulerconfig.Plugin{ | ||
{Name: "*"}, | ||
}, | ||
}, | ||
PostFilter: &schedulerconfig.PluginSet{ | ||
everpeace marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Enabled: []schedulerconfig.Plugin{ | ||
{Name: postfilterPluginName}, | ||
|
@@ -646,7 +688,7 @@ func TestPostFilterPlugin(t *testing.T) { | |
testCtx := initTestSchedulerForFrameworkTest( | ||
t, | ||
testutils.InitTestMaster(t, fmt.Sprintf("postfilter%v-", i), nil), | ||
numNodes, | ||
tt.numNodes, | ||
scheduler.WithProfiles(prof), | ||
scheduler.WithFrameworkOutOfTreeRegistry(registry), | ||
) | ||
|
@@ -662,9 +704,13 @@ func TestPostFilterPlugin(t *testing.T) { | |
if err = wait.Poll(10*time.Millisecond, 10*time.Second, podUnschedulable(testCtx.ClientSet, pod.Namespace, pod.Name)); err != nil { | ||
t.Errorf("Didn't expect the pod to be scheduled.") | ||
} | ||
|
||
if filterPlugin.numFilterCalled < tt.expectFilterNumCalled { | ||
t.Errorf("Expected the filter plugin to be called at least %v times, but got %v.", tt.expectFilterNumCalled, filterPlugin.numFilterCalled) | ||
} | ||
if numScoreCalled := atomic.LoadInt32(&scorePlugin.numScoreCalled); numScoreCalled < tt.expectScoreNumCalled { | ||
t.Errorf("Expected the score plugin to be called at least %v times, but got %v.", tt.expectScoreNumCalled, numScoreCalled) | ||
everpeace marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
if postFilterPlugin.numPostFilterCalled < tt.expectPostFilterNumCalled { | ||
t.Errorf("Expected the postfilter plugin to be called at least %v times, but got %v.", tt.expectPostFilterNumCalled, postFilterPlugin.numPostFilterCalled) | ||
} | ||
|
@@ -675,6 +721,9 @@ func TestPostFilterPlugin(t *testing.T) { | |
if filterPlugin.numFilterCalled != tt.expectFilterNumCalled { | ||
t.Errorf("Expected the filter plugin to be called %v times, but got %v.", tt.expectFilterNumCalled, filterPlugin.numFilterCalled) | ||
} | ||
if numScoreCalled := atomic.LoadInt32(&scorePlugin.numScoreCalled); numScoreCalled != tt.expectScoreNumCalled { | ||
t.Errorf("Expected the score plugin to be called %v times, but got %v.", tt.expectScoreNumCalled, numScoreCalled) | ||
} | ||
if postFilterPlugin.numPostFilterCalled != tt.expectPostFilterNumCalled { | ||
t.Errorf("Expected the postfilter plugin to be called %v times, but got %v.", tt.expectPostFilterNumCalled, postFilterPlugin.numPostFilterCalled) | ||
} | ||
|
@@ -748,7 +797,7 @@ func TestScorePlugin(t *testing.T) { | |
} | ||
} | ||
|
||
if scorePlugin.numScoreCalled == 0 { | ||
if numScoreCalled := atomic.LoadInt32(&scorePlugin.numScoreCalled); numScoreCalled == 0 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. as mentioned in #93534 (review)
Sure, I updated to read |
||
t.Errorf("Expected the score plugin to be called.") | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if we need some caveat here or in
PluginsRunner
interface to make it clear that this is potentially for out-of-tree plugins only.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the comment. I think I don't need comments here and
PluginsRunner
because the scheduler framework is essentially for out-of-tree plugins.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okay, thanks!