@@ -3569,40 +3569,42 @@ func translatePodNameToUID(c clientset.Interface, ns string, expectedEndpoints p
3569
3569
// validateEndpointsPorts validates that the given service exists and is served by the given expectedEndpoints.
3570
3570
func validateEndpointsPorts (c clientset.Interface , namespace , serviceName string , expectedEndpoints portsByPodName ) error {
3571
3571
ginkgo .By (fmt .Sprintf ("waiting up to %v for service %s in namespace %s to expose endpoints %v" , framework .ServiceStartTimeout , serviceName , namespace , expectedEndpoints ))
3572
- i := 1
3573
- for start := time .Now (); time .Since (start ) < framework .ServiceStartTimeout ; time .Sleep (1 * time .Second ) {
3572
+ expectedPortsByPodUID , err := translatePodNameToUID (c , namespace , expectedEndpoints )
3573
+ if err != nil {
3574
+ return err
3575
+ }
3576
+
3577
+ i := 0
3578
+ if pollErr := wait .PollImmediate (time .Second , framework .ServiceStartTimeout , func () (bool , error ) {
3574
3579
ep , err := c .CoreV1 ().Endpoints (namespace ).Get (context .TODO (), serviceName , metav1.GetOptions {})
3575
3580
if err != nil {
3576
- framework .Logf ("Get endpoints failed (%v elapsed, ignoring for 5s): %v" , time .Since (start ), err )
3577
- continue
3581
+ framework .Logf ("Failed go get Endpoints object: %v" , err )
3582
+ // Retry the error
3583
+ return false , nil
3578
3584
}
3579
3585
portsByPodUID := e2eendpoints .GetContainerPortsByPodUID (ep )
3580
- expectedPortsByPodUID , err := translatePodNameToUID (c , namespace , expectedEndpoints )
3581
- if err != nil {
3582
- return err
3583
- }
3584
- if len (portsByPodUID ) == len (expectedEndpoints ) {
3585
- err := validatePorts (portsByPodUID , expectedPortsByPodUID )
3586
- if err != nil {
3587
- return err
3586
+
3587
+ i ++
3588
+ if err := validatePorts (portsByPodUID , expectedPortsByPodUID ); err != nil {
3589
+ if i % 5 == 0 {
3590
+ framework .Logf ("Unexpected endpoints: found %v, expected %v, will retry" , portsByPodUID , expectedEndpoints )
3588
3591
}
3589
- framework .Logf ("successfully validated that service %s in namespace %s exposes endpoints %v (%v elapsed)" ,
3590
- serviceName , namespace , expectedEndpoints , time .Since (start ))
3591
- return nil
3592
- }
3593
- if i % 5 == 0 {
3594
- framework .Logf ("Unexpected endpoints: found %v, expected %v (%v elapsed, will retry)" , portsByPodUID , expectedEndpoints , time .Since (start ))
3592
+ return false , nil
3595
3593
}
3596
- i ++
3597
- }
3598
- if pods , err := c .CoreV1 ().Pods (metav1 .NamespaceAll ).List (context .TODO (), metav1.ListOptions {}); err == nil {
3599
- for _ , pod := range pods .Items {
3600
- framework .Logf ("Pod %s\t %s\t %s\t %s" , pod .Namespace , pod .Name , pod .Spec .NodeName , pod .DeletionTimestamp )
3594
+ framework .Logf ("successfully validated that service %s in namespace %s exposes endpoints %v" ,
3595
+ serviceName , namespace , expectedEndpoints )
3596
+ return true , nil
3597
+ }); pollErr != nil {
3598
+ if pods , err := c .CoreV1 ().Pods (metav1 .NamespaceAll ).List (context .TODO (), metav1.ListOptions {}); err == nil {
3599
+ for _ , pod := range pods .Items {
3600
+ framework .Logf ("Pod %s\t %s\t %s\t %s" , pod .Namespace , pod .Name , pod .Spec .NodeName , pod .DeletionTimestamp )
3601
+ }
3602
+ } else {
3603
+ framework .Logf ("Can't list pod debug info: %v" , err )
3601
3604
}
3602
- } else {
3603
- framework .Logf ("Can't list pod debug info: %v" , err )
3605
+ return fmt .Errorf ("error waithing for service %s in namespace %s to expose endpoints %v: %v" , serviceName , namespace , expectedEndpoints , pollErr )
3604
3606
}
3605
- return fmt . Errorf ( "Timed out waiting for service %s in namespace %s to expose endpoints %v (%v elapsed)" , serviceName , namespace , expectedEndpoints , framework . ServiceStartTimeout )
3607
+ return nil
3606
3608
}
3607
3609
3608
3610
// restartApiserver restarts the kube-apiserver.
0 commit comments