@@ -230,7 +230,7 @@ func (eit *EgressIPTracker) UpdateHostSubnetEgress(hs *networkapi.HostSubnet) {
230230 movedEgressIPs := make ([]string , 0 , node .requestedIPs .Len ())
231231 for _ , ip := range node .requestedIPs .UnsortedList () {
232232 eg := eit .egressIPs [ip ]
233- if eg .assignedNodeIP == node .nodeIP {
233+ if eg != nil && eg .assignedNodeIP == node .nodeIP {
234234 movedEgressIPs = append (movedEgressIPs , ip )
235235 eit .deleteNodeEgressIP (node , ip )
236236 }
@@ -308,7 +308,9 @@ func (eit *EgressIPTracker) UpdateNetNamespaceEgress(netns *networkapi.NetNamesp
308308 // Even IPs that weren't added/removed need to be considered "changed", to
309309 // ensure we correctly process reorderings, duplicates added/removed, etc.
310310 for _ , ip := range newRequestedIPs .Intersection (oldRequestedIPs ).UnsortedList () {
311- eit .egressIPChanged (eit .egressIPs [ip ])
311+ if eg := eit .egressIPs [ip ]; eg != nil {
312+ eit .egressIPChanged (eg )
313+ }
312314 }
313315
314316 eit .syncEgressIPs ()
@@ -332,7 +334,7 @@ func (eit *EgressIPTracker) egressIPActive(eg *egressIPInfo) (bool, error) {
332334 }
333335 for _ , ip := range eg .namespaces [0 ].requestedIPs {
334336 eg2 := eit .egressIPs [ip ]
335- if eg2 != eg && len (eg2 .nodes ) == 1 && eg2 .nodes [0 ] == eg .nodes [0 ] {
337+ if eg2 != nil && eg2 != eg && len (eg2 .nodes ) == 1 && eg2 .nodes [0 ] == eg .nodes [0 ] {
336338 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 )
337339 }
338340 }
@@ -358,6 +360,12 @@ func (eit *EgressIPTracker) syncEgressIPs() {
358360 eit .syncEgressNamespaceState (ns )
359361 }
360362
363+ for eg := range changedEgressIPs {
364+ if len (eg .namespaces ) == 0 && len (eg .nodes ) == 0 {
365+ delete (eit .egressIPs , eg .ip )
366+ }
367+ }
368+
361369 if eit .updateEgressCIDRs {
362370 eit .updateEgressCIDRs = false
363371 if eit .nodesWithCIDRs > 0 {
@@ -539,7 +547,7 @@ func (eit *EgressIPTracker) ReallocateEgressIPs() map[string][]string {
539547
540548 // Allocate pending egress IPs that can only go to a single node
541549 for egressIP , eip := range eit .egressIPs {
542- if alreadyAllocated [egressIP ] {
550+ if alreadyAllocated [egressIP ] || len ( eip . namespaces ) == 0 {
543551 continue
544552 }
545553 nodeName , otherNodes := eit .findEgressIPAllocation (eip .parsed , allocation )
@@ -551,7 +559,7 @@ func (eit *EgressIPTracker) ReallocateEgressIPs() map[string][]string {
551559 }
552560 // Allocate any other pending egress IPs that we can
553561 for egressIP , eip := range eit .egressIPs {
554- if alreadyAllocated [egressIP ] {
562+ if alreadyAllocated [egressIP ] || len ( eip . namespaces ) == 0 {
555563 continue
556564 }
557565 nodeName , _ := eit .findEgressIPAllocation (eip .parsed , allocation )
0 commit comments