@@ -84,6 +84,27 @@ func BeRunningNoRetries() types.GomegaMatcher {
84
84
)
85
85
}
86
86
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
+
87
108
// BeInPhase matches if pod.status.phase is the expected phase.
88
109
func BeInPhase (phase v1.PodPhase ) types.GomegaMatcher {
89
110
// A simple implementation of this would be:
@@ -526,6 +547,16 @@ func WaitTimeoutForPodRunningInNamespace(ctx context.Context, c clientset.Interf
526
547
Should (BeRunningNoRetries ())
527
548
}
528
549
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
+
529
560
// WaitForPodRunningInNamespace waits default amount of time (podStartTimeout) for the specified pod to become running.
530
561
// Returns an error if timeout occurs first, or pod goes in to failed state.
531
562
func WaitForPodRunningInNamespace (ctx context.Context , c clientset.Interface , pod * v1.Pod ) error {
0 commit comments