Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IPv6][e2e] Fix testDeletePod #1193

Merged
merged 1 commit into from
Sep 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jianjuns @tnqn any concern about breaking backward-compatibility for that API? No concern on my side since this is an API which is local to the Agent and AFAIK only consumed by antctl.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is fine.
But maybe we should think about our API versioning strategy sometime.

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