From 4650a3e83c4c45c06c7a5492ac40c5b1baaf6793 Mon Sep 17 00:00:00 2001 From: Predrag Rogic Date: Wed, 8 Mar 2023 20:56:44 +0000 Subject: [PATCH] wait for pods to get IPs --- test/integration/multinode_test.go | 33 +++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/test/integration/multinode_test.go b/test/integration/multinode_test.go index df9793a5cc..679b5027c2 100644 --- a/test/integration/multinode_test.go +++ b/test/integration/multinode_test.go @@ -28,9 +28,11 @@ import ( "path/filepath" "strings" "testing" + "time" "k8s.io/minikube/cmd/minikube/cmd" "k8s.io/minikube/pkg/minikube/config" + "k8s.io/minikube/pkg/util/retry" ) // TestMultiNode tests all multi node cluster functionality @@ -487,20 +489,31 @@ func validateDeployAppToMultiNode(ctx context.Context, t *testing.T, profile str } // resolve Pod IPs - rr, err := Run(t, exec.CommandContext(ctx, Target(), "kubectl", "-p", profile, "--", "get", "pods", "-o", "jsonpath='{.items[*].status.podIP}'")) - if err != nil { - t.Errorf("failed to retrieve Pod IPs") + resolvePodIPs := func() error { + rr, err := Run(t, exec.CommandContext(ctx, Target(), "kubectl", "-p", profile, "--", "get", "pods", "-o", "jsonpath='{.items[*].status.podIP}'")) + if err != nil { + err := fmt.Errorf("failed to retrieve Pod IPs (may be temporary): %v", err) + t.Logf(err.Error()) + return err + } + podIPs := strings.Split(strings.Trim(rr.Stdout.String(), "'"), " ") + if len(podIPs) != 2 { + err := fmt.Errorf("expected 2 Pod IPs but got %d (may be temporary), output: %q", len(podIPs), rr.Output()) + t.Logf(err.Error()) + return err + } else if podIPs[0] == podIPs[1] { + err := fmt.Errorf("expected 2 different pod IPs but got %s and %s (may be temporary), output: %q", podIPs[0], podIPs[1], rr.Output()) + t.Logf(err.Error()) + return err + } + return nil } - podIPs := strings.Split(strings.Trim(rr.Stdout.String(), "'"), " ") - if len(podIPs) != 2 { - t.Errorf("expected 2 Pod IPs but got %d, output: %q", len(podIPs), rr.Output()) - } else if podIPs[0] == podIPs[1] { - t.Errorf("expected 2 different pod IPs but got %s and %s. output: %q", podIPs[0], podIPs[1], rr.Output()) - + if err := retry.Expo(resolvePodIPs, 1*time.Second, Seconds(120)); err != nil { + t.Errorf("failed to resolve pod IPs: %v", err) } // get Pod names - rr, err = Run(t, exec.CommandContext(ctx, Target(), "kubectl", "-p", profile, "--", "get", "pods", "-o", "jsonpath='{.items[*].metadata.name}'")) + rr, err := Run(t, exec.CommandContext(ctx, Target(), "kubectl", "-p", profile, "--", "get", "pods", "-o", "jsonpath='{.items[*].metadata.name}'")) if err != nil { t.Errorf("failed get Pod names") }