Merge pull request #16001 from prezha/fix-TestMultiNode-deploy-wait

wait for pods to get IPs
pull/16131/head
Medya Ghazizadeh 2023-03-22 11:17:06 -07:00 committed by GitHub
commit c025dfc9b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 23 additions and 10 deletions

View File

@ -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")
}