Skip to content

Commit

Permalink
Clean up internal data when egress IPs go away
Browse files Browse the repository at this point in the history
  • Loading branch information
danwinship committed Aug 1, 2018
1 parent ba75085 commit 9132d51
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions pkg/network/common/egressip.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ func (eit *EgressIPTracker) UpdateHostSubnetEgress(hs *networkapi.HostSubnet) {
movedEgressIPs := make([]string, 0, node.requestedIPs.Len())
for _, ip := range node.requestedIPs.UnsortedList() {
eg := eit.egressIPs[ip]
if eg.assignedNodeIP == node.nodeIP {
if eg != nil && eg.assignedNodeIP == node.nodeIP {
movedEgressIPs = append(movedEgressIPs, ip)
eit.deleteNodeEgressIP(node, ip)
}
Expand Down Expand Up @@ -308,7 +308,9 @@ func (eit *EgressIPTracker) UpdateNetNamespaceEgress(netns *networkapi.NetNamesp
// Even IPs that weren't added/removed need to be considered "changed", to
// ensure we correctly process reorderings, duplicates added/removed, etc.
for _, ip := range newRequestedIPs.Intersection(oldRequestedIPs).UnsortedList() {
eit.egressIPChanged(eit.egressIPs[ip])
if eg := eit.egressIPs[ip]; eg != nil {
eit.egressIPChanged(eg)
}
}

eit.syncEgressIPs()
Expand All @@ -332,7 +334,7 @@ func (eit *EgressIPTracker) egressIPActive(eg *egressIPInfo) (bool, error) {
}
for _, ip := range eg.namespaces[0].requestedIPs {
eg2 := eit.egressIPs[ip]
if eg2 != eg && len(eg2.nodes) == 1 && eg2.nodes[0] == eg.nodes[0] {
if eg2 != nil && eg2 != eg && len(eg2.nodes) == 1 && eg2.nodes[0] == eg.nodes[0] {
return false, fmt.Errorf("Multiple EgressIPs (%s, %s) for VNID %d on node %s", eg.ip, eg2.ip, eg.namespaces[0].vnid, eg.nodes[0].nodeIP)
}
}
Expand All @@ -358,6 +360,12 @@ func (eit *EgressIPTracker) syncEgressIPs() {
eit.syncEgressNamespaceState(ns)
}

for eg := range changedEgressIPs {
if len(eg.namespaces) == 0 && len(eg.nodes) == 0 {
delete(eit.egressIPs, eg.ip)
}
}

if eit.updateEgressCIDRs {
eit.updateEgressCIDRs = false
if eit.nodesWithCIDRs > 0 {
Expand Down

0 comments on commit 9132d51

Please sign in to comment.