Skip to content

Commit 59f9858

Browse files
committed
Move function specific to container restart test inline
Signed-off-by: Laura Lorenz <[email protected]>
1 parent 529d5ba commit 59f9858

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

test/e2e/framework/pod/wait.go

-13
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ import (
3737
apitypes "k8s.io/apimachinery/pkg/types"
3838
clientset "k8s.io/client-go/kubernetes"
3939
"k8s.io/kubectl/pkg/util/podutils"
40-
podv1util "k8s.io/kubernetes/pkg/api/v1/pod"
4140
"k8s.io/kubernetes/test/e2e/framework"
4241
testutils "k8s.io/kubernetes/test/utils"
4342
"k8s.io/kubernetes/test/utils/format"
@@ -869,15 +868,3 @@ func WaitForContainerTerminated(ctx context.Context, c clientset.Interface, name
869868
return false, nil
870869
})
871870
}
872-
873-
// WaitForContainerRestartedNTimes waits for the given normal container in the Pod to have restarted N times
874-
func WaitForContainerRestartedNTimes(ctx context.Context, c clientset.Interface, namespace string, podName string, containerName string, timeout time.Duration, target int) error {
875-
conditionDesc := fmt.Sprintf("A container in pod %s restarted at least %d times", podName, target)
876-
return WaitForPodCondition(ctx, c, namespace, podName, conditionDesc, timeout, func(pod *v1.Pod) (bool, error) {
877-
cs, found := podv1util.GetContainerStatus(pod.Status.ContainerStatuses, containerName)
878-
if !found {
879-
return false, fmt.Errorf("could not find container %s in pod %s", containerName, podName)
880-
}
881-
return cs.RestartCount >= int32(target), nil
882-
})
883-
}

test/e2e_node/container_restart_test.go

+14-1
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ package e2enode
2121

2222
import (
2323
"context"
24+
"fmt"
2425
"time"
2526

27+
podv1util "k8s.io/kubernetes/pkg/api/v1/pod"
2628
imageutils "k8s.io/kubernetes/test/utils/image"
2729

2830
"github.com/onsi/ginkgo/v2"
@@ -97,7 +99,7 @@ func doTest(ctx context.Context, f *framework.Framework, targetRestarts int, con
9799

98100
// Hard wait 30 seconds for targetRestarts in the best case; longer timeout later will handle if infra was slow.
99101
time.Sleep(30 * time.Second)
100-
podErr = e2epod.WaitForContainerRestartedNTimes(ctx, f.ClientSet, f.Namespace.Name, pod.Name, containerName, 5*time.Minute, targetRestarts)
102+
podErr = waitForContainerRestartedNTimes(ctx, f, f.Namespace.Name, pod.Name, containerName, 5*time.Minute, targetRestarts)
101103
gomega.Expect(podErr).ShouldNot(gomega.HaveOccurred(), "Expected container to repeatedly back off container failures")
102104

103105
r, err := extractObservedBackoff(ctx, f, pod.Name, containerName)
@@ -140,3 +142,14 @@ func newFailAlwaysPod() *v1.Pod {
140142
}
141143
return pod
142144
}
145+
146+
func waitForContainerRestartedNTimes(ctx context.Context, f *framework.Framework, namespace string, podName string, containerName string, timeout time.Duration, target int) error {
147+
conditionDesc := fmt.Sprintf("A container in pod %s restarted at least %d times", podName, target)
148+
return e2epod.WaitForPodCondition(ctx, f.ClientSet, namespace, podName, conditionDesc, timeout, func(pod *v1.Pod) (bool, error) {
149+
cs, found := podv1util.GetContainerStatus(pod.Status.ContainerStatuses, containerName)
150+
if !found {
151+
return false, fmt.Errorf("could not find container %s in pod %s", containerName, podName)
152+
}
153+
return cs.RestartCount >= int32(target), nil
154+
})
155+
}

0 commit comments

Comments
 (0)