Skip to content

Commit 9d1e4a1

Browse files
committed
Change ReallocateEgressIPs() to return the full allocation, not just changes
1 parent 31f6201 commit 9d1e4a1

File tree

3 files changed

+9
-19
lines changed

3 files changed

+9
-19
lines changed

pkg/network/common/egressip.go

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -498,22 +498,20 @@ func (eit *EgressIPTracker) findEgressIPAllocation(ip net.IP, allocation map[str
498498
return bestNode, otherNodes
499499
}
500500

501-
// ReallocateEgressIPs returns a map from Node name to array-of-Egress-IP. Unchanged nodes are not included.
501+
// ReallocateEgressIPs returns a map from Node name to array-of-Egress-IP for all auto-allocated egress IPs
502502
func (eit *EgressIPTracker) ReallocateEgressIPs() map[string][]string {
503503
eit.Lock()
504504
defer eit.Unlock()
505505

506506
allocation := make(map[string][]string)
507-
changed := make(map[string]bool)
508507
alreadyAllocated := make(map[string]bool)
509508
for _, node := range eit.nodes {
510509
if len(node.parsedCIDRs) > 0 {
511510
allocation[node.nodeName] = make([]string, 0, node.requestedIPs.Len())
512511
}
513512
}
514513
// For each active egress IP, if it still fits within some egress CIDR on its node,
515-
// add it to that node's allocation. (Otherwise add the node to the "changed" map,
516-
// since we'll be removing this egress IP from it.)
514+
// add it to that node's allocation.
517515
for egressIP, eip := range eit.egressIPs {
518516
if eip.assignedNodeIP == "" {
519517
continue
@@ -528,8 +526,6 @@ func (eit *EgressIPTracker) ReallocateEgressIPs() map[string][]string {
528526
}
529527
if found {
530528
allocation[node.nodeName] = append(allocation[node.nodeName], egressIP)
531-
} else {
532-
changed[node.nodeName] = true
533529
}
534530
// (We set alreadyAllocated even if the egressIP will be removed from
535531
// its current node; we can't assign it to a new node until the next
@@ -545,7 +541,6 @@ func (eit *EgressIPTracker) ReallocateEgressIPs() map[string][]string {
545541
nodeName, otherNodes := eit.findEgressIPAllocation(eip.parsed, allocation)
546542
if nodeName != "" && !otherNodes {
547543
allocation[nodeName] = append(allocation[nodeName], egressIP)
548-
changed[nodeName] = true
549544
alreadyAllocated[egressIP] = true
550545
}
551546
}
@@ -557,15 +552,8 @@ func (eit *EgressIPTracker) ReallocateEgressIPs() map[string][]string {
557552
nodeName, _ := eit.findEgressIPAllocation(eip.parsed, allocation)
558553
if nodeName != "" {
559554
allocation[nodeName] = append(allocation[nodeName], egressIP)
560-
changed[nodeName] = true
561555
}
562556
}
563557

564-
// Remove unchanged nodes from the return value
565-
for _, node := range eit.nodes {
566-
if !changed[node.nodeName] {
567-
delete(allocation, node.nodeName)
568-
}
569-
}
570558
return allocation
571559
}

pkg/network/common/egressip_test.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -864,9 +864,6 @@ func TestEgressCIDRAllocation(t *testing.T) {
864864
t.Fatalf("%v", err)
865865
}
866866
allocation = eit.ReallocateEgressIPs()
867-
if len(allocation) != 0 {
868-
t.Fatalf("Unexpected allocation: %#v", allocation)
869-
}
870867
updateAllocations(eit, allocation)
871868
err = w.assertNoChanges()
872869
if err != nil {

pkg/network/master/egressip.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"time"
77

88
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
9+
"k8s.io/apimachinery/pkg/util/sets"
910
utilwait "k8s.io/apimachinery/pkg/util/wait"
1011
"k8s.io/client-go/util/retry"
1112

@@ -82,8 +83,12 @@ func (eim *egressIPManager) maybeDoUpdateEgressCIDRs() (bool, error) {
8283
return err
8384
}
8485

85-
hs.EgressIPs = egressIPs
86-
_, err = eim.networkClient.Network().HostSubnets().Update(hs)
86+
oldIPs := sets.NewString(hs.EgressIPs...)
87+
newIPs := sets.NewString(egressIPs...)
88+
if !oldIPs.Equal(newIPs) {
89+
hs.EgressIPs = egressIPs
90+
_, err = eim.networkClient.Network().HostSubnets().Update(hs)
91+
}
8792
return err
8893
})
8994
if resultErr != nil {

0 commit comments

Comments
 (0)