Skip to content

Commit

Permalink
[IPv6] Support IPv6 in e2e
Browse files Browse the repository at this point in the history
  • Loading branch information
lzhecheng committed Aug 21, 2020
1 parent d14389c commit 97719a3
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 8 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.IP(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
31 changes: 25 additions & 6 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,25 @@ 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 {
if net.IP(matches[1]).To4() != nil {
clusterInfo.podV4NetworkCIDR = matches[1]
} else {
clusterInfo.podV6NetworkCIDR = matches[1]
}
} else if len(CIDRs) == 2 {
IP := net.IP(CIDRs[0])
if 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
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 97719a3

Please sign in to comment.