diff --git a/pkg/agent/apiserver/handlers/podinterface/handler.go b/pkg/agent/apiserver/handlers/podinterface/handler.go index f8f58073661..914143b6a85 100644 --- a/pkg/agent/apiserver/handlers/podinterface/handler.go +++ b/pkg/agent/apiserver/handlers/podinterface/handler.go @@ -30,7 +30,7 @@ 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"` + IPs []string `json:"ips,omitempty"` MAC string `json:"mac,omitempty"` PortUUID string `json:"portUUID,omitempty"` OFPort int32 `json:"ofPort,omitempty"` @@ -42,7 +42,7 @@ func generateResponse(i *interfacestore.InterfaceConfig) 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, @@ -50,12 +50,12 @@ func generateResponse(i *interfacestore.InterfaceConfig) Response { } } -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, @@ -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 { diff --git a/pkg/agent/apiserver/handlers/podinterface/handler_test.go b/pkg/agent/apiserver/handlers/podinterface/handler_test.go index 5c127d93a2e..907beba138b 100644 --- a/pkg/agent/apiserver/handlers/podinterface/handler_test.go +++ b/pkg/agent/apiserver/handlers/podinterface/handler_test.go @@ -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, @@ -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, @@ -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, diff --git a/pkg/antctl/command_definition_test.go b/pkg/antctl/command_definition_test.go index aa7998db248..153951f38ea 100644 --- a/pkg/antctl/command_definition_test.go +++ b/pkg/antctl/command_definition_test.go @@ -241,7 +241,7 @@ GroupName 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, @@ -251,7 +251,7 @@ GroupName 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, diff --git a/test/e2e/basic_test.go b/test/e2e/basic_test.go index b40151ffd05..3fa1afb5057 100644 --- a/test/e2e/basic_test.go +++ b/test/e2e/basic_test.go @@ -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 { @@ -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) @@ -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) @@ -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) + } } }