Skip to content

Commit

Permalink
[IPv6][e2e] Fix testDeletePod (#1193)
Browse files Browse the repository at this point in the history
On a dual-stack cluster, podInterfaces[0].IP returns "[ipv4-address], [ipv6-address]".
Current implementation doesn't distingush two.
  • Loading branch information
lzhecheng authored and wenyingd committed Sep 7, 2020
1 parent 19f2a23 commit a979177
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 25 deletions.
26 changes: 13 additions & 13 deletions pkg/agent/apiserver/handlers/podinterface/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,35 +27,35 @@ import (

// Response describes the response struct of pod-interface command.
type Response struct {
PodName string `json:"name,omitempty" antctl:"name,Name of the Pod"`
PodNamespace string `json:"podNamespace,omitempty"`
InterfaceName string `json:"interfaceName,omitempty"`
IP string `json:"ip,omitempty"`
MAC string `json:"mac,omitempty"`
PortUUID string `json:"portUUID,omitempty"`
OFPort int32 `json:"ofPort,omitempty"`
ContainerID string `json:"containerID,omitempty"`
PodName string `json:"name,omitempty" antctl:"name,Name of the Pod"`
PodNamespace string `json:"podNamespace,omitempty"`
InterfaceName string `json:"interfaceName,omitempty"`
IPs []string `json:"ips,omitempty"`
MAC string `json:"mac,omitempty"`
PortUUID string `json:"portUUID,omitempty"`
OFPort int32 `json:"ofPort,omitempty"`
ContainerID string `json:"containerID,omitempty"`
}

func generateResponse(i *interfacestore.InterfaceConfig) Response {
return Response{
PodName: i.ContainerInterfaceConfig.PodName,
PodNamespace: i.ContainerInterfaceConfig.PodNamespace,
InterfaceName: i.InterfaceName,
IP: getPodIPsStr(i.IPs),
IPs: getPodIPs(i.IPs),
MAC: i.MAC.String(),
PortUUID: i.OVSPortConfig.PortUUID,
OFPort: i.OVSPortConfig.OFPort,
ContainerID: i.ContainerInterfaceConfig.ContainerID,
}
}

func getPodIPsStr(ips []net.IP) string {
func getPodIPs(ips []net.IP) []string {
ipStrs := make([]string, len(ips))
for i := range ips {
ipStrs[i] = ips[i].String()
}
return strings.Join(ipStrs, ", ")
return ipStrs
}

// HandleFunc returns the function which can handle queries issued by the pod-interface command,
Expand Down Expand Up @@ -97,8 +97,8 @@ func (r Response) GetContainerIDStr() string {
return r.ContainerID
}

func (r Response) GetTableRow(maxColumnLength int) []string {
return []string{r.PodNamespace, r.PodName, r.InterfaceName, r.IP, r.MAC, r.PortUUID, common.Int32ToString(r.OFPort), r.GetContainerIDStr()}
func (r Response) GetTableRow(_ int) []string {
return []string{r.PodNamespace, r.PodName, r.InterfaceName, strings.Join(r.IPs, ", "), r.MAC, r.PortUUID, common.Int32ToString(r.OFPort), r.GetContainerIDStr()}
}

func (r Response) SortRows() bool {
Expand Down
6 changes: 3 additions & 3 deletions pkg/agent/apiserver/handlers/podinterface/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ var responses = []Response{
PodName: podNames[0],
PodNamespace: "namespaceA",
InterfaceName: "interface0",
IP: ipStrs[0],
IPs: []string{ipStrs[0]},
MAC: macStrs[0],
PortUUID: "portuuid0",
OFPort: 0,
Expand All @@ -70,7 +70,7 @@ var responses = []Response{
PodName: podNames[1],
PodNamespace: "namespaceA",
InterfaceName: "interface1",
IP: ipStrs[1],
IPs: []string{ipStrs[1]},
MAC: macStrs[1],
PortUUID: "portuuid1",
OFPort: 1,
Expand All @@ -80,7 +80,7 @@ var responses = []Response{
PodName: podNames[0],
PodNamespace: "namespaceB",
InterfaceName: "interface2",
IP: ipStrs[2],
IPs: []string{ipStrs[2]},
MAC: macStrs[2],
PortUUID: "portuuid2",
OFPort: 2,
Expand Down
2 changes: 1 addition & 1 deletion pkg/agent/controller/networkpolicy/reconciler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ func TestReconcilerUpdate(t *testing.T) {
ifaceStore.AddInterface(
&interfacestore.InterfaceConfig{
InterfaceName: util.GenerateContainerInterfaceName("pod3", "ns1", "container3"),
IP: net.ParseIP("4.4.4.4"),
IPs: []net.IP{net.ParseIP("4.4.4.4")},
ContainerInterfaceConfig: &interfacestore.ContainerInterfaceConfig{PodName: "pod3", PodNamespace: "ns1", ContainerID: "container3"},
OVSPortConfig: &interfacestore.OVSPortConfig{OFPort: 3}})
tests := []struct {
Expand Down
4 changes: 2 additions & 2 deletions pkg/antctl/command_definition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ GroupName <NONE>
PodName: "nginx-6db489d4b7-vgv7v",
PodNamespace: "default",
InterfaceName: "Interface",
IP: "127.0.0.1",
IPs: []string{"127.0.0.1"},
MAC: "07-16-76-00-02-86",
PortUUID: "portuuid0",
OFPort: 80,
Expand All @@ -251,7 +251,7 @@ GroupName <NONE>
PodName: "nginx-32b489d4b7-vgv7v",
PodNamespace: "default",
InterfaceName: "Interface2",
IP: "127.0.0.2",
IPs: []string{"127.0.0.2"},
MAC: "07-16-76-00-02-87",
PortUUID: "portuuid1",
OFPort: 35572,
Expand Down
16 changes: 10 additions & 6 deletions test/e2e/basic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func (data *TestData) testDeletePod(t *testing.T, podName string, nodeName strin
t.Fatalf("Expected 1 pod interface, got %d", len(podInterfaces))
}
ifName := podInterfaces[0].InterfaceName
podIP := podInterfaces[0].IP
podIPs := podInterfaces[0].IPs
t.Logf("Host interface name for Pod is '%s'", ifName)

doesInterfaceExist := func() bool {
Expand All @@ -122,7 +122,7 @@ func (data *TestData) testDeletePod(t *testing.T, podName string, nodeName strin
return exists
}

doesIPAllocationExist := func() bool {
doesIPAllocationExist := func(podIP string) bool {
cmd := fmt.Sprintf("test -f /var/run/antrea/cni/networks/antrea/%s", podIP)
if rc, _, _, err := RunCommandOnNode(nodeName, cmd); err != nil {
t.Fatalf("Error when running ip command on Node '%s': %v", nodeName, err)
Expand All @@ -139,8 +139,10 @@ func (data *TestData) testDeletePod(t *testing.T, podName string, nodeName strin
if !doesOVSPortExist() {
t.Errorf("OVS port '%s' does not exist on Node '%s'", ifName, nodeName)
}
if !doesIPAllocationExist() {
t.Errorf("IP allocation '%s' does not exist on Node '%s'", podIP, nodeName)
for _, podIP := range podIPs {
if !doesIPAllocationExist(podIP) {
t.Errorf("IP allocation '%s' does not exist on Node '%s'", podIP, nodeName)
}
}

t.Logf("Deleting Pod '%s'", podName)
Expand All @@ -155,8 +157,10 @@ func (data *TestData) testDeletePod(t *testing.T, podName string, nodeName strin
if doesOVSPortExist() {
t.Errorf("OVS port '%s' still exists on Node '%s' after Pod deletion", ifName, nodeName)
}
if doesIPAllocationExist() {
t.Errorf("IP allocation '%s' still exists on Node '%s'", podIP, nodeName)
for _, podIP := range podIPs {
if doesIPAllocationExist(podIP) {
t.Errorf("IP allocation '%s' still exists on Node '%s'", podIP, nodeName)
}
}
}

Expand Down

0 comments on commit a979177

Please sign in to comment.