allocator

package
v0.58.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 13, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Ports

func Ports(svc *v1.Service) []corev1.ServicePort

Ports turns a service definition into a set of allocator ports.

Types

type Allocator

type Allocator struct {
	// contains filtered or unexported fields
}

An Allocator tracks IP address pools and allocates addresses from them.

func NewAllocator

func NewAllocator() *Allocator

NewAllocator returns an Allocator managing no pools.

func (*Allocator) AddPrefix

func (a *Allocator) AddPrefix(sp epicv1.ServicePrefix) error

AddPrefix adds a ServicePrefix's address pool(s) to the allocator. Each SP will have at least one pool, but if that pool is IPV6 then it will also have an alternative pool of IPV4 addresses.

func (*Allocator) AllocateFromPool

func (a *Allocator) AllocateFromPool(svc string, poolName string, ports []corev1.ServicePort, sharingKey string) (net.IP, error)

AllocateFromPool assigns an available IP from pool to service.

func (*Allocator) Assign

func (a *Allocator) Assign(svc string, ip net.IP, ports []corev1.ServicePort, sharingKey string) (string, error)

Assign assigns the requested ip to svc, if the assignment is permissible by sharingKey.

func (*Allocator) RemovePool

func (a *Allocator) RemovePool(sp epicv1.ServicePrefix) error

RemovePool removes an address pool from the allocator.

func (*Allocator) Unassign

func (a *Allocator) Unassign(svc string) bool

Unassign frees the IP associated with service, if any.

func (*Allocator) ValidateDelete

func (a *Allocator) ValidateDelete(sp *epicv1.ServicePrefix) error

ValidateDelete checks whether "sp" can be deleted. A nil return value is good; non-nil means that this pool can't be deleted.

type IPRange

type IPRange struct {
	// contains filtered or unexported fields
}

IPRange represents a from-to range of IP addresses.

func NewIPRange

func NewIPRange(raw string) (IPRange, error)

NewIPRange parses a string representation of an IP address range and returns the corresponding IPRange. The representation can be in either of two forms: CIDR or from-to. CIDR looks like "192.168.1.0/24" and from-to looks like "192.168.1.0 - 192.168.1.255". The error return value will be non-nil if the representation couldn't be parsed.

func (IPRange) Contains

func (r IPRange) Contains(ip net.IP) bool

Contains indicates whether the provided net.IP represents an address within this IPRange. It returns true if so, false otherwise.

func (IPRange) First

func (r IPRange) First() net.IP

First returns the first (i.e., lowest-valued) net.IP within this IPRange.

func (IPRange) Next

func (r IPRange) Next(ip net.IP) net.IP

Next returns the next net.IP within this IPRange, or nil if the provided net.IP is the last address in the range.

func (IPRange) Overlaps

func (r IPRange) Overlaps(other IPRange) bool

Overlaps indicates whether the other IPRange overlaps with this one (i.e., has any addresses in common). It returns true if there are any common addresses and false if there aren't.

func (IPRange) Size

func (r IPRange) Size() uint64

Size returns the count of net.IPs contained in this IPRange. If the count is too large to be represented by a uint64 then the return value will be math.MaxUint64.

type Key

type Key struct {
	Sharing string
}

Key represents a "sharing key" which is used to have two or more services share an IP address.

type LocalPool

type LocalPool struct {
	// contains filtered or unexported fields
}

LocalPool is the configuration of an IP address pool.

func NewLocalPool

func NewLocalPool(rawrange string, subnet string, aggregation string) (*LocalPool, error)

NewLocalPool initializes a new LocalPool object.

func (LocalPool) Assign

func (p LocalPool) Assign(ip net.IP, ports []corev1.ServicePort, service string, sharingKey *Key) error

Assign assigns a service to an IP.

func (LocalPool) AssignNext

func (p LocalPool) AssignNext(service string, ports []corev1.ServicePort, sharingKey *Key) (net.IP, error)

AssignNext assigns a service to the next available IP.

func (LocalPool) Available

func (p LocalPool) Available(ip net.IP, ports []corev1.ServicePort, service string, key *Key) error

Available determines whether an address is available. The decision depends on whether another service is using the address, and if so, whether this service can share the address with it. error will be nil if the ip is available, and will contain an explanation if not.

func (LocalPool) Contains

func (p LocalPool) Contains(ip net.IP) bool

Contains indicates whether the provided net.IP represents an address within this Pool. It returns true if so, false otherwise.

func (LocalPool) First

func (p LocalPool) First() net.IP

First returns the first (i.e., lowest-valued) net.IP within this Pool, or nil if the pool has no addresses.

func (LocalPool) InUse

func (p LocalPool) InUse() int

InUse returns the count of addresses that currently have services assigned.

func (LocalPool) Next

func (p LocalPool) Next(ip net.IP) net.IP

Next returns the next net.IP within this Pool, or nil if the provided net.IP is the last address in the range.

func (LocalPool) Overlaps

func (p LocalPool) Overlaps(other Pool) bool

Overlaps indicates whether the other Pool overlaps with this one (i.e., has any addresses in common). It returns true if there are any common addresses and false if there aren't.

func (LocalPool) Release

func (p LocalPool) Release(ip net.IP, service string)

Release releases an IP so it can be assigned again.

func (LocalPool) SharingKey

func (p LocalPool) SharingKey(ip net.IP) *Key

SharingKey returns the "sharing key" for the specified address.

func (LocalPool) Size

func (p LocalPool) Size() uint64

Size returns the total number of addresses in this pool if it's a local pool, or 0 if it's a remote pool.

type Pool

type Pool interface {
	Available(net.IP, []corev1.ServicePort, string, *Key) error
	AssignNext(string, []corev1.ServicePort, *Key) (net.IP, error)
	Assign(net.IP, []corev1.ServicePort, string, *Key) error
	Release(net.IP, string)
	InUse() int
	SharingKey(net.IP) *Key
	Overlaps(Pool) bool
	Contains(net.IP) bool
	Size() uint64
}

Pool represents a pool of IP addresses.

Notes

Bugs

  • this is inefficient. Is there a better way to find the last address of a CIDR?

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL