@@ -92,7 +92,8 @@ func LogPodsStatus(t *testing.T, cl client.Client, namespace string, selectors m
9292	for  i  :=  range  pods .Items  {
9393		p  :=  & pods .Items [i ]
9494		var  containerSummaries  []string 
95- 		for  _ , cs  :=  range  p .Status .ContainerStatuses  {
95+ 		for  i  :=  0 ; i  <  len (p .Status .ContainerStatuses ); i ++  {
96+ 			cs  :=  p .Status .ContainerStatuses [i ]
9697			state  :=  "unknown" 
9798			switch  {
9899			case  cs .State .Waiting  !=  nil :
@@ -111,64 +112,47 @@ func LogPodsStatus(t *testing.T, cl client.Client, namespace string, selectors m
111112	}
112113}
113114
114- // WaitForPods waits for the pods in the given namespace and with the given selector 
115- // to be in the given phase and condition. 
116115func  WaitForPods (t  * testing.T , cl  client.Client , namespace  string , selectors  map [string ]string , phase  corev1.PodPhase , condition  * corev1.PodCondition ) {
117116	if  condition  ==  nil  {
118117		t .Fatalf ("condition cannot be nil" )
119118	}
120119	tlog .Logf (t , "waiting for %s/[%s] to be %v..." , namespace , selectors , phase )
121120
122- 	timeout  :=  time .After (defaultServiceStartupTimeout )
123- 	ticker  :=  time .NewTicker (2  *  time .Second )
124- 	defer  ticker .Stop ()
125- 
126- 	for  {
121+ 	require .Eventually (t , func () bool  {
127122		pods  :=  & corev1.PodList {}
123+ 
128124		err  :=  cl .List (context .Background (), pods , & client.ListOptions {
129125			Namespace :     namespace ,
130126			LabelSelector : labels .SelectorFromSet (selectors ),
131127		})
132- 		if  err  ==  nil  &&  len (pods .Items ) >  0  {
133- 			success  :=  true 
134- 		checkPods:
135- 			for  i  :=  range  pods .Items  {
136- 				p  :=  & pods .Items [i ]
137- 				if  p .Status .Phase  !=  phase  {
138- 					success  =  false 
139- 					break 
140- 				}
141128
142- 				if  p .Status .Conditions  ==  nil  {
143- 					success  =  false 
144- 					break 
145- 				}
129+ 		if  err  !=  nil  ||  len (pods .Items ) ==  0  {
130+ 			return  false 
131+ 		}
146132
147- 				conditionMet  :=  false 
148- 				for  _ , c  :=  range  p .Status .Conditions  {
149- 					if  c .Type  ==  condition .Type  &&  c .Status  ==  condition .Status  {
150- 						conditionMet  =  true 
151- 						continue  checkPods
152- 					}
153- 				}
154- 				if  ! conditionMet  {
155- 					success  =  false 
156- 					break 
157- 				}
133+ 	checkPods:
134+ 		for  i  :=  range  pods .Items  {
135+ 			p  :=  & pods .Items [i ]
136+ 			if  p .Status .Phase  !=  phase  {
137+ 				return  false 
158138			}
159139
160- 			if  success  {
161- 				return 
140+ 			if  p . Status . Conditions   ==   nil  {
141+ 				return   false 
162142			}
163- 		}
164143
165- 		select  {
166- 		case  <- timeout :
167- 			LogPodsStatus (t , cl , namespace , selectors , fmt .Sprintf ("timed out waiting for pods to reach %s/%s" , phase , condition .Type ))
168- 			t .Fatalf ("timed out waiting for pods in %s with selector %v to reach phase %s and condition %s" , namespace , selectors , phase , condition .Type )
169- 		case  <- ticker .C :
144+ 			for  _ , c  :=  range  p .Status .Conditions  {
145+ 				if  c .Type  ==  condition .Type  &&  c .Status  ==  condition .Status  {
146+ 					continue  checkPods // pod is ready, check next pod 
147+ 				}
148+ 			}
149+ 
150+ 			tlog .Logf (t , "pod %s/%s status: %v" , p .Namespace , p .Name , p .Status )
151+ 			return  false 
170152		}
171- 	}
153+ 
154+ 		return  true 
155+ 	}, defaultServiceStartupTimeout , 2 * time .Second )
172156}
173157
174158// SecurityPolicyMustBeAccepted waits for the specified SecurityPolicy to be accepted. 
0 commit comments