Skip to content

Commit

Permalink
Cleanup Pods in TestNominatedNodeCleanUp.
Browse files Browse the repository at this point in the history
Signed-off-by: Da K. Ma <[email protected]>
  • Loading branch information
k82cn committed May 7, 2018
1 parent bac31d6 commit 5257dfc
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
4 changes: 4 additions & 0 deletions test/integration/scheduler/preemption_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,11 @@ func TestNominatedNodeCleanUp(t *testing.T) {
// Initialize scheduler.
context := initTest(t, "preemption")
defer cleanupTest(t, context)

cs := context.clientSet

defer cleanupPodsInNamespace(cs, t, context.ns.Name)

// Create a node with some resources and a label.
nodeRes := &v1.ResourceList{
v1.ResourcePods: *resource.NewQuantity(32, resource.DecimalSI),
Expand Down
26 changes: 26 additions & 0 deletions test/integration/scheduler/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -534,3 +534,29 @@ func cleanupPods(cs clientset.Interface, t *testing.T, pods []*v1.Pod) {
}
}
}

// noPodsInNamespace returns true if no pods in the given namespace.
func noPodsInNamespace(c clientset.Interface, podNamespace string) wait.ConditionFunc {
return func() (bool, error) {
pods, err := c.CoreV1().Pods(podNamespace).List(metav1.ListOptions{})
if err != nil {
return false, err
}

return len(pods.Items) == 0, nil
}
}

// cleanupPodsInNamespace deletes the pods in the given namespace and waits for them to
// be actually deleted.
func cleanupPodsInNamespace(cs clientset.Interface, t *testing.T, ns string) {
if err := cs.CoreV1().Pods(ns).DeleteCollection(nil, metav1.ListOptions{}); err != nil {
t.Errorf("error while listing pod in namespace %v: %v", ns, err)
return
}

if err := wait.Poll(time.Second, wait.ForeverTestTimeout,
noPodsInNamespace(cs, ns)); err != nil {
t.Errorf("error while waiting for pods in namespace %v: %v", ns, err)
}
}

0 comments on commit 5257dfc

Please sign in to comment.