forget the pod when the reserve plugins fail

and move the metrics function calls before all other functions
This commit is contained in:
Yecheng Fu
2020-08-09 20:28:23 +08:00
parent 9b78bd5979
commit 1176ef9c7d
4 changed files with 157 additions and 18 deletions

View File

@@ -214,17 +214,57 @@ func TestSchedulerScheduleOne(t *testing.T) {
errB := errors.New("binder")
table := []struct {
name string
injectBindError error
sendPod *v1.Pod
algo core.ScheduleAlgorithm
expectErrorPod *v1.Pod
expectForgetPod *v1.Pod
expectAssumedPod *v1.Pod
expectError error
expectBind *v1.Binding
eventReason string
name string
injectBindError error
sendPod *v1.Pod
algo core.ScheduleAlgorithm
registerPluginFuncs []st.RegisterPluginFunc
expectErrorPod *v1.Pod
expectForgetPod *v1.Pod
expectAssumedPod *v1.Pod
expectError error
expectBind *v1.Binding
eventReason string
}{
{
name: "error reserve pod",
sendPod: podWithID("foo", ""),
algo: mockScheduler{core.ScheduleResult{SuggestedHost: testNode.Name, EvaluatedNodes: 1, FeasibleNodes: 1}, nil},
registerPluginFuncs: []st.RegisterPluginFunc{
st.RegisterReservePlugin("FakeReserve", st.NewFakeReservePlugin(framework.NewStatus(framework.Error, "reserve error"))),
},
expectErrorPod: podWithID("foo", testNode.Name),
expectForgetPod: podWithID("foo", testNode.Name),
expectAssumedPod: podWithID("foo", testNode.Name),
expectError: errors.New(`error while running Reserve in "FakeReserve" reserve plugin for pod "foo": reserve error`),
eventReason: "FailedScheduling",
},
{
name: "error permit pod",
sendPod: podWithID("foo", ""),
algo: mockScheduler{core.ScheduleResult{SuggestedHost: testNode.Name, EvaluatedNodes: 1, FeasibleNodes: 1}, nil},
registerPluginFuncs: []st.RegisterPluginFunc{
st.RegisterPermitPlugin("FakePermit", st.NewFakePermitPlugin(framework.NewStatus(framework.Error, "permit error"), time.Minute)),
},
expectErrorPod: podWithID("foo", testNode.Name),
expectForgetPod: podWithID("foo", testNode.Name),
expectAssumedPod: podWithID("foo", testNode.Name),
expectError: errors.New(`error while running "FakePermit" permit plugin for pod "foo": permit error`),
eventReason: "FailedScheduling",
},
{
name: "error prebind pod",
sendPod: podWithID("foo", ""),
algo: mockScheduler{core.ScheduleResult{SuggestedHost: testNode.Name, EvaluatedNodes: 1, FeasibleNodes: 1}, nil},
registerPluginFuncs: []st.RegisterPluginFunc{
st.RegisterPreBindPlugin("FakePreBind", st.NewFakePreBindPlugin(framework.NewStatus(framework.Error, "prebind error"))),
},
expectErrorPod: podWithID("foo", testNode.Name),
expectForgetPod: podWithID("foo", testNode.Name),
expectAssumedPod: podWithID("foo", testNode.Name),
expectError: errors.New(`error while running "FakePreBind" prebind plugin for pod "foo": prebind error`),
eventReason: "FailedScheduling",
},
{
name: "bind assumed pod scheduled",
sendPod: podWithID("foo", ""),
@@ -252,7 +292,8 @@ func TestSchedulerScheduleOne(t *testing.T) {
expectErrorPod: podWithID("foo", testNode.Name),
expectForgetPod: podWithID("foo", testNode.Name),
eventReason: "FailedScheduling",
}, {
},
{
name: "deleting pod",
sendPod: deletingPod("foo"),
algo: mockScheduler{core.ScheduleResult{}, nil},
@@ -296,10 +337,11 @@ func TestSchedulerScheduleOne(t *testing.T) {
gotBinding = action.(clienttesting.CreateAction).GetObject().(*v1.Binding)
return true, gotBinding, item.injectBindError
})
fwk, err := st.NewFramework([]st.RegisterPluginFunc{
registerPluginFuncs := append(item.registerPluginFuncs,
st.RegisterQueueSortPlugin(queuesort.Name, queuesort.New),
st.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New),
}, frameworkruntime.WithClientSet(client))
)
fwk, err := st.NewFramework(registerPluginFuncs, frameworkruntime.WithClientSet(client))
if err != nil {
t.Fatal(err)
}