Documentation
¶
Overview ¶
Package ipam handles address allocation management: it hands out the addresses the local endpoints get, from the pools and CIDRs the node has been assigned.
The allocation machinery here is registered by the cilium-agent only. The operator's counterpart, which decides what each node is assigned, lives in operator/pkg/ipam. A few shared types (Family, PoolSpecAccessors) are imported by the operator, but nothing else in this package is.
Index ¶
- Variables
- func NewIPNotAvailableInPoolError(addr netip.Addr) error
- func ParseMultiPoolPreAllocMap(conf map[string]string) (preAllocatePerPool, error)
- type AllocationResult
- type Allocator
- type CloudProvider
- type CloudProviderOut
- type ErrIPNotAvailableInPool
- type ErrPoolNotReadyYet
- type Family
- type IPAM
- func (ipam *IPAM) AllocateIP(ip netip.Addr, owner string, pool Pool) error
- func (ipam *IPAM) AllocateIPString(ipAddr, owner string, pool Pool) error
- func (ipam *IPAM) AllocateIPWithoutSyncUpstream(ip netip.Addr, owner string, pool Pool) (*AllocationResult, error)
- func (ipam *IPAM) AllocateNext(family, owner string, pool Pool) (ipv4Result, ipv6Result *AllocationResult, err error)
- func (ipam *IPAM) AllocateNextFamily(family Family, owner string, pool Pool) (result *AllocationResult, err error)
- func (ipam *IPAM) AllocateNextFamilyWithoutSyncUpstream(family Family, owner string, pool Pool) (result *AllocationResult, err error)
- func (ipam *IPAM) AllocateNextWithExpiration(family, owner string, pool Pool, timeout time.Duration) (ipv4Result, ipv6Result *AllocationResult, err error)
- func (ipam *IPAM) ConfigureAllocator(ctx context.Context) error
- func (ipam *IPAM) DebugStatus() string
- func (ipam *IPAM) Dump() (allocv4 map[string]string, allocv6 map[string]string, status string)
- func (ipam *IPAM) EndpointCreated(ep *endpoint.Endpoint)
- func (ipam *IPAM) EndpointDeleted(ep *endpoint.Endpoint, conf endpoint.DeleteConfig)
- func (ipam *IPAM) EndpointRestored(ep *endpoint.Endpoint)
- func (ipam *IPAM) ExcludeIP(ip netip.Addr, owner string, pool Pool)
- func (ipam *IPAM) ReleaseIP(ip netip.Addr, pool Pool) error
- func (ipam *IPAM) RestoreFinished()
- func (ipam *IPAM) StartExpirationTimer(ip netip.Addr, pool Pool, timeout time.Duration) (string, error)
- func (ipam *IPAM) StopExpirationTimer(ip netip.Addr, pool Pool, allocationUUID string) error
- type K8sEventRegister
- type Metadata
- type MtuConfiguration
- type MultiPoolAllocatorParams
- type MultiPoolManagerParams
- type NewIPAMParams
- type Owner
- type Pool
- type PoolSpecAccessors
- type RoutingMetadataResolver
- type SkipMasqueradeForPoolFn
Constants ¶
This section is empty.
Variables ¶
var ( // ErrIPv4Disabled is returned when IPv4 allocation is disabled ErrIPv4Disabled = errors.New("IPv4 allocation disabled") // ErrIPv6Disabled is returned when Ipv6 allocation is disabled ErrIPv6Disabled = errors.New("IPv6 allocation disabled") )
Error definitions
var MultiPoolAccessor = PoolSpecAccessors{ FromResource: func(cn *ciliumv2.CiliumNode) types.IPAMPoolSpec { return cn.Spec.IPAM.Pools }, ToResource: func(cn *ciliumv2.CiliumNode, spec types.IPAMPoolSpec) bool { if !cn.Spec.IPAM.Pools.DeepEqual(&spec) { cn.Spec.IPAM.Pools = spec return true } return false }, }
Functions ¶
func NewIPNotAvailableInPoolError ¶
NewIPNotAvailableInPoolError returns an error representing the given IP not being available in the IPAM pool.
func ParseMultiPoolPreAllocMap ¶ added in v1.20.0
Types ¶
type AllocationResult ¶
type AllocationResult struct {
// IP is the allocated IP
IP netip.Addr
// IPPoolName is the IPAM pool from which the above IP was allocated from
IPPoolName Pool
// CIDRs is a list of all CIDRs to which the IP has direct access to.
// This is primarily useful if the IP has been allocated out of a VPC
// subnet range and the VPC provides routing to a set of CIDRs in which
// the IP is routable.
CIDRs []netip.Prefix
// PrimaryMAC is the MAC address of the primary interface. This is useful
// when the IP is a secondary address of an interface which is
// represented on the node as a Linux device and all routing of the IP
// must occur through that master interface. It is unset for the IPAM
// modes which have no master interface.
PrimaryMAC mac.MAC
// GatewayIP is the IP of the gateway which must be used for this IP.
// If the allocated IP is derived from a VPC, then the gateway
// represented the gateway of the VPC or VPC subnet.
GatewayIP netip.Addr
// ExpirationUUID is the UUID of the expiration timer. This field is
// only set if AllocateNextWithExpiration is used.
ExpirationUUID string
// InterfaceNumber is a field for generically identifying an interface.
// This is only useful in ENI mode.
InterfaceNumber string
// SkipMasquerade indicates whether the datapath should avoid masquerading connections from this IP when the cluster is in tunneling mode.
SkipMasquerade bool
}
AllocationResult is the result of an allocation
type Allocator ¶
type Allocator interface {
// Allocate allocates a specific IP or fails
Allocate(addr netip.Addr, owner string, pool Pool) (*AllocationResult, error)
// AllocateWithoutSyncUpstream allocates a specific IP without syncing
// upstream or fails
AllocateWithoutSyncUpstream(addr netip.Addr, owner string, pool Pool) (*AllocationResult, error)
// Release releases a previously allocated IP or fails
Release(addr netip.Addr, pool Pool) error
// AllocateNext allocates the next available IP or fails if no more IPs
// are available
AllocateNext(owner string, pool Pool) (*AllocationResult, error)
// AllocateNextWithoutSyncUpstream allocates the next available IP without syncing
// upstream or fails if no more IPs are available
AllocateNextWithoutSyncUpstream(owner string, pool Pool) (*AllocationResult, error)
// Dump returns a map of all allocated IPs per pool with the IP represented as key in the
// map. Dump must also provide a status one-liner to represent the overall status, e.g.
// number of IPs allocated and overall health information if available.
Dump() (map[Pool]map[string]string, string)
// Capacity returns the total IPAM allocator capacity (not the current
// available).
Capacity() uint64
// RestoreFinished marks the status of restoration as done
RestoreFinished()
}
Allocator is the interface for an IP allocator implementation
type CloudProvider ¶
type CloudProvider interface {
// Mode returns the IPAM mode this provider handles.
Mode() string
// PoolSpecAccessors returns how allocated CIDRs are read from and written
// back to the CiliumNode for this cloud.
PoolSpecAccessors() PoolSpecAccessors
// Initialize performs the cloud-specific startup work that must not block:
// registering the provider's CiliumNode observers and whatever jobs it needs
// to configure the node. It is called once, before the multi-pool manager is
// constructed, and returns the resolver the allocators enrich their results
// with.
Initialize() (RoutingMetadataResolver, error)
// WaitReady blocks until the state the jobs registered by Initialize set in
// motion has converged and the agent is allowed to serve allocations. A
// provider with nothing to converge on returns nil immediately.
//
// It returns an error if ctx is cancelled first.
WaitReady(ctx context.Context) error
}
CloudProvider is the cloud-specific customization of the agent-side multi-pool allocator. Exactly one is selected at runtime, by IPAM mode.
Implementations live in pkg/{cloud}/agent and import this package, pkg/ipam consumes them through the "ipam-cloud-providers" hive value group and imports no cloud-provider package.
This is the agent-side counterpart of operator/pkg/ipam.CloudAllocator.
type CloudProviderOut ¶
type CloudProviderOut struct {
cell.Out
Provider CloudProvider `group:"ipam-cloud-providers"`
}
CloudProviderOut is returned by each cloud provider cell.
type ErrIPNotAvailableInPool ¶
type ErrIPNotAvailableInPool struct {
// contains filtered or unexported fields
}
ErrIPNotAvailableInPool represents an error when an IP is not available in the pool.
func (*ErrIPNotAvailableInPool) Error ¶
func (e *ErrIPNotAvailableInPool) Error() string
func (*ErrIPNotAvailableInPool) Is ¶
func (e *ErrIPNotAvailableInPool) Is(target error) bool
Is provides this error type with the logic for use with errors.Is.
type ErrPoolNotReadyYet ¶ added in v1.17.2
type ErrPoolNotReadyYet struct {
// contains filtered or unexported fields
}
func (*ErrPoolNotReadyYet) Error ¶ added in v1.17.2
func (e *ErrPoolNotReadyYet) Error() string
func (*ErrPoolNotReadyYet) Is ¶ added in v1.17.2
func (e *ErrPoolNotReadyYet) Is(err error) bool
type Family ¶
type Family string
Family is the type describing all address families support by the IP allocation manager
func DeriveFamily ¶
DeriveFamily derives the address family of an IP
type IPAM ¶
type IPAM struct {
// contains filtered or unexported fields
}
IPAM is the configuration used for a particular IPAM type.
func (*IPAM) AllocateIP ¶
AllocateIP allocates an IP address.
func (*IPAM) AllocateIPString ¶
AllocateIPString is identical to AllocateIP but takes a string
func (*IPAM) AllocateIPWithoutSyncUpstream ¶
func (ipam *IPAM) AllocateIPWithoutSyncUpstream(ip netip.Addr, owner string, pool Pool) (*AllocationResult, error)
AllocateIPWithoutSyncUpstream allocates an IP address without syncing upstream.
func (*IPAM) AllocateNext ¶
func (ipam *IPAM) AllocateNext(family, owner string, pool Pool) (ipv4Result, ipv6Result *AllocationResult, err error)
AllocateNext allocates the next available IPv4 and IPv6 address out of the configured address pool. If family is set to "ipv4" or "ipv6", then allocation is limited to the specified address family. If the pool has been drained of addresses, an error will be returned.
func (*IPAM) AllocateNextFamily ¶
func (ipam *IPAM) AllocateNextFamily(family Family, owner string, pool Pool) (result *AllocationResult, err error)
AllocateNextFamily allocates the next IP of the requested address family
func (*IPAM) AllocateNextFamilyWithoutSyncUpstream ¶
func (ipam *IPAM) AllocateNextFamilyWithoutSyncUpstream(family Family, owner string, pool Pool) (result *AllocationResult, err error)
AllocateNextFamilyWithoutSyncUpstream allocates the next IP of the requested address family without syncing upstream
func (*IPAM) AllocateNextWithExpiration ¶
func (ipam *IPAM) AllocateNextWithExpiration(family, owner string, pool Pool, timeout time.Duration) (ipv4Result, ipv6Result *AllocationResult, err error)
AllocateNextWithExpiration is identical to AllocateNext but registers an expiration timer as well. This is identical to using AllocateNext() in combination with StartExpirationTimer()
func (*IPAM) ConfigureAllocator ¶ added in v1.16.0
ConfigureAllocator initializes the IPAM allocator according to the configuration. As a precondition, the NodeAddressing must be fully initialized - therefore the method must be called after Daemon.WaitForNodeInformation.
func (*IPAM) DebugStatus ¶
DebugStatus implements debug.StatusObject to provide debug status collection ability
func (*IPAM) EndpointCreated ¶ added in v1.18.0
func (*IPAM) EndpointDeleted ¶ added in v1.18.0
func (ipam *IPAM) EndpointDeleted(ep *endpoint.Endpoint, conf endpoint.DeleteConfig)
func (*IPAM) EndpointRestored ¶ added in v1.18.0
func (*IPAM) ExcludeIP ¶
ExcludeIP ensures that a certain IP is never allocated. It is preferred to use this method instead of allocating the IP as the allocation block can change and suddenly cover the IP to be excluded.
func (*IPAM) ReleaseIP ¶
ReleaseIP releases an IP address. The pool argument must not be empty, it must be set to the pool name returned by the `Allocate*` functions when the IP was allocated.
func (*IPAM) RestoreFinished ¶ added in v1.19.0
func (ipam *IPAM) RestoreFinished()
RestoreFinished marks the status of restoration as done
func (*IPAM) StartExpirationTimer ¶
func (ipam *IPAM) StartExpirationTimer(ip netip.Addr, pool Pool, timeout time.Duration) (string, error)
StartExpirationTimer installs an expiration timer for a previously allocated IP. Unless StopExpirationTimer is called in time, the IP will be released again after expiration of the specified timeout. The function will return a UUID representing the unique allocation attempt. The same UUID must be passed into StopExpirationTimer again.
This function is to be used as allocation and use of an IP can be controlled by an external entity and that external entity can disappear. Therefore such users should register an expiration timer before returning the IP and then stop the expiration timer when the IP has been used.
func (*IPAM) StopExpirationTimer ¶
StopExpirationTimer will remove the expiration timer for a particular IP. The UUID returned by the symmetric StartExpirationTimer must be provided. The expiration timer will only be removed if the UUIDs match. Releasing an IP will also stop the expiration timer.
type K8sEventRegister ¶
type K8sEventRegister interface {
// K8sEventReceived is called to do metrics accounting for received
// Kubernetes events, as well as calculating timeouts for k8s watcher
// cache sync.
K8sEventReceived(apiGroupResourceName string, scope string, action string, valid, equal bool)
// K8sEventProcessed is called to do metrics accounting for each processed
// Kubernetes event.
K8sEventProcessed(scope string, action string, status bool)
}
K8sEventRegister is used to register and handle events as they are processed by K8s controllers.
type MtuConfiguration ¶
type MtuConfiguration interface {
GetDeviceMTU() int
}
type MultiPoolAllocatorParams ¶ added in v1.20.0
type MultiPoolAllocatorParams struct {
Logger *slog.Logger
IPv4Enabled bool
IPv6Enabled bool
CiliumNodeUpdateRate time.Duration
PreAllocPools map[string]string
Node agentK8s.LocalCiliumNodeResource
LocalNodeStore *node.LocalNodeStore
CNClient cilium_v2.CiliumNodeInterface
JobGroup job.Group
DB *statedb.DB
PodIPPools statedb.Table[podippool.LocalPodIPPool]
OnlyMasqueradeDefaultPool bool
}
type MultiPoolManagerParams ¶ added in v1.19.0
type MultiPoolManagerParams struct {
Logger *slog.Logger
IPv4Enabled bool
IPv6Enabled bool
CiliumNodeUpdateRate time.Duration
PreallocMap preAllocatePerPool
Node agentK8s.LocalCiliumNodeResource
CNClient cilium_v2.CiliumNodeInterface
JobGroup job.Group
PoolSpecAccessors PoolSpecAccessors
SkipMasqueradeForPool SkipMasqueradeForPoolFn
// LinearPreAlloc uses a simple inUse + preAlloc formula for demand
// computation instead of the multi-pool's neededIPCeil rounding. This
// matches the CRD allocator's calculateNeededIPs behavior and allows
// the operator to recover exact usage from the demand signal.
LinearPreAlloc bool
}
type NewIPAMParams ¶ added in v1.19.0
type NewIPAMParams struct {
Logger *slog.Logger
NodeAddressing node.Addressing
AgentConfig *option.DaemonConfig
NodeDiscovery Owner
LocalNodeStore *node.LocalNodeStore
K8sEventReg K8sEventRegister
NodeResource agentK8s.LocalCiliumNodeResource
MTUConfig MtuConfiguration
Clientset client.Clientset
Metadata Metadata
Sysctl sysctl.Sysctl
IPMasqAgent *ipmasq.IPMasqAgent
JobGroup job.Group
DB *statedb.DB
PodIPPools statedb.Table[podippool.LocalPodIPPool]
OnlyMasqueradeDefaultPool bool
// CloudProviders holds the registered cloud providers, keyed by the IPAM
// mode each one handles.
CloudProviders map[string]CloudProvider
}
NewIPAMParams contains the parameters for creating a new IPAM instance.
type Owner ¶
type Owner interface {
// UpdateCiliumNodeResource is called to create/update the CiliumNode
// resource. The function must block until the custom resource has been
// created.
UpdateCiliumNodeResource()
}
Owner is the interface the owner of an IPAM allocator has to implement
type Pool ¶
type Pool string
Pool is the IP pool from which to allocate.
func PoolOrDefault ¶
PoolOrDefault returns the default pool if no pool is specified.
type PoolSpecAccessors ¶ added in v1.20.0
type PoolSpecAccessors struct {
// FromResource returns the IPAM Pool specs from the CiliumNode
FromResource func(*ciliumv2.CiliumNode) types.IPAMPoolSpec
// ToResource writes the IPAM Pool specs to the CiliumNode.
// It returns true if the pools have been updated, false otherwise.
ToResource func(*ciliumv2.CiliumNode, types.IPAMPoolSpec) bool
}
PoolSpecAccessors reads and writes the pool specification in the CiliumNode.
This is needed to reuse the same multi-pool manager for different implementations, since each frontend targets a different field when reading and writing the pool specs.
type RoutingMetadataResolver ¶
type RoutingMetadataResolver interface {
// ResolveRoutingMetadata returns the cloud-specific routing metadata of
// addr (PrimaryMAC, GatewayIP, CIDRs, InterfaceNumber), reported as the
// AllocationResult the allocator hands to its caller.
//
// Returning an error makes an allocating caller release the reservation
// that the underlying allocation already took.
ResolveRoutingMetadata(node *ciliumv2.CiliumNode, addr netip.Addr, pool Pool) (*AllocationResult, error)
}
RoutingMetadataResolver reports the cloud-specific routing metadata of an allocated address. It is built by CloudProvider.Initialize.
type SkipMasqueradeForPoolFn ¶ added in v1.20.0
SkipMasqueradeForPoolFn is the type of a function that, given a pool returns true if the addresses of that pool should be excluded from masquerading, false otherwise. In case the pool is not found a non-nil error is returned.