@@ -67,8 +67,11 @@ const (
67
67
type podCondition func (pod * v1.Pod ) (bool , error )
68
68
69
69
// errorBadPodsStates create error message of basic info of bad pods for debugging.
70
- func errorBadPodsStates (badPods []v1.Pod , desiredPods int , ns , desiredState string , timeout time.Duration ) string {
70
+ func errorBadPodsStates (badPods []v1.Pod , desiredPods int , ns , desiredState string , timeout time.Duration , err error ) string {
71
71
errStr := fmt .Sprintf ("%d / %d pods in namespace %q are NOT in %s state in %v\n " , len (badPods ), desiredPods , ns , desiredState , timeout )
72
+ if err != nil {
73
+ errStr += fmt .Sprintf ("Last error: %s\n " , err )
74
+ }
72
75
// Print bad pods info only if there are fewer than 10 bad pods
73
76
if len (badPods ) > 10 {
74
77
return errStr + "There are too many bad pods. Please check log for details."
@@ -110,17 +113,21 @@ func WaitForPodsRunningReady(c clientset.Interface, ns string, minPods, allowedN
110
113
badPods := []v1.Pod {}
111
114
desiredPods := 0
112
115
notReady := int32 (0 )
116
+ var lastAPIError error
113
117
114
118
if wait .PollImmediate (poll , timeout , func () (bool , error ) {
115
119
// We get the new list of pods, replication controllers, and
116
120
// replica sets in every iteration because more pods come
117
121
// online during startup and we want to ensure they are also
118
122
// checked.
119
123
replicas , replicaOk := int32 (0 ), int32 (0 )
124
+ // Clear API error from the last attempt in case the following calls succeed.
125
+ lastAPIError = nil
120
126
121
127
rcList , err := c .CoreV1 ().ReplicationControllers (ns ).List (context .TODO (), metav1.ListOptions {})
122
128
if err != nil {
123
129
e2elog .Logf ("Error getting replication controllers in namespace '%s': %v" , ns , err )
130
+ lastAPIError = err
124
131
if testutils .IsRetryableAPIError (err ) {
125
132
return false , nil
126
133
}
@@ -133,6 +140,7 @@ func WaitForPodsRunningReady(c clientset.Interface, ns string, minPods, allowedN
133
140
134
141
rsList , err := c .AppsV1 ().ReplicaSets (ns ).List (context .TODO (), metav1.ListOptions {})
135
142
if err != nil {
143
+ lastAPIError = err
136
144
e2elog .Logf ("Error getting replication sets in namespace %q: %v" , ns , err )
137
145
if testutils .IsRetryableAPIError (err ) {
138
146
return false , nil
@@ -146,6 +154,7 @@ func WaitForPodsRunningReady(c clientset.Interface, ns string, minPods, allowedN
146
154
147
155
podList , err := c .CoreV1 ().Pods (ns ).List (context .TODO (), metav1.ListOptions {})
148
156
if err != nil {
157
+ lastAPIError = err
149
158
e2elog .Logf ("Error getting pods in namespace '%s': %v" , ns , err )
150
159
if testutils .IsRetryableAPIError (err ) {
151
160
return false , nil
@@ -193,7 +202,7 @@ func WaitForPodsRunningReady(c clientset.Interface, ns string, minPods, allowedN
193
202
return false , nil
194
203
}) != nil {
195
204
if ! ignoreNotReady {
196
- return errors .New (errorBadPodsStates (badPods , desiredPods , ns , "RUNNING and READY" , timeout ))
205
+ return errors .New (errorBadPodsStates (badPods , desiredPods , ns , "RUNNING and READY" , timeout , lastAPIError ))
197
206
}
198
207
e2elog .Logf ("Number of not-ready pods (%d) is below the allowed threshold (%d)." , notReady , allowedNotReadyPods )
199
208
}
0 commit comments