Skip to content

Commit

Permalink
replace the iptree on the ipallocator
Browse files Browse the repository at this point in the history
ServiceCIDRs are protected by finalizers and the CIDRs fields are
inmutable once set, only the readiness state impact the allocator
as it can only allocate IPs if any of the ServiceCIDR is ready.

The Add/Update events triggers a reconcilation of the current state
of the ServiceCIDR present in the informers with the existing IP
allocators.

The Delete events are handled directly to update or delete the
corresponing IP allocator.
  • Loading branch information
aojea committed Jun 27, 2024
1 parent b5cfccb commit b04ca18
Show file tree
Hide file tree
Showing 4 changed files with 293 additions and 185 deletions.
6 changes: 3 additions & 3 deletions pkg/api/servicecidr/servicecidr.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func ContainsAddress(serviceCIDRLister networkinglisters.ServiceCIDRLister, addr
for _, serviceCIDR := range serviceCIDRList {
for _, cidr := range serviceCIDR.Spec.CIDRs {
if prefix, err := netip.ParsePrefix(cidr); err == nil { // it can not fail since is already validated
if prefixContainsIP(prefix, address) {
if PrefixContainsIP(prefix, address) {
result = append(result, serviceCIDR)
}
}
Expand All @@ -92,12 +92,12 @@ func ContainsAddress(serviceCIDRLister networkinglisters.ServiceCIDRLister, addr
return result
}

// prefixContainsIP returns true if the given IP is contained with the prefix,
// PrefixContainsIP returns true if the given IP is contained with the prefix,
// is not the network address and also, if IPv4, is not the broadcast address.
// This is required (rather than just `prefix.Contains(ip)`) because a ServiceCIDR
// covering prefix will not allocate those IPs, so a service with one of those IPs
// can't belong to that ServiceCIDR.
func prefixContainsIP(prefix netip.Prefix, ip netip.Addr) bool {
func PrefixContainsIP(prefix netip.Prefix, ip netip.Addr) bool {
// if the IP is the network address is not contained
if prefix.Masked().Addr() == ip {
return false
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/servicecidr/servicecidr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ func Test_PrefixContainIP(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := prefixContainsIP(tt.prefix, tt.ip); got != tt.want {
if got := PrefixContainsIP(tt.prefix, tt.ip); got != tt.want {
t.Errorf("prefixContainIP() = %v, want %v", got, tt.want)
}
})
Expand Down
Loading

0 comments on commit b04ca18

Please sign in to comment.