package ipallocator
import "k8s.io/kubernetes/pkg/registry/core/service/ipallocator"
Index ¶
- Constants
- Variables
- type Allocator
- func NewIPAllocator( cidr *net.IPNet, client networkingv1client.NetworkingV1Interface, ipAddressInformer networkingv1informers.IPAddressInformer, ) (*Allocator, error)
- func (a *Allocator) Allocate(ip net.IP) error
- func (a *Allocator) AllocateNext() (net.IP, error)
- func (a *Allocator) AllocateNextService(svc *api.Service) (net.IP, error)
- func (a *Allocator) AllocateService(svc *api.Service, ip net.IP) error
- func (a *Allocator) CIDR() net.IPNet
- func (a *Allocator) Destroy()
- func (a *Allocator) DryRun() Interface
- func (a *Allocator) EnableMetrics()
- func (a *Allocator) ForEach(f func(net.IP))
- func (a *Allocator) Free() int
- func (a *Allocator) Has(ip net.IP) bool
- func (a *Allocator) IPFamily() api.IPFamily
- func (a *Allocator) Release(ip net.IP) error
- func (a *Allocator) Used() int
- type ErrNotInRange
- type Interface
- type MetaAllocator
- func NewMetaAllocator( client networkingv1client.NetworkingV1Interface, serviceCIDRInformer networkingv1informers.ServiceCIDRInformer, ipAddressInformer networkingv1informers.IPAddressInformer, isIPv6 bool, bitmapAllocator Interface, ) (*MetaAllocator, error)
- func (c *MetaAllocator) Allocate(ip net.IP) error
- func (c *MetaAllocator) AllocateNext() (net.IP, error)
- func (c *MetaAllocator) AllocateNextService(service *api.Service) (net.IP, error)
- func (c *MetaAllocator) AllocateService(service *api.Service, ip net.IP) error
- func (c *MetaAllocator) CIDR() net.IPNet
- func (c *MetaAllocator) Destroy()
- func (c *MetaAllocator) DryRun() Interface
- func (c *MetaAllocator) EnableMetrics()
- func (c *MetaAllocator) ForEach(f func(ip net.IP))
- func (c *MetaAllocator) Free() int
- func (c *MetaAllocator) Has(ip net.IP) bool
- func (c *MetaAllocator) IPFamily() api.IPFamily
- func (c *MetaAllocator) Release(ip net.IP) error
- func (c *MetaAllocator) Used() int
- type Range
- func New(cidr *net.IPNet, allocatorFactory allocator.AllocatorWithOffsetFactory) (*Range, error)
- func NewFromSnapshot(snap *api.RangeAllocation) (*Range, error)
- func NewInMemory(cidr *net.IPNet) (*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) Destroy()
- func (r *Range) DryRun() Interface
- func (r *Range) EnableMetrics()
- func (r *Range) ForEach(fn func(net.IP))
- func (r *Range) Free() int
- func (r *Range) Has(ip net.IP) bool
- func (r *Range) IPFamily() api.IPFamily
- 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
Constants ¶
const ControllerName = "ipallocator.k8s.io"
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") ErrNotReady = errors.New("allocator not ready") )
Types ¶
type Allocator ¶
type Allocator struct {
// contains filtered or unexported fields
}
Allocator implements current ipallocator interface using IPAddress API object and an informer as backend.
func NewIPAllocator ¶
func NewIPAllocator( cidr *net.IPNet, client networkingv1client.NetworkingV1Interface, ipAddressInformer networkingv1informers.IPAddressInformer, ) (*Allocator, error)
NewIPAllocator returns an IP allocator associated to a network range that use the IPAddress objectto track the assigned IP addresses, using an informer cache as storage.
func (*Allocator) 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. Only for testing, it will fail to create the IPAddress object because the Service reference is required.
func (*Allocator) AllocateNext ¶
AllocateNext return an IP address that wasn't allocated yet. Only for testing, it will fail to create the IPAddress object because the Service reference is required.
func (*Allocator) AllocateNextService ¶
AllocateNext return an IP address that wasn't allocated yet.
func (*Allocator) AllocateService ¶
AllocateService 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 (*Allocator) CIDR ¶
func (*Allocator) Destroy ¶
func (a *Allocator) Destroy()
Destroy
func (*Allocator) DryRun ¶
DryRun
func (*Allocator) EnableMetrics ¶
func (a *Allocator) EnableMetrics()
EnableMetrics
func (*Allocator) ForEach ¶
ForEach executes the function on each allocated IP This is required to satisfy the Allocator Interface only
func (*Allocator) Free ¶
for testing, it assumes this is the allocator is unique for the ipFamily
func (*Allocator) Has ¶
for testing
func (*Allocator) IPFamily ¶
func (*Allocator) 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 (*Allocator) Used ¶
for testing, it assumes this is the allocator is unique for the ipFamily
type ErrNotInRange ¶
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)) CIDR() net.IPNet IPFamily() api.IPFamily Has(ip net.IP) bool Destroy() EnableMetrics() // DryRun offers a way to try operations without persisting them. DryRun() Interface }
Interface manages the allocation of IP addresses out of a range. Interface should be threadsafe.
type MetaAllocator ¶
type MetaAllocator struct {
// contains filtered or unexported fields
}
MetaAllocator implements current allocator interface using ServiceCIDR and IPAddress API objects.
func NewMetaAllocator ¶
func NewMetaAllocator( client networkingv1client.NetworkingV1Interface, serviceCIDRInformer networkingv1informers.ServiceCIDRInformer, ipAddressInformer networkingv1informers.IPAddressInformer, isIPv6 bool, bitmapAllocator Interface, ) (*MetaAllocator, error)
NewMetaAllocator returns an IP allocator that use the IPAddress and ServiceCIDR objects to track the assigned IP addresses, using an informer cache as storage.
func (*MetaAllocator) Allocate ¶
func (c *MetaAllocator) Allocate(ip net.IP) error
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. Only for testing, it will fail to create the IPAddress object because the Service reference is required.s
func (*MetaAllocator) AllocateNext ¶
func (c *MetaAllocator) AllocateNext() (net.IP, error)
AllocateNext return an IP address that wasn't allocated yet. Only for testing, it will fail to create the IPAddress object because the Service reference is required
func (*MetaAllocator) AllocateNextService ¶
func (*MetaAllocator) AllocateService ¶
func (*MetaAllocator) CIDR ¶
func (c *MetaAllocator) CIDR() net.IPNet
func (*MetaAllocator) Destroy ¶
func (c *MetaAllocator) Destroy()
func (*MetaAllocator) DryRun ¶
func (c *MetaAllocator) DryRun() Interface
DryRun returns a random allocator
func (*MetaAllocator) EnableMetrics ¶
func (c *MetaAllocator) EnableMetrics()
func (*MetaAllocator) ForEach ¶
func (c *MetaAllocator) ForEach(f func(ip net.IP))
func (*MetaAllocator) Free ¶
func (c *MetaAllocator) Free() int
for testing
func (*MetaAllocator) Has ¶
func (c *MetaAllocator) Has(ip net.IP) bool
func (*MetaAllocator) IPFamily ¶
func (c *MetaAllocator) IPFamily() api.IPFamily
func (*MetaAllocator) Release ¶
func (c *MetaAllocator) Release(ip net.IP) error
func (*MetaAllocator) Used ¶
func (c *MetaAllocator) Used() int
for testing
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 New ¶
New creates a Range over a net.IPNet, calling allocatorFactory to construct the backing store.
func NewFromSnapshot ¶
func NewFromSnapshot(snap *api.RangeAllocation) (*Range, error)
NewFromSnapshot allocates a Range and initializes it from a snapshot.
func NewInMemory ¶
NewInMemory creates an in-memory allocator.
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) Destroy ¶
func (r *Range) Destroy()
Destroy shuts down internal allocator.
func (*Range) DryRun ¶
DryRun returns a non-persisting form of this Range.
func (*Range) EnableMetrics ¶
func (r *Range) EnableMetrics()
EnableMetrics enables metrics recording.
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) IPFamily ¶
IPFamily returns the IP family of this range.
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 ¶
bitmap.go cidrallocator.go interfaces.go ipallocator.go metrics.go
Directories ¶
Path | Synopsis |
---|---|
pkg/registry/core/service/ipallocator/controller | |
pkg/registry/core/service/ipallocator/storage |
- Version
- v1.33.1 (latest)
- Published
- May 15, 2025
- Platform
- linux/amd64
- Imports
- 34 packages
- Last checked
- 12 hours ago –
Tools for package owners.