Skip to content

Commit cf07a65

Browse files
authored
Merge pull request kubernetes#130612 from carlory/fix-sleep-infinity-on-windows
Fix non-portable use of "sleep infinity"
2 parents 43560c6 + 0a32e7d commit cf07a65

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

test/e2e/framework/pod/utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ const InfiniteSleepCommand = "trap exit TERM; while true; do sleep 1; done"
4343
//
4444
// This is useful for testing scenarios where the container is terminated
4545
// with a non-zero exit code.
46-
const InfiniteSleepCommandWithoutGracefulShutdown = "sleep infinity"
46+
const InfiniteSleepCommandWithoutGracefulShutdown = "while true; do sleep 100000; done"
4747

4848
// GenerateScriptCmd generates the corresponding command lines to execute a command.
4949
func GenerateScriptCmd(command string) []string {

test/e2e/framework/pod/wait.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,27 @@ func BeRunningNoRetries() types.GomegaMatcher {
8484
)
8585
}
8686

87+
// BeRunningReadyNoRetries verifies that a pod starts running and has a ready
88+
// condition of status true. It's a permanent failure when the pod enters some
89+
// other permanent phase.
90+
func BeRunningReadyNoRetries() types.GomegaMatcher {
91+
return gomega.And(
92+
// This additional matcher checks for the final error condition.
93+
gcustom.MakeMatcher(func(pod *v1.Pod) (bool, error) {
94+
switch pod.Status.Phase {
95+
case v1.PodFailed, v1.PodSucceeded:
96+
return false, gomega.StopTrying(fmt.Sprintf("Expected pod to reach phase %q, got final phase %q instead:\n%s", v1.PodRunning, pod.Status.Phase, format.Object(pod, 1)))
97+
default:
98+
return true, nil
99+
}
100+
}),
101+
BeInPhase(v1.PodRunning),
102+
gcustom.MakeMatcher(func(pod *v1.Pod) (bool, error) {
103+
return podutils.IsPodReady(pod), nil
104+
}).WithMessage("Expected pod to have a ready condition of status true"),
105+
)
106+
}
107+
87108
// BeInPhase matches if pod.status.phase is the expected phase.
88109
func BeInPhase(phase v1.PodPhase) types.GomegaMatcher {
89110
// A simple implementation of this would be:
@@ -526,6 +547,16 @@ func WaitTimeoutForPodRunningInNamespace(ctx context.Context, c clientset.Interf
526547
Should(BeRunningNoRetries())
527548
}
528549

550+
// WaitTimeoutForPodRunningReadyInNamespace waits the given timeout duration for the specified pod to become running
551+
// and have a ready condition of status true.
552+
// It does not need to exist yet when this function gets called and the pod is not expected to be recreated
553+
// when it succeeds or fails.
554+
func WaitTimeoutForPodRunningReadyInNamespace(ctx context.Context, c clientset.Interface, podName, namespace string, timeout time.Duration) error {
555+
return framework.Gomega().Eventually(ctx, framework.RetryNotFound(framework.GetObject(c.CoreV1().Pods(namespace).Get, podName, metav1.GetOptions{}))).
556+
WithTimeout(timeout).
557+
Should(BeRunningReadyNoRetries())
558+
}
559+
529560
// WaitForPodRunningInNamespace waits default amount of time (podStartTimeout) for the specified pod to become running.
530561
// Returns an error if timeout occurs first, or pod goes in to failed state.
531562
func WaitForPodRunningInNamespace(ctx context.Context, c clientset.Interface, pod *v1.Pod) error {

test/e2e/storage/testsuites/subpath.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -806,8 +806,8 @@ func testPodContainerRestartWithHooks(ctx context.Context, f *framework.Framewor
806806
pod, err := f.ClientSet.CoreV1().Pods(f.Namespace.Name).Create(ctx, pod, metav1.CreateOptions{})
807807
framework.ExpectNoError(err, "while creating pod")
808808
ginkgo.DeferCleanup(e2epod.DeletePodWithWait, f.ClientSet, pod)
809-
err = e2epod.WaitTimeoutForPodRunningInNamespace(ctx, f.ClientSet, pod.Name, pod.Namespace, f.Timeouts.PodStart)
810-
framework.ExpectNoError(err, "while waiting for pod to be running")
809+
err = e2epod.WaitTimeoutForPodRunningReadyInNamespace(ctx, f.ClientSet, pod.Name, pod.Namespace, f.Timeouts.PodStart)
810+
framework.ExpectNoError(err, "while waiting for pod to be running and ready")
811811

812812
ginkgo.By("Failing liveness probe")
813813
hooks.FailLivenessProbe(pod, probeFilePath)

0 commit comments

Comments
 (0)