test/e2e: handle ipv6 addresses in netpol tests

The tests, as written, don't correctly join ip and port for v6
addresses.

use net.JoinHostPort to handle this case.
This commit is contained in:
Casey Callendrello 2021-03-30 16:41:06 +02:00
parent b6ff1370bd
commit 1efd456bcf

View File

@ -19,6 +19,8 @@ package netpol
import ( import (
"context" "context"
"fmt" "fmt"
"net"
"strconv"
"strings" "strings"
"time" "time"
@ -109,14 +111,15 @@ func (k *kubeManager) getPod(ns string, name string) (*v1.Pod, error) {
// probeConnectivity execs into a pod and checks its connectivity to another pod.. // probeConnectivity execs into a pod and checks its connectivity to another pod..
func (k *kubeManager) probeConnectivity(nsFrom string, podFrom string, containerFrom string, addrTo string, protocol v1.Protocol, toPort int) (bool, string, error) { func (k *kubeManager) probeConnectivity(nsFrom string, podFrom string, containerFrom string, addrTo string, protocol v1.Protocol, toPort int) (bool, string, error) {
port := strconv.Itoa(toPort)
var cmd []string var cmd []string
switch protocol { switch protocol {
case v1.ProtocolSCTP: case v1.ProtocolSCTP:
cmd = []string{"/agnhost", "connect", fmt.Sprintf("%s:%d", addrTo, toPort), "--timeout=1s", "--protocol=sctp"} cmd = []string{"/agnhost", "connect", net.JoinHostPort(addrTo, port), "--timeout=1s", "--protocol=sctp"}
case v1.ProtocolTCP: case v1.ProtocolTCP:
cmd = []string{"/agnhost", "connect", fmt.Sprintf("%s:%d", addrTo, toPort), "--timeout=1s", "--protocol=tcp"} cmd = []string{"/agnhost", "connect", net.JoinHostPort(addrTo, port), "--timeout=1s", "--protocol=tcp"}
case v1.ProtocolUDP: case v1.ProtocolUDP:
cmd = []string{"/agnhost", "connect", fmt.Sprintf("%s:%d", addrTo, toPort), "--timeout=1s", "--protocol=udp"} cmd = []string{"/agnhost", "connect", net.JoinHostPort(addrTo, port), "--timeout=1s", "--protocol=udp"}
default: default:
framework.Failf("protocol %s not supported", protocol) framework.Failf("protocol %s not supported", protocol)
} }