Skip to content

Commit af1e1f4

Browse files
committed
Remove dependency for node integration tests from e2e fw
1 parent 22a4c2c commit af1e1f4

File tree

2 files changed

+36
-4
lines changed

2 files changed

+36
-4
lines changed

test/integration/node/BUILD

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ go_test(
1414
],
1515
tags = ["integration"],
1616
deps = [
17+
"//pkg/api/v1/pod:go_default_library",
1718
"//pkg/controller/nodelifecycle:go_default_library",
1819
"//plugin/pkg/admission/defaulttolerationseconds:go_default_library",
1920
"//plugin/pkg/admission/podtolerationrestriction:go_default_library",
@@ -27,7 +28,6 @@ go_test(
2728
"//staging/src/k8s.io/client-go/informers:go_default_library",
2829
"//staging/src/k8s.io/client-go/kubernetes:go_default_library",
2930
"//staging/src/k8s.io/client-go/rest:go_default_library",
30-
"//test/e2e/framework/pod:go_default_library",
3131
"//test/integration/framework:go_default_library",
3232
"//test/integration/util:go_default_library",
3333
"//test/utils/image:go_default_library",

test/integration/node/lifecycle_test.go

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,22 @@ import (
3030
"k8s.io/apiserver/pkg/admission"
3131
"k8s.io/client-go/informers"
3232
"k8s.io/client-go/kubernetes"
33+
clientset "k8s.io/client-go/kubernetes"
3334
restclient "k8s.io/client-go/rest"
35+
podutil "k8s.io/kubernetes/pkg/api/v1/pod"
3436
"k8s.io/kubernetes/pkg/controller/nodelifecycle"
3537
"k8s.io/kubernetes/plugin/pkg/admission/defaulttolerationseconds"
3638
"k8s.io/kubernetes/plugin/pkg/admission/podtolerationrestriction"
3739
pluginapi "k8s.io/kubernetes/plugin/pkg/admission/podtolerationrestriction/apis/podtolerationrestriction"
38-
"k8s.io/kubernetes/test/e2e/framework/pod"
3940
testutils "k8s.io/kubernetes/test/integration/util"
4041
imageutils "k8s.io/kubernetes/test/utils/image"
4142
)
4243

44+
// poll is how often to poll pods, nodes and claims.
45+
const poll = 2 * time.Second
46+
47+
type podCondition func(pod *v1.Pod) (bool, error)
48+
4349
// TestTaintBasedEvictions tests related cases for the TaintBasedEvictions feature
4450
func TestTaintBasedEvictions(t *testing.T) {
4551
// we need at least 2 nodes to prevent lifecycle manager from entering "fully-disrupted" mode
@@ -275,7 +281,7 @@ func TestTaintBasedEvictions(t *testing.T) {
275281
}
276282

277283
if test.pod != nil {
278-
err = pod.WaitForPodCondition(cs, testCtx.NS.Name, test.pod.Name, test.waitForPodCondition, time.Second*15, func(pod *v1.Pod) (bool, error) {
284+
err = waitForPodCondition(cs, testCtx.NS.Name, test.pod.Name, test.waitForPodCondition, time.Second*15, func(pod *v1.Pod) (bool, error) {
279285
// as node is unreachable, pod0 is expected to be in Terminating status
280286
// rather than getting deleted
281287
if tolerationSeconds[i] == 0 {
@@ -285,7 +291,7 @@ func TestTaintBasedEvictions(t *testing.T) {
285291
return seconds == tolerationSeconds[i], nil
286292
}
287293
return false, nil
288-
})
294+
}, t)
289295
if err != nil {
290296
pod, _ := cs.CoreV1().Pods(testCtx.NS.Name).Get(context.TODO(), test.pod.Name, metav1.GetOptions{})
291297
t.Fatalf("Error: %v, Expected test pod to be %s but it's %v", err, test.waitForPodCondition, pod)
@@ -297,3 +303,29 @@ func TestTaintBasedEvictions(t *testing.T) {
297303
})
298304
}
299305
}
306+
307+
// waitForPodCondition waits a pods to be matched to the given condition.
308+
func waitForPodCondition(c clientset.Interface, ns, podName, desc string, timeout time.Duration, condition podCondition, t *testing.T) error {
309+
t.Logf("Waiting up to %v for pod %q in namespace %q to be %q", timeout, podName, ns, desc)
310+
for start := time.Now(); time.Since(start) < timeout; time.Sleep(poll) {
311+
pod, err := c.CoreV1().Pods(ns).Get(context.TODO(), podName, metav1.GetOptions{})
312+
if err != nil {
313+
if apierrors.IsNotFound(err) {
314+
t.Logf("Pod %q in namespace %q not found. Error: %v", podName, ns, err)
315+
return err
316+
}
317+
t.Logf("Get pod %q in namespace %q failed, ignoring for %v. Error: %v", podName, ns, poll, err)
318+
continue
319+
}
320+
// log now so that current pod info is reported before calling `condition()`
321+
t.Logf("Pod %q: Phase=%q, Reason=%q, readiness=%t. Elapsed: %v",
322+
podName, pod.Status.Phase, pod.Status.Reason, podutil.IsPodReady(pod), time.Since(start))
323+
if done, err := condition(pod); done {
324+
if err == nil {
325+
t.Logf("Pod %q satisfied condition %q", podName, desc)
326+
}
327+
return err
328+
}
329+
}
330+
return fmt.Errorf("gave up after waiting %v for pod %q to be %q", timeout, podName, desc)
331+
}

0 commit comments

Comments
 (0)