package ipallocator
import "k8s.io/kubernetes/pkg/registry/core/service/ipallocator"
Index ¶
- Variables
- func GetIndexedIP(subnet *net.IPNet, index int) (net.IP, error)
- func RangeSize(subnet *net.IPNet) int64
- type ErrNotInRange
- type Interface
- type Range
- func NewAllocatorCIDRRange(cidr *net.IPNet, allocatorFactory allocator.AllocatorFactory) *Range
- func NewCIDRRange(cidr *net.IPNet) *Range
- func NewFromSnapshot(snap *api.RangeAllocation) (*Range, error)
- func (r *Range) Allocate(ip net.IP) error
- func (r *Range) AllocateNext() (net.IP, error)
- func (r *Range) CIDR() net.IPNet
- func (r *Range) ForEach(fn func(net.IP))
- func (r *Range) Free() int
- func (r *Range) Has(ip net.IP) bool
- func (r *Range) Release(ip net.IP) error
- func (r *Range) Restore(net *net.IPNet, data []byte) error
- func (r *Range) Snapshot(dst *api.RangeAllocation) error
- func (r *Range) Used() int
Variables ¶
var ( ErrFull = errors.New("range is full") ErrAllocated = errors.New("provided IP is already allocated") 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.
func RangeSize ¶
RangeSize returns the size of a range in valid addresses.
Types ¶
type ErrNotInRange ¶
type ErrNotInRange struct { ValidRange string }
func (*ErrNotInRange) Error ¶
func (e *ErrNotInRange) Error() string
type Interface ¶
type Interface interface { Allocate(net.IP) error AllocateNext() (net.IP, error) Release(net.IP) error ForEach(func(net.IP)) // For testing Has(ip net.IP) bool }
Interface manages the allocation of IP addresses out of a range. Interface should be threadsafe.
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 ¶
func NewAllocatorCIDRRange(cidr *net.IPNet, allocatorFactory allocator.AllocatorFactory) *Range
NewAllocatorCIDRRange creates a Range over a net.IPNet, calling allocatorFactory to construct the backing store.
func NewCIDRRange ¶
Helper that wraps NewAllocatorCIDRRange, for creating a range backed by an in-memory store.
func NewFromSnapshot ¶
func NewFromSnapshot(snap *api.RangeAllocation) (*Range, error)
NewFromSnapshot allocates a Range and initializes it from a snapshot.
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) CIDR ¶
CIDR returns the CIDR covered by the range.
func (*Range) ForEach ¶
ForEach calls the provided function for each allocated IP.
func (*Range) Free ¶
Free returns the count of IP addresses left in the range.
func (*Range) Has ¶
Has returns true if the provided IP is already allocated and a call to Allocate(ip) would fail with ErrAllocated.
func (*Range) Release ¶
Release releases the IP back to the pool. Releasing an unallocated IP or an IP out of the range is a no-op and returns no error.
func (*Range) Restore ¶
Restore restores the pool to the previously captured state. ErrMismatchedNetwork is returned if the provided IPNet range doesn't exactly match the previous range.
func (*Range) Snapshot ¶
func (r *Range) Snapshot(dst *api.RangeAllocation) error
Snapshot saves the current state of the pool.
func (*Range) Used ¶
Used returns the count of IP addresses used in the range.
Source Files ¶
allocator.go
Directories ¶
Path | Synopsis |
---|---|
pkg/registry/core/service/ipallocator/controller | |
pkg/registry/core/service/ipallocator/storage |
- Version
- v1.15.8
- Published
- Jan 11, 2020
- Platform
- js/wasm
- Imports
- 6 packages
- Last checked
- 13 minutes ago –
Tools for package owners.