@@ -489,17 +489,89 @@ func restartTerway(ctx context.Context, config *envconf.Config) error {
489489}
490490
491491func waitPodsReady (client klient.Client , pods ... * corev1.Pod ) error {
492+ timeout := 2 * time .Minute
492493 for _ , pod := range pods {
494+ startTime := time .Now ()
493495 err := wait .For (conditions .New (client .Resources ()).PodReady (pod ),
494- wait .WithTimeout (2 * time . Minute ),
496+ wait .WithTimeout (timeout ),
495497 wait .WithInterval (1 * time .Second ))
496498 if err != nil {
497- return fmt .Errorf ("wait pod %s/%s ready failed: %w" , pod .Namespace , pod .Name , err )
499+ waitDuration := time .Since (startTime )
500+ return fmt .Errorf ("wait pod %s/%s ready failed after %v (timeout: %v): %w\n %s" ,
501+ pod .Namespace , pod .Name , waitDuration .Round (time .Second ), timeout , err , getPodStatusDetails (client , pod ))
498502 }
499503 }
500504 return nil
501505}
502506
507+ func getPodStatusDetails (client klient.Client , pod * corev1.Pod ) string {
508+ var sb strings.Builder
509+ sb .WriteString ("--- Pod Status Details ---\n " )
510+
511+ // fetch the latest pod status
512+ latestPod := & corev1.Pod {}
513+ err := client .Resources ().Get (context .Background (), pod .Name , pod .Namespace , latestPod )
514+ if err != nil {
515+ sb .WriteString (fmt .Sprintf ("failed to get pod status: %v\n " , err ))
516+ return sb .String ()
517+ }
518+
519+ sb .WriteString (fmt .Sprintf ("Phase: %s\n " , latestPod .Status .Phase ))
520+ if latestPod .Status .Reason != "" {
521+ sb .WriteString (fmt .Sprintf ("Reason: %s\n " , latestPod .Status .Reason ))
522+ }
523+ if latestPod .Status .Message != "" {
524+ sb .WriteString (fmt .Sprintf ("Message: %s\n " , latestPod .Status .Message ))
525+ }
526+
527+ // show pod conditions
528+ if len (latestPod .Status .Conditions ) > 0 {
529+ sb .WriteString ("Conditions:\n " )
530+ for _ , cond := range latestPod .Status .Conditions {
531+ sb .WriteString (fmt .Sprintf (" - Type: %s, Status: %s" , cond .Type , cond .Status ))
532+ if cond .Reason != "" {
533+ sb .WriteString (fmt .Sprintf (", Reason: %s" , cond .Reason ))
534+ }
535+ if cond .Message != "" {
536+ sb .WriteString (fmt .Sprintf (", Message: %s" , cond .Message ))
537+ }
538+ sb .WriteString ("\n " )
539+ }
540+ }
541+
542+ // show container statuses
543+ for _ , cs := range latestPod .Status .ContainerStatuses {
544+ sb .WriteString (fmt .Sprintf ("Container %s: Ready=%v" , cs .Name , cs .Ready ))
545+ if cs .State .Waiting != nil {
546+ sb .WriteString (fmt .Sprintf (", Waiting: %s - %s" , cs .State .Waiting .Reason , cs .State .Waiting .Message ))
547+ }
548+ if cs .State .Terminated != nil {
549+ sb .WriteString (fmt .Sprintf (", Terminated: %s - %s (ExitCode: %d)" , cs .State .Terminated .Reason , cs .State .Terminated .Message , cs .State .Terminated .ExitCode ))
550+ }
551+ sb .WriteString ("\n " )
552+ }
553+
554+ // fetch and show recent events for the pod
555+ eventList := & corev1.EventList {}
556+ err = client .Resources (pod .Namespace ).List (context .Background (), eventList )
557+ if err == nil {
558+ var podEvents []corev1.Event
559+ for _ , event := range eventList .Items {
560+ if event .InvolvedObject .Name == pod .Name && event .InvolvedObject .Kind == "Pod" {
561+ podEvents = append (podEvents , event )
562+ }
563+ }
564+ if len (podEvents ) > 0 {
565+ sb .WriteString ("Recent Events:\n " )
566+ for _ , event := range podEvents {
567+ sb .WriteString (fmt .Sprintf (" - [%s] %s: %s\n " , event .Type , event .Reason , event .Message ))
568+ }
569+ }
570+ }
571+
572+ return sb .String ()
573+ }
574+
503575type PodNetworking struct {
504576 * networkv1beta1.PodNetworking
505577}
0 commit comments