Merge pull request #100676 from squeed/netpol-v6-test

test/e2e: handle ipv6 addresses in netpol tests
This commit is contained in:
Kubernetes Prow Robot 2021-04-09 05:19:53 -07:00 committed by GitHub
commit fded3d71e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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