Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ipam: various minor cleanups #23383

Merged
merged 3 commits into from
Jan 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 6 additions & 15 deletions pkg/ipam/allocator.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ import (
const (
metricAllocate = "allocate"
metricRelease = "release"
familyIPv4 = "ipv4"
familyIPv6 = "ipv6"
)

// Error definitions
Expand Down Expand Up @@ -54,13 +52,6 @@ func (ipam *IPAM) AllocateIP(ip net.IP, owner string) (err error) {
return
}

// AllocateIPWithAllocationResult allocates an IP address, and returns the
// allocation result.
func (ipam *IPAM) AllocateIPWithAllocationResult(ip net.IP, owner string) (result *AllocationResult, err error) {
needSyncUpstream := true
return ipam.allocateIP(ip, owner, needSyncUpstream)
}

// AllocateIPWithoutSyncUpstream allocates a IP address without syncing upstream.
func (ipam *IPAM) AllocateIPWithoutSyncUpstream(ip net.IP, owner string) (result *AllocationResult, err error) {
needSyncUpstream := false
Expand All @@ -86,7 +77,7 @@ func (ipam *IPAM) allocateIP(ip net.IP, owner string, needSyncUpstream bool) (re
return
}

family := familyIPv4
family := IPv4
if ip.To4() != nil {
if ipam.IPv4Allocator == nil {
err = ErrIPv4Disabled
Expand All @@ -103,7 +94,7 @@ func (ipam *IPAM) allocateIP(ip net.IP, owner string, needSyncUpstream bool) (re
}
}
} else {
family = familyIPv6
family = IPv6
if ipam.IPv6Allocator == nil {
err = ErrIPv6Disabled
return
Expand All @@ -126,7 +117,7 @@ func (ipam *IPAM) allocateIP(ip net.IP, owner string, needSyncUpstream bool) (re
}).Debugf("Allocated specific IP")

ipam.owner[ip.String()] = owner
metrics.IpamEvent.WithLabelValues(metricAllocate, family).Inc()
metrics.IpamEvent.WithLabelValues(metricAllocate, string(family)).Inc()
return
}

Expand Down Expand Up @@ -252,7 +243,7 @@ func (ipam *IPAM) AllocateNextWithExpiration(family, owner string, timeout time.
}

func (ipam *IPAM) releaseIPLocked(ip net.IP) error {
family := familyIPv4
family := IPv4
if ip.To4() != nil {
if ipam.IPv4Allocator == nil {
return ErrIPv4Disabled
Expand All @@ -262,7 +253,7 @@ func (ipam *IPAM) releaseIPLocked(ip net.IP) error {
return err
}
} else {
family = familyIPv6
family = IPv6
if ipam.IPv6Allocator == nil {
return ErrIPv6Disabled
}
Expand All @@ -280,7 +271,7 @@ func (ipam *IPAM) releaseIPLocked(ip net.IP) error {
delete(ipam.owner, ip.String())
delete(ipam.expirationTimers, ip.String())

metrics.IpamEvent.WithLabelValues(metricRelease, family).Inc()
metrics.IpamEvent.WithLabelValues(metricRelease, string(family)).Inc()
return nil
}

Expand Down
12 changes: 6 additions & 6 deletions pkg/ipam/allocator/clusterpool/clusterpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ import (

var log = logging.DefaultLogger.WithField(logfields.LogSubsys, "ipam-allocator-clusterpool")

type ErrCIDRColision struct {
type ErrCIDRCollision struct {
cidr string
allocator podcidr.CIDRAllocator
}

func (e ErrCIDRColision) Error() string {
return fmt.Sprintf("requested CIDR %s colides with %s", e.cidr, e.allocator)
func (e ErrCIDRCollision) Error() string {
return fmt.Sprintf("requested CIDR %s collides with %s", e.cidr, e.allocator)
}

func (e *ErrCIDRColision) Is(target error) bool {
t, ok := target.(*ErrCIDRColision)
func (e *ErrCIDRCollision) Is(target error) bool {
t, ok := target.(*ErrCIDRCollision)
if !ok {
return false
}
Expand Down Expand Up @@ -114,7 +114,7 @@ func newCIDRSets(isV6 bool, strCIDRs []string, maskSize int) ([]podcidr.CIDRAllo
// Check if CIDRs collide with each other.
for _, cidrAllocator := range cidrAllocators {
if cidrAllocator.InRange(cidr) {
return nil, &ErrCIDRColision{
return nil, &ErrCIDRCollision{
cidr: strCIDR,
allocator: cidrAllocator,
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/ipam/allocator/clusterpool/clusterpool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func Test_newCIDRSets(t *testing.T) {
strCIDRs: []string{"10.0.0.0/16", "10.0.0.0/8"},
maskSize: 24,
},
wantErr: &ErrCIDRColision{
wantErr: &ErrCIDRCollision{
cidr: "10.0.0.0/8",
},
},
Expand All @@ -55,7 +55,7 @@ func Test_newCIDRSets(t *testing.T) {
strCIDRs: []string{"fd00::/100", "fd00::/96"},
maskSize: 112,
},
wantErr: &ErrCIDRColision{
wantErr: &ErrCIDRCollision{
cidr: "fd00::/96",
},
},
Expand Down