Documentation ¶
Overview ¶
package ipallocator manages allocation of IP addresses from a network range. Modified from https://github.com/kubernetes/kubernetes/blob/v1.17.9/pkg/registry/core/service/ipallocator/allocator.go
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrFull indicates a range is full error ErrFull = errors.New("range is full") // ErrAllocated indicates an IP already allocated error ErrAllocated = errors.New("provided IP is already allocated") // ErrMismatchedNetwork indicates a mismatched network error ErrMismatchedNetwork = errors.New("the provided network does not match the current range") )
Functions ¶
func GetIndexedIP ¶
GetIndexedIP returns a net.IP that is subnet.IP + index in the contiguous IP space.
Types ¶
type ErrNotInRange ¶
type ErrNotInRange struct {
ValidRange string
}
func (*ErrNotInRange) Error ¶
func (e *ErrNotInRange) Error() string
type Range ¶
type Range struct {
// contains filtered or unexported fields
}
Range is a contiguous block of IPs that can be allocated atomically.
The internal structure of the range is:
For CIDR 10.0.0.0/24 254 addresses usable out of 256 total (minus base and broadcast IPs) The number of usable addresses is r.max CIDR base IP CIDR broadcast IP 10.0.0.0 10.0.0.255 | | 0 1 2 3 4 5 ... ... 253 254 255 | | r.base r.base + r.max | | offset #0 of r.allocated last offset of r.allocated
func NewAllocatorCIDRRange ¶
NewAllocatorCIDRRange creates a Range over a net.IPNet backed by in-memory store.
func (*Range) Allocate ¶
Allocate attempts to reserve the provided IP. ErrNotInRange or ErrAllocated will be returned if the IP is not valid for this range or has already been reserved. ErrFull will be returned if there are no addresses left.
func (*Range) AllocateNext ¶
AllocateNext reserves one of the IPs from the pool. ErrFull may be returned if there are no addresses left.
func (*Range) Has ¶
Has returns true if the provided IP is already allocated and a call to Allocate(ip) would fail with ErrAllocated.