diff --git a/connectivity/tests/host.go b/connectivity/tests/host.go index 1ba2ec9ab7..d6cbce141c 100644 --- a/connectivity/tests/host.go +++ b/connectivity/tests/host.go @@ -35,33 +35,28 @@ func (s *podToHost) Run(ctx context.Context, t *check.Test) { for _, node := range ct.Nodes() { node := node - var ipFamStr string - t.ForEachIPFamily(func(ipFam check.IPFamily) { - if ipFam == check.IPFamilyV4 { - ipFamStr = "v4" - } else if ipFam == check.IPFamilyV6 { - ipFamStr = "v6" - } - + dstAddrs := []string{} for _, addr := range node.Status.Addresses { if check.GetIPFamily(addr.Address) != ipFam { continue } + dstAddrs = append(dstAddrs, addr.Address) + } + if len(dstAddrs) == 0 { + return + } - dst := check.ICMPEndpoint("", addr.Address) - ipFam := check.GetIPFamily(addr.Address) - - t.NewAction(s, fmt.Sprintf("ping-%s-%d", ipFamStr, i), &pod, dst, ipFam).Run(func(a *check.Action) { - a.ExecInPod(ctx, ct.PingCommand(dst, ipFam)) + dst := check.ICMPEndpoint("", addr.Address) + t.NewAction(s, fmt.Sprintf("ping-%s-%d", ipFam, i), &pod, dst, ipFam).Run(func(a *check.Action) { + a.ExecInPod(ctx, ct.PingCommand(dst, ipFam)) - a.ValidateFlows(ctx, pod, a.GetEgressRequirements(check.FlowParameters{ - Protocol: check.ICMP, - })) - }) + a.ValidateFlows(ctx, pod, a.GetEgressRequirements(check.FlowParameters{ + Protocol: check.ICMP, + })) + }) - i++ - } + i++ }) } } @@ -96,31 +91,21 @@ func (s *podToHostPort) Run(ctx context.Context, t *check.Test) { for _, echo := range ct.EchoPods() { echo := echo // copy to avoid memory aliasing when using reference - var ipFamStr string - - t.ForEachIPFamily(func(ipFam check.IPFamily) { - if ipFam == check.IPFamilyV4 { - ipFamStr = "v4" - } else if ipFam == check.IPFamilyV6 { - ipFamStr = "v6" - } - - baseURL := fmt.Sprintf("%s://%s:%d%s", echo.Scheme(), echo.Pod.Status.HostIP, check.EchoServerHostPort, echo.Path()) - ep := check.HTTPEndpoint(echo.Name(), baseURL) - t.NewAction(s, fmt.Sprintf("curl-%s-%d", ipFamStr, i), &client, ep, check.IPFamilyAny).Run(func(a *check.Action) { - a.ExecInPod(ctx, ct.CurlCommand(ep, check.IPFamilyAny)) - - a.ValidateFlows(ctx, client, a.GetEgressRequirements(check.FlowParameters{ - // Because the HostPort request is NATed, we might only - // observe flows after DNAT has been applied (e.g. by - // HostReachableServices), - AltDstIP: echo.Address(check.IPFamilyAny), - AltDstPort: echo.Port(), - })) - }) - - i++ + baseURL := fmt.Sprintf("%s://%s:%d%s", echo.Scheme(), echo.Pod.Status.HostIP, check.EchoServerHostPort, echo.Path()) + ep := check.HTTPEndpoint(echo.Name(), baseURL) + t.NewAction(s, fmt.Sprintf("curl-%d", i), &client, ep, check.IPFamilyAny).Run(func(a *check.Action) { + a.ExecInPod(ctx, ct.CurlCommand(ep, check.IPFamilyAny)) + + a.ValidateFlows(ctx, client, a.GetEgressRequirements(check.FlowParameters{ + // Because the HostPort request is NATed, we might only + // observe flows after DNAT has been applied (e.g. by + // HostReachableServices), + AltDstIP: echo.Address(check.IPFamilyAny), + AltDstPort: echo.Port(), + })) }) + + i++ } } } diff --git a/connectivity/tests/pod.go b/connectivity/tests/pod.go index 17b39c29df..00258eebde 100644 --- a/connectivity/tests/pod.go +++ b/connectivity/tests/pod.go @@ -50,7 +50,8 @@ func (s *podToPod) Run(ctx context.Context, t *check.Test) { continue } t.ForEachIPFamily(func(ipFam check.IPFamily) { - t.NewAction(s, fmt.Sprintf("curl-%d", i), &client, echo, ipFam).Run(func(a *check.Action) { + actionDesc := fmt.Sprintf("curl-%s-%d", ipFam.String(), i) + t.NewAction(s, actionDesc, &client, echo, ipFam).Run(func(a *check.Action) { if s.method == "" { a.ExecInPod(ctx, ct.CurlCommand(echo, ipFam)) } else { diff --git a/connectivity/tests/service.go b/connectivity/tests/service.go index 56441ea492..e8edad45d0 100644 --- a/connectivity/tests/service.go +++ b/connectivity/tests/service.go @@ -49,7 +49,9 @@ func (s *podToService) Run(ctx context.Context, t *check.Test) { continue } - t.NewAction(s, fmt.Sprintf("curl-%d", i), &pod, svc, check.IPFamilyAny).Run(func(a *check.Action) { + actionDesc := fmt.Sprintf("curl-%s-%d", check.IPFamilyAny, i) + + t.NewAction(s, actionDesc, &pod, svc, check.IPFamilyAny).Run(func(a *check.Action) { a.ExecInPod(ctx, ct.CurlCommand(svc, check.IPFamilyAny)) a.ValidateFlows(ctx, pod, a.GetEgressRequirements(check.FlowParameters{