Cleanup "slow-path" logic in scheduler Filters

This commit is contained in:
notpad
2020-02-10 22:48:49 +08:00
parent 06c639fb4a
commit a7057f8df0
11 changed files with 65 additions and 421 deletions

View File

@@ -86,9 +86,8 @@ func (pl *NodePorts) PreFilterExtensions() framework.PreFilterExtensions {
func getPreFilterState(cycleState *framework.CycleState) (preFilterState, error) {
c, err := cycleState.Read(preFilterStateKey)
if err != nil {
// preFilterState state doesn't exist. We ignore the error for now since
// Filter is able to handle that by computing it again.
return nil, nil
// preFilterState state doesn't exist.
return nil, fmt.Errorf("error reading %q from cycleState: %v", preFilterStateKey, err)
}
s, ok := c.(preFilterState)
@@ -105,12 +104,7 @@ func (pl *NodePorts) Filter(ctx context.Context, cycleState *framework.CycleStat
return framework.NewStatus(framework.Error, err.Error())
}
var fits bool
if wantPorts != nil {
fits = fitsPorts(wantPorts, nodeInfo)
} else {
fits = Fits(pod, nodeInfo)
}
fits := fitsPorts(wantPorts, nodeInfo)
if !fits {
return framework.NewStatus(framework.Unschedulable, ErrReason)
}

View File

@@ -163,45 +163,6 @@ func TestNodePorts(t *testing.T) {
}
}
func TestPreFilterDisabled(t *testing.T) {
tests := []struct {
pod *v1.Pod
nodeInfo *schedulernodeinfo.NodeInfo
name string
wantStatus *framework.Status
}{
{
pod: &v1.Pod{},
nodeInfo: schedulernodeinfo.NewNodeInfo(),
name: "nothing running",
},
{
pod: newPod("m1", "UDP/127.0.0.1/8080"),
nodeInfo: schedulernodeinfo.NewNodeInfo(
newPod("m1", "UDP/127.0.0.1/9090")),
name: "other port",
},
{
pod: newPod("m1", "UDP/127.0.0.1/8080"),
nodeInfo: schedulernodeinfo.NewNodeInfo(
newPod("m1", "UDP/127.0.0.1/8080")),
name: "same udp port",
wantStatus: framework.NewStatus(framework.Unschedulable, ErrReason),
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
p, _ := New(nil, nil)
cycleState := framework.NewCycleState()
gotStatus := p.(framework.FilterPlugin).Filter(context.Background(), cycleState, test.pod, test.nodeInfo)
if !reflect.DeepEqual(gotStatus, test.wantStatus) {
t.Errorf("status does not match: %v, want: %v", gotStatus, test.wantStatus)
}
})
}
}
func TestGetContainerPorts(t *testing.T) {
tests := []struct {
pod1 *v1.Pod