Skip to content

Commit

Permalink
LowNodeUtilization: use clientset in testing, drop all custom reactors
Browse files Browse the repository at this point in the history
  • Loading branch information
ingvagabund committed Aug 25, 2020
1 parent d65a7c4 commit 4e152a2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
5 changes: 5 additions & 0 deletions pkg/descheduler/pod/pods.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ func ListPodsOnANode(
}

for i := range podList.Items {
// fake client does not support field selectors
// so let's filter based on the node name as well (quite cheap)
if podList.Items[i].Spec.NodeName != node.Name {
continue
}
if options.filter != nil && !options.filter(&podList.Items[i]) {
continue
}
Expand Down
20 changes: 6 additions & 14 deletions pkg/descheduler/strategies/lownodeutilization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ func TestLowNodeUtilization(t *testing.T) {
},
n2NodeName: {
Items: []v1.Pod{
*test.BuildTestPod("p9", 400, 2100, n1NodeName, test.SetRSOwnerRef),
*test.BuildTestPod("p9", 400, 2100, n2NodeName, test.SetRSOwnerRef),
},
},
n3NodeName: {},
Expand Down Expand Up @@ -803,29 +803,21 @@ func TestWithTaints(t *testing.T) {
objs = append(objs, pod)
}

fakePtr := newFake(objs...)
var evictionCounter int
fakePtr.PrependReactor("create", "pods", func(action core.Action) (bool, runtime.Object, error) {
if action.GetSubresource() != "eviction" || action.GetResource().Resource != "pods" {
return false, nil, nil
}
evictionCounter++
return true, nil, nil
})
fakeClient := fake.NewSimpleClientset(objs...)

podEvictor := evictions.NewPodEvictor(
&fake.Clientset{Fake: *fakePtr},
fakeClient,
"policy/v1",
false,
item.evictionsExpected,
item.nodes,
false,
)

LowNodeUtilization(ctx, &fake.Clientset{Fake: *fakePtr}, strategy, item.nodes, podEvictor)
LowNodeUtilization(ctx, fakeClient, strategy, item.nodes, podEvictor)

if item.evictionsExpected != evictionCounter {
t.Errorf("Expected %v evictions, got %v", item.evictionsExpected, evictionCounter)
if item.evictionsExpected != podEvictor.TotalEvicted() {
t.Errorf("Expected %v evictions, got %v", item.evictionsExpected, podEvictor.TotalEvicted())
}
})
}
Expand Down

0 comments on commit 4e152a2

Please sign in to comment.