Skip to content

Commit

Permalink
[IPv6] Support IPv6 in e2e (#1129)
Browse files Browse the repository at this point in the history
  • Loading branch information
lzhecheng authored Aug 28, 2020
1 parent f65dfa2 commit 420d338
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 11 deletions.
8 changes: 7 additions & 1 deletion test/e2e/basic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,13 @@ func TestPodAssignIP(t *testing.T) {
t.Errorf("Error when waiting for Pod IP: %v", err)
} else {
t.Logf("Pod IP is '%s'", podIP)
isValid, err := validatePodIP(clusterInfo.podNetworkCIDR, podIP)
var isValid bool
var err error
if net.ParseIP(podIP).To4() != nil {
isValid, err = validatePodIP(clusterInfo.podV4NetworkCIDR, podIP)
} else {
isValid, err = validatePodIP(clusterInfo.podV6NetworkCIDR, podIP)
}
if err != nil {
t.Errorf("Error when trying to validate Pod IP: %v", err)
} else if !isValid {
Expand Down
10 changes: 8 additions & 2 deletions test/e2e/connectivity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package e2e

import (
"fmt"
"net"
"strings"
"testing"
"time"
Expand All @@ -41,7 +42,7 @@ func waitForPodIPs(t *testing.T, data *TestData, podNames []string) map[string]s
return podIPs
}

// runPingMesh runs a ping mesh between all the provided Pods after first retrieveing their IP
// runPingMesh runs a ping mesh between all the provided Pods after first retrieving their IP
// addresses.
func (data *TestData) runPingMesh(t *testing.T, podNames []string) {
podIPs := waitForPodIPs(t, data, podNames)
Expand Down Expand Up @@ -375,7 +376,12 @@ func TestPingLargeMTU(t *testing.T) {
podIPs := waitForPodIPs(t, data, podNames)

pingSize := 2000
cmd := fmt.Sprintf("ping -c %d -s %d %s", pingCount, pingSize, podIPs[podName1])
var cmd string
if net.ParseIP(podIPs[podName1]).To4() != nil {
cmd = fmt.Sprintf("ping -c %d -s %d %s", pingCount, pingSize, podIPs[podName1])
} else {
cmd = fmt.Sprintf("ping -6 -c %d -s %d %s", pingCount, pingSize, podIPs[podName1])
}
t.Logf("Running ping with size %d between Pods %s and %s", pingSize, podName0, podName1)
stdout, stderr, err := data.runCommandFromPod(testNamespace, podName0, busyboxContainerName, strings.Fields(cmd))
if err != nil {
Expand Down
45 changes: 38 additions & 7 deletions test/e2e/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,12 @@ type ClusterNode struct {
}

type ClusterInfo struct {
numWorkerNodes int
numNodes int
podNetworkCIDR string
masterNodeName string
nodes map[int]ClusterNode
numWorkerNodes int
numNodes int
podV4NetworkCIDR string
podV6NetworkCIDR string
masterNodeName string
nodes map[int]ClusterNode
}

var clusterInfo ClusterInfo
Expand Down Expand Up @@ -204,7 +205,32 @@ func collectClusterInfo() error {
if matches := re.FindStringSubmatch(stdout); len(matches) == 0 {
return fmt.Errorf("cannot retrieve cluster CIDR, unexpected kubectl output: %s", stdout)
} else {
clusterInfo.podNetworkCIDR = matches[1]
cidrs := strings.Split(matches[1], ",")
if len(cidrs) == 1 {
_, cidr, err := net.ParseCIDR(cidrs[0])
if err != nil {
return fmt.Errorf("CIDR cannot be parsed: %s", cidrs[0])
}
if cidr.IP.To4() != nil {
clusterInfo.podV4NetworkCIDR = cidrs[0]
} else {
clusterInfo.podV6NetworkCIDR = cidrs[0]
}
} else if len(cidrs) == 2 {
_, cidr, err := net.ParseCIDR(cidrs[0])
if err != nil {
return fmt.Errorf("CIDR cannot be parsed: %s", cidrs[0])
}
if cidr.IP.To4() != nil {
clusterInfo.podV4NetworkCIDR = cidrs[0]
clusterInfo.podV6NetworkCIDR = cidrs[1]
} else {
clusterInfo.podV4NetworkCIDR = cidrs[1]
clusterInfo.podV6NetworkCIDR = cidrs[0]
}
} else {
return fmt.Errorf("unexpected cluster CIDR: %s", matches[1])
}
}
return nil
}(); err != nil {
Expand Down Expand Up @@ -1025,7 +1051,12 @@ func parseArpingStdout(out string) (sent uint32, received uint32, loss float32,
}

func (data *TestData) runPingCommandFromTestPod(podName string, targetIP string, count int) error {
cmd := []string{"ping", "-c", strconv.Itoa(count), targetIP}
var cmd []string
if net.ParseIP(targetIP).To4() != nil {
cmd = []string{"ping", "-c", strconv.Itoa(count), targetIP}
} else {
cmd = []string{"ping", "-6", "-c", strconv.Itoa(count), targetIP}
}
_, _, err := data.runCommandFromPod(testNamespace, podName, busyboxContainerName, cmd)
return err
}
Expand Down
7 changes: 6 additions & 1 deletion test/e2e/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,12 @@ func testMain(m *testing.M) int {
if err := collectClusterInfo(); err != nil {
log.Fatalf("Error when collecting information about K8s cluster: %v", err)
} else {
log.Printf("Pod network: '%s'", clusterInfo.podNetworkCIDR)
if clusterInfo.podV4NetworkCIDR != "" {
log.Printf("Pod IPv4 network: '%s'", clusterInfo.podV4NetworkCIDR)
}
if clusterInfo.podV6NetworkCIDR != "" {
log.Printf("Pod IPv6 network: '%s'", clusterInfo.podV6NetworkCIDR)
}
log.Printf("Num nodes: %d", clusterInfo.numNodes)
}

Expand Down

0 comments on commit 420d338

Please sign in to comment.