testcluster: Handle short-lived pods in WaitForPodRunning.

Prior to this change, `WaitForPodRunning` was susceptible to a race
condition whereby a short-lived pod could run and complete before the
poll loop notices that its state has changed to "running".

PiperOrigin-RevId: 707380314
This commit is contained in:
Etienne Perot
2024-12-17 21:19:16 -08:00
committed by gVisor bot
parent c87b16ccc8
commit f34ef4e1f7
+3 -1
View File
@@ -451,7 +451,9 @@ func (t *TestCluster) ReadPodLogs(ctx context.Context, pod *v13.Pod) (string, er
// WaitForPodRunning is a helper method to wait for a pod to be running.
func (t *TestCluster) WaitForPodRunning(ctx context.Context, pod *v13.Pod) error {
_, err := t.doWaitForPod(ctx, pod, func(p v13.PodPhase) bool { return p == v13.PodRunning })
// We also accept pods in the PodSucceeded state, because short-lived pods
// may have already ran and succeeded by the time we poll them.
_, err := t.doWaitForPod(ctx, pod, func(p v13.PodPhase) bool { return p == v13.PodRunning || p == v13.PodSucceeded })
return err
}