Skip to content

Commit 613ee7f

Browse files
authored
Merge pull request kubernetes#95233 from jsafrane/framework-start-error
Add error text to kube-system wait error
2 parents c905130 + 6e85ebd commit 613ee7f

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

test/e2e/framework/pod/wait.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,11 @@ const (
6767
type podCondition func(pod *v1.Pod) (bool, error)
6868

6969
// 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 {
7171
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+
}
7275
// Print bad pods info only if there are fewer than 10 bad pods
7376
if len(badPods) > 10 {
7477
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
110113
badPods := []v1.Pod{}
111114
desiredPods := 0
112115
notReady := int32(0)
116+
var lastAPIError error
113117

114118
if wait.PollImmediate(poll, timeout, func() (bool, error) {
115119
// We get the new list of pods, replication controllers, and
116120
// replica sets in every iteration because more pods come
117121
// online during startup and we want to ensure they are also
118122
// checked.
119123
replicas, replicaOk := int32(0), int32(0)
124+
// Clear API error from the last attempt in case the following calls succeed.
125+
lastAPIError = nil
120126

121127
rcList, err := c.CoreV1().ReplicationControllers(ns).List(context.TODO(), metav1.ListOptions{})
122128
if err != nil {
123129
e2elog.Logf("Error getting replication controllers in namespace '%s': %v", ns, err)
130+
lastAPIError = err
124131
if testutils.IsRetryableAPIError(err) {
125132
return false, nil
126133
}
@@ -133,6 +140,7 @@ func WaitForPodsRunningReady(c clientset.Interface, ns string, minPods, allowedN
133140

134141
rsList, err := c.AppsV1().ReplicaSets(ns).List(context.TODO(), metav1.ListOptions{})
135142
if err != nil {
143+
lastAPIError = err
136144
e2elog.Logf("Error getting replication sets in namespace %q: %v", ns, err)
137145
if testutils.IsRetryableAPIError(err) {
138146
return false, nil
@@ -146,6 +154,7 @@ func WaitForPodsRunningReady(c clientset.Interface, ns string, minPods, allowedN
146154

147155
podList, err := c.CoreV1().Pods(ns).List(context.TODO(), metav1.ListOptions{})
148156
if err != nil {
157+
lastAPIError = err
149158
e2elog.Logf("Error getting pods in namespace '%s': %v", ns, err)
150159
if testutils.IsRetryableAPIError(err) {
151160
return false, nil
@@ -193,7 +202,7 @@ func WaitForPodsRunningReady(c clientset.Interface, ns string, minPods, allowedN
193202
return false, nil
194203
}) != nil {
195204
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))
197206
}
198207
e2elog.Logf("Number of not-ready pods (%d) is below the allowed threshold (%d).", notReady, allowedNotReadyPods)
199208
}

0 commit comments

Comments
 (0)