Skip to content
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
5 changes: 3 additions & 2 deletions pkg/network/node/egressip.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,9 @@ func (eip *egressIPWatcher) deleteNamespaceEgress(vnid uint32) {

if ns.assignedIP != "" {
ns.requestedIP = ""
eip.deleteEgressIP(ns.assignedIP)
delete(eip.namespacesByEgressIP, ns.assignedIP)
egressIP := ns.assignedIP
eip.deleteEgressIP(egressIP)
delete(eip.namespacesByEgressIP, egressIP)
}
delete(eip.namespacesByVNID, vnid)
}
Expand Down
54 changes: 54 additions & 0 deletions pkg/network/node/egressip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ func TestEgressIP(t *testing.T) {
eip.deleteNamespaceEgress(42)
eip.deleteNamespaceEgress(43)

if len(eip.nodesByNodeIP) != 0 || len(eip.nodesByEgressIP) != 0 || len(eip.namespacesByVNID) != 0 || len(eip.namespacesByEgressIP) != 0 {
t.Fatalf("Unexpected eip state: %#v", eip)
}

// No namespaces use egress yet, so should be no changes
err := assertNoNetlinkChanges(eip)
if err != nil {
Expand Down Expand Up @@ -74,6 +78,11 @@ func TestEgressIP(t *testing.T) {
t.Fatalf("Unexpected flow changes: %v", err)
}

ns42 := eip.namespacesByVNID[42]
if ns42 == nil || eip.namespacesByEgressIP["172.17.0.100"] != ns42 || eip.nodesByEgressIP["172.17.0.100"] != nil {
t.Fatalf("Unexpected eip state: %#v", eip)
}

eip.updateNodeEgress("172.17.0.3", []string{"172.17.0.100"})
err = assertNoNetlinkChanges(eip)
if err != nil {
Expand All @@ -94,6 +103,11 @@ func TestEgressIP(t *testing.T) {
}
origFlows = flows

node3 := eip.nodesByNodeIP["172.17.0.3"]
if node3 == nil || eip.namespacesByEgressIP["172.17.0.100"] != ns42 || eip.nodesByEgressIP["172.17.0.100"] != node3 {
t.Fatalf("Unexpected eip state: %#v", eip)
}

// Assign HostSubnet.EgressIP first, then NetNamespace.EgressIP, with a remote EgressIP
eip.updateNodeEgress("172.17.0.3", []string{"172.17.0.101", "172.17.0.100"})
err = assertNoNetlinkChanges(eip)
Expand All @@ -109,6 +123,10 @@ func TestEgressIP(t *testing.T) {
t.Fatalf("Unexpected flow changes: %v", err)
}

if eip.nodesByEgressIP["172.17.0.100"] != node3 || eip.nodesByEgressIP["172.17.0.101"] != node3 {
t.Fatalf("Unexpected eip state: %#v", eip)
}

eip.updateNamespaceEgress(43, "172.17.0.101")
err = assertNoNetlinkChanges(eip)
if err != nil {
Expand All @@ -129,6 +147,11 @@ func TestEgressIP(t *testing.T) {
}
origFlows = flows

ns43 := eip.namespacesByVNID[43]
if ns43 == nil || eip.namespacesByEgressIP["172.17.0.101"] != ns43 || eip.nodesByEgressIP["172.17.0.101"] != node3 {
t.Fatalf("Unexpected eip state: %#v", eip)
}

// Assign NetNamespace.EgressIP first, then HostSubnet.EgressIP, with a local EgressIP
eip.updateNamespaceEgress(44, "172.17.0.102")
err = assertNoNetlinkChanges(eip)
Expand All @@ -149,6 +172,11 @@ func TestEgressIP(t *testing.T) {
t.Fatalf("Unexpected flow changes: %v", err)
}

ns44 := eip.namespacesByVNID[44]
if ns44 == nil || eip.namespacesByEgressIP["172.17.0.102"] != ns44 || eip.nodesByEgressIP["172.17.0.102"] != nil {
t.Fatalf("Unexpected eip state: %#v", eip)
}

eip.updateNodeEgress("172.17.0.4", []string{"172.17.0.102"})
err = assertNetlinkChange(eip, "claim 172.17.0.102")
if err != nil {
Expand All @@ -169,6 +197,11 @@ func TestEgressIP(t *testing.T) {
}
origFlows = flows

node4 := eip.nodesByNodeIP["172.17.0.4"]
if node4 == nil || eip.nodesByEgressIP["172.17.0.102"] != node4 {
t.Fatalf("Unexpected eip state: %#v", eip)
}

// Assign HostSubnet.EgressIP first, then NetNamespace.EgressIP, with a local EgressIP
eip.updateNodeEgress("172.17.0.4", []string{"172.17.0.102", "172.17.0.103"})
err = assertNoNetlinkChanges(eip)
Expand All @@ -184,6 +217,10 @@ func TestEgressIP(t *testing.T) {
t.Fatalf("Unexpected flow changes: %v", err)
}

if eip.nodesByEgressIP["172.17.0.102"] != node4 || eip.nodesByEgressIP["172.17.0.103"] != node4 {
t.Fatalf("Unexpected eip state: %#v", eip)
}

eip.updateNamespaceEgress(45, "172.17.0.103")
err = assertNetlinkChange(eip, "claim 172.17.0.103")
if err != nil {
Expand All @@ -204,6 +241,11 @@ func TestEgressIP(t *testing.T) {
}
origFlows = flows

ns45 := eip.namespacesByVNID[45]
if ns45 == nil || eip.namespacesByEgressIP["172.17.0.103"] != ns45 || eip.nodesByEgressIP["172.17.0.103"] != node4 {
t.Fatalf("Unexpected eip state: %#v", eip)
}

// Drop namespace EgressIP
eip.deleteNamespaceEgress(44)
err = assertNetlinkChange(eip, "release 172.17.0.102")
Expand All @@ -225,6 +267,10 @@ func TestEgressIP(t *testing.T) {
}
origFlows = flows

if eip.namespacesByVNID[44] != nil || eip.namespacesByEgressIP["172.17.0.102"] != nil || eip.nodesByEgressIP["172.17.0.102"] != node4 {
t.Fatalf("Unexpected eip state: %#v", eip)
}

// Drop remote node EgressIP
eip.updateNodeEgress("172.17.0.3", []string{"172.17.0.100"})
err = assertNoNetlinkChanges(eip)
Expand All @@ -250,6 +296,10 @@ func TestEgressIP(t *testing.T) {
}
origFlows = flows

if eip.namespacesByVNID[43] != ns43 || eip.namespacesByEgressIP["172.17.0.101"] != ns43 || eip.nodesByEgressIP["172.17.0.101"] != nil {
t.Fatalf("Unexpected eip state: %#v", eip)
}

// Drop local node EgressIP
eip.updateNodeEgress("172.17.0.4", []string{"172.17.0.102"})
err = assertNetlinkChange(eip, "release 172.17.0.103")
Expand All @@ -275,6 +325,10 @@ func TestEgressIP(t *testing.T) {
}
origFlows = flows

if eip.namespacesByVNID[45] != ns45 || eip.namespacesByEgressIP["172.17.0.103"] != ns45 || eip.nodesByEgressIP["172.17.0.103"] != nil {
t.Fatalf("Unexpected eip state: %#v", eip)
}

// Trying to assign node IP as egress IP should fail. (It will log an error but this test doesn't notice that.)
eip.updateNodeEgress("172.17.0.4", []string{"172.17.0.4", "172.17.0.102"})
err = assertNoNetlinkChanges(eip)
Expand Down