Skip to content

Commit b9cf1ab

Browse files
Merge pull request #20971 from danwinship/egress-ip-ha-vs-ha
Don't allow mixing "multiple-egress-IP HA" with "auto-allocated-egress-IP HA"
2 parents f9dce12 + e04ea55 commit b9cf1ab

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

pkg/network/common/egressip.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,19 @@ func (eit *EgressIPTracker) findEgressIPAllocation(ip net.IP, allocation map[str
524524
}
525525

526526
func (eit *EgressIPTracker) makeEmptyAllocation() (map[string][]string, map[string]bool) {
527-
return make(map[string][]string), make(map[string]bool)
527+
allocation := make(map[string][]string)
528+
alreadyAllocated := make(map[string]bool)
529+
530+
// We don't want to auto-allocate/reallocate IPs for NetNamespaces using
531+
// multiple-egress-IP HA, so those should be considered "already allocated"
532+
// even before we start.
533+
for egressIP, eip := range eit.egressIPs {
534+
if eip.assignedNodeIP != "" && len(eip.namespaces[0].requestedIPs) > 1 {
535+
alreadyAllocated[egressIP] = true
536+
}
537+
}
538+
539+
return allocation, alreadyAllocated
528540
}
529541

530542
func (eit *EgressIPTracker) allocateExistingEgressIPs(allocation map[string][]string, alreadyAllocated map[string]bool) bool {

pkg/network/common/egressip_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -997,6 +997,29 @@ func TestEgressCIDRAllocation(t *testing.T) {
997997
if err != nil {
998998
t.Fatalf("%v", err)
999999
}
1000+
1001+
// You can't mix multiple-egress-IP HA with auto-allocated-egress-IP HA
1002+
updateNetNamespaceEgress(eit, &networkapi.NetNamespace{
1003+
NetID: 45,
1004+
EgressIPs: []string{"172.17.0.102", "172.17.0.302"},
1005+
})
1006+
err = w.assertChanges(
1007+
"update egress CIDRs",
1008+
)
1009+
if err != nil {
1010+
t.Fatalf("%v", err)
1011+
}
1012+
1013+
allocation = eit.ReallocateEgressIPs()
1014+
updateAllocations(eit, allocation)
1015+
err = w.assertChanges(
1016+
"release 172.17.0.102 on 172.17.0.4",
1017+
"namespace 45 dropped",
1018+
"update egress CIDRs",
1019+
)
1020+
if err != nil {
1021+
t.Fatalf("%v", err)
1022+
}
10001023
}
10011024

10021025
func TestEgressNodeRenumbering(t *testing.T) {

0 commit comments

Comments
 (0)