Commit fa96ff3b authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #33813 from ymqytw/improve_e2e_error_message

Automatic merge from submit-queue Provide more detailed error message when pod fails to be success state Return more detailed error message when it timeouts for waiting for pod to success state. This PR extends #31895. #31895 is for running and ready state. It is used for debugging #31561 #32980 cc: @lavalamp
parents 8cdd5269 44eade9b
...@@ -507,8 +507,8 @@ func logPodStates(pods []api.Pod) { ...@@ -507,8 +507,8 @@ func logPodStates(pods []api.Pod) {
} }
// errorBadPodsStates create error message of basic info of bad pods for debugging. // errorBadPodsStates create error message of basic info of bad pods for debugging.
func errorBadPodsStates(badPods []api.Pod, desiredPods int, ns string, timeout time.Duration) string { func errorBadPodsStates(badPods []api.Pod, desiredPods int, ns, desiredState string, timeout time.Duration) string {
errStr := fmt.Sprintf("%d / %d pods in namespace %q are NOT in the desired state in %v\n", len(badPods), desiredPods, ns, timeout) errStr := fmt.Sprintf("%d / %d pods in namespace %q are NOT in %s state in %v\n", len(badPods), desiredPods, ns, desiredState, timeout)
// Pirnt bad pods info only if there are fewer than 10 bad pods // Pirnt bad pods info only if there are fewer than 10 bad pods
if len(badPods) > 10 { if len(badPods) > 10 {
return errStr + "There are too many bad pods. Please check log for details." return errStr + "There are too many bad pods. Please check log for details."
...@@ -580,7 +580,7 @@ func hasReplicationControllersForPod(rcs *api.ReplicationControllerList, pod api ...@@ -580,7 +580,7 @@ func hasReplicationControllersForPod(rcs *api.ReplicationControllerList, pod api
// pods have been created. // pods have been created.
func WaitForPodsSuccess(c *client.Client, ns string, successPodLabels map[string]string, timeout time.Duration) error { func WaitForPodsSuccess(c *client.Client, ns string, successPodLabels map[string]string, timeout time.Duration) error {
successPodSelector := labels.SelectorFromSet(successPodLabels) successPodSelector := labels.SelectorFromSet(successPodLabels)
start, badPods := time.Now(), []api.Pod{} start, badPods, desiredPods := time.Now(), []api.Pod{}, 0
if wait.PollImmediate(30*time.Second, timeout, func() (bool, error) { if wait.PollImmediate(30*time.Second, timeout, func() (bool, error) {
podList, err := c.Pods(ns).List(api.ListOptions{LabelSelector: successPodSelector}) podList, err := c.Pods(ns).List(api.ListOptions{LabelSelector: successPodSelector})
...@@ -593,6 +593,7 @@ func WaitForPodsSuccess(c *client.Client, ns string, successPodLabels map[string ...@@ -593,6 +593,7 @@ func WaitForPodsSuccess(c *client.Client, ns string, successPodLabels map[string
return true, nil return true, nil
} }
badPods = []api.Pod{} badPods = []api.Pod{}
desiredPods = len(podList.Items)
for _, pod := range podList.Items { for _, pod := range podList.Items {
if pod.Status.Phase != api.PodSucceeded { if pod.Status.Phase != api.PodSucceeded {
badPods = append(badPods, pod) badPods = append(badPods, pod)
...@@ -608,7 +609,8 @@ func WaitForPodsSuccess(c *client.Client, ns string, successPodLabels map[string ...@@ -608,7 +609,8 @@ func WaitForPodsSuccess(c *client.Client, ns string, successPodLabels map[string
}) != nil { }) != nil {
logPodStates(badPods) logPodStates(badPods)
LogPodsWithLabels(c, ns, successPodLabels) LogPodsWithLabels(c, ns, successPodLabels)
return fmt.Errorf("Not all pods in namespace %q are successful within %v", ns, timeout) return errors.New(errorBadPodsStates(badPods, desiredPods, ns, "SUCCESS", timeout))
} }
return nil return nil
} }
...@@ -695,7 +697,7 @@ func WaitForPodsRunningReady(c *client.Client, ns string, minPods int32, timeout ...@@ -695,7 +697,7 @@ func WaitForPodsRunningReady(c *client.Client, ns string, minPods int32, timeout
logPodStates(badPods) logPodStates(badPods)
return false, nil return false, nil
}) != nil { }) != nil {
return errors.New(errorBadPodsStates(badPods, desiredPods, ns, timeout)) return errors.New(errorBadPodsStates(badPods, desiredPods, ns, "RUNNING and READY", timeout))
} }
wg.Wait() wg.Wait()
if waitForSuccessError != nil { if waitForSuccessError != nil {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment