Documentation
¶
Index ¶
- Variables
- type AllocationAction
- type AllocationImplementation
- type IPAllocationAction
- type IPStatistics
- type MetricsAPI
- type MetricsNodeAPI
- type Node
- func (n *Node) GetNeededAddresses() int
- func (n *Node) InstanceID() (id string)
- func (n *Node) IsPrefixDelegationEnabled() bool
- func (n *Node) IsRunning() bool
- func (n *Node) MaintainIPPool(ctx context.Context) error
- func (n *Node) Ops() NodeOperations
- func (n *Node) Pool() (pool ipamTypes.AllocationMap)
- func (n *Node) PopulateIPReleaseStatus(node *v2.CiliumNode)
- func (n *Node) PopulateStaticIPStatus(node *v2.CiliumNode)
- func (n *Node) ResourceCopy() *v2.CiliumNode
- func (n *Node) SetOpts(ops NodeOperations)
- func (n *Node) SetPoolMaintainer(maintainer PoolMaintainer)
- func (n *Node) SetRunning(running bool)
- func (n *Node) Stats() Statistics
- func (n *Node) UpdatedResource(resource *v2.CiliumNode) bool
- type NodeManager
- func (n *NodeManager) ClusterSizeDependantInterval(baseInterval time.Duration) time.Duration
- func (n *NodeManager) Delete(resource *v2.CiliumNode)
- func (n *NodeManager) Get(nodeName string) *Node
- func (n *NodeManager) GetNames() (allNodeNames []string)
- func (n *NodeManager) GetNodesByIPWatermarkLocked() []*Node
- func (n *NodeManager) InstancesAPIIsReady() bool
- func (n *NodeManager) Resync(ctx context.Context, syncTime time.Time)
- func (n *NodeManager) SetInstancesAPIReadiness(ready bool)
- func (n *NodeManager) Start(ctx context.Context) error
- func (n *NodeManager) Stop()
- func (n *NodeManager) Upsert(resource *v2.CiliumNode)
- type NodeOperations
- type PoolMaintainer
- type ReleaseAction
- type Statistics
Constants ¶
This section is empty.
Variables ¶
var ErrLimitsNotFound = errors.New("Limits not found")
ErrLimitsNotFound signals lack of limits for given instance type.
Functions ¶
This section is empty.
Types ¶
type AllocationAction ¶
type AllocationAction struct {
// InterfaceID is set to the identifier describing the interface on
// which the IPs must be allocated. This is optional, an IPAM
// implementation can leave this empty to indicate that no interface
// context is needed or a new interface must be created.
InterfaceID string
// Interface is the interface to allocate IPs on
Interface ipamTypes.Interface
// PoolID is the IPAM pool identifier to allocate the IPs from. This
// can correspond to a subnet ID or it can also be left blank or set to a
// value such as "global" to indicate a single address pool.
PoolID ipamTypes.PoolID
// EmptyInterfaceSlots is the number of empty interface slots available
// for interfaces to be attached.
EmptyInterfaceSlots int
// IPv4 represents IPv4-specific allocation actions.
IPv4 IPAllocationAction
// IPv6 represents IPv6-specific allocation actions.
IPv6 IPAllocationAction
}
AllocationAction is the action to be taken to resolve allocation deficits for a particular node. It is returned by NodeOperations.PrepareIPAllocation() and passed into NodeOperations.AllocateIPs().
type AllocationImplementation ¶
type AllocationImplementation interface {
// CreateNode is called when the IPAM layer has learned about a new
// node which requires IPAM services. This function must return a
// NodeOperations implementation which will render IPAM services to the
// node context provided.
CreateNode(obj *v2.CiliumNode, node *Node) NodeOperations
// GetPoolQuota is called to retrieve the remaining IP addresses in all
// IP pools known to the IPAM implementation.
GetPoolQuota() ipamTypes.PoolQuotaMap
// Resync is called periodically to give the IPAM implementation a
// chance to resync its own state with external APIs or systems. It is
// also called when the IPAM layer detects that state got out of sync.
Resync(ctx context.Context) (time.Time, error)
// InstanceSync is called to sync the state of the specified instance with
// external APIs or systems.
InstanceSync(ctx context.Context, instanceID string) (time.Time, error)
// HasInstance returns whether the instance is in instances
HasInstance(instanceID string) bool
// DeleteInstance deletes the instance from instances
DeleteInstance(instanceID string)
}
AllocationImplementation is the interface an implementation must provide. Other than NodeOperations, this implementation is not related to a node specifically.
type IPAllocationAction ¶
type IPAllocationAction struct {
// AvailableForAllocation is the number of IPs available for allocation.
// If InterfaceID is set, then this number corresponds to the number of
// IPs available for allocation on that interface. This number may be
// lower than the number of IPs required to resolve the deficit.
AvailableForAllocation int
// MaxIPsToAllocate is set by the core IPAM layer before
// NodeOperations.AllocateIPs() is called and defines the maximum
// number of IPs to allocate in order to stay within the boundaries as
// defined by NodeOperations.{ MinAllocate() | PreAllocate() |
// getMaxAboveWatermark() }.
MaxIPsToAllocate int
// MaxPrefixesToAllocate is set by the core IPAM layer before
// NodeOperations.AllocateIPs() is called and defines the maximum
// number of prefixes to allocate.
MaxPrefixesToAllocate int
// InterfaceCandidates is the number of attached interfaces with IPs
// available for allocation.
InterfaceCandidates int
}
IPAllocationAction is the IP-specific action to be taken to resolve allocation deficits for a particular node.
type IPStatistics ¶
type IPStatistics struct {
// UsedIPs is the number of IPs currently in use
UsedIPs int
// AvailableIPs is the number of IPs currently allocated and available for assignment.
AvailableIPs int
// AvailablePrefixes is the number of IP prefixes currently allocated and
// available for assignment. (Used for IPv6 prefixes)
// Since IPv6 prefixes are very large it does not make sense to keep track of
// the effective number of IPv6 addresses available for assignment.
AvailablePrefixes int
// Capacity is the max inferred IPAM IP capacity for the node.
// In theory, this provides an upper limit on the number of Cilium IPs that
// this Node can support.
Capacity int
// NeededIPs is the number of IPs needed to reach the PreAllocate
// watermark
NeededIPs int
// NeededPrefixes is the number of prefixes needed.
//
// Used for IPv6 prefixes
NeededPrefixes int
// ExcessIPs is the number of free IPs exceeding MaxAboveWatermark
ExcessIPs int
// RemainingInterfaces is the number of interfaces that can either be
// allocated or have not yet exhausted the instance specific quota of
// addresses
RemainingInterfaces int
// InterfaceCandidates is the number of attached interfaces with IPs
// available for allocation.
InterfaceCandidates int
// AssignedStaticIP is the static IP address assigned to the node (ex: public Elastic IP address in AWS)
AssignedStaticIP string
}
IPStatistics represents IP-specific allocation statistics.
type MetricsAPI ¶
type MetricsAPI interface {
MetricsNodeAPI
AllocationAttempt(typ, status, subnetID string, observe float64)
ReleaseAttempt(typ, status, subnetID string, observe float64)
IncInterfaceAllocation(subnetID string)
AddIPAllocation(subnetID string, allocated int64)
AddIPRelease(subnetID string, released int64)
SetInterfaceCandidates(interfaceCandidates int)
SetEmptyInterfaceSlots(emptyInterfaceSlots int)
SetAvailableIPsPerSubnet(subnetID string, availabilityZone string, available int)
SetNodes(category string, nodes int)
IncResyncCount()
ObserveBackgroundSync(status string, duration time.Duration)
PoolMaintainerTrigger() trigger.MetricsObserver
K8sSyncTrigger() trigger.MetricsObserver
ResyncTrigger() trigger.MetricsObserver
}
MetricsAPI represents the metrics being maintained by a NodeManager
type MetricsNodeAPI ¶
type Node ¶
type Node struct {
// contains filtered or unexported fields
}
Node represents a Kubernetes node running Cilium with an associated CiliumNode custom resource
func (*Node) GetNeededAddresses ¶
GetNeededAddresses returns the number of needed addresses that need to be allocated or released. A positive number is returned to indicate allocation. A negative number is returned to indicate release of addresses. This only checks IPv4 since IPv6 subnets rarely reach exhaustion
func (*Node) InstanceID ¶
InstanceID returns the instance ID of the node
func (*Node) IsPrefixDelegationEnabled ¶
func (*Node) MaintainIPPool ¶
MaintainIPPool attempts to allocate or release all required IPs to fulfill the needed gap. If required, interfaces are created.
func (*Node) Ops ¶
func (n *Node) Ops() NodeOperations
Ops returns the IPAM implementation operations for the node
func (*Node) Pool ¶
func (n *Node) Pool() (pool ipamTypes.AllocationMap)
Pool returns the IP allocation pool available to the node
func (*Node) PopulateIPReleaseStatus ¶
func (n *Node) PopulateIPReleaseStatus(node *v2.CiliumNode)
PopulateIPReleaseStatus Updates cilium node IPAM status with excess IP release data
func (*Node) PopulateStaticIPStatus ¶
func (n *Node) PopulateStaticIPStatus(node *v2.CiliumNode)
func (*Node) ResourceCopy ¶
func (n *Node) ResourceCopy() *v2.CiliumNode
ResourceCopy returns a deep copy of the CiliumNode custom resource associated with the node
func (*Node) SetOpts ¶
func (n *Node) SetOpts(ops NodeOperations)
func (*Node) SetPoolMaintainer ¶
func (n *Node) SetPoolMaintainer(maintainer PoolMaintainer)
func (*Node) SetRunning ¶
func (*Node) UpdatedResource ¶
func (n *Node) UpdatedResource(resource *v2.CiliumNode) bool
UpdatedResource is called when an update to the CiliumNode has been received. The IPAM layer will attempt to immediately resolve any IP deficits and also trigger the background sync to continue working in the background to resolve any deficits or excess.
type NodeManager ¶
type NodeManager struct {
// contains filtered or unexported fields
}
NodeManager manages all nodes
func NewNodeManager ¶
func NewNodeManager(logger *slog.Logger, instancesAPI AllocationImplementation, k8sAPI allocator.CiliumNodeGetterUpdater, metrics MetricsAPI, parallelWorkers int64, releaseExcessIPs bool, excessIPReleaseDelay int, prefixDelegation bool) (*NodeManager, error)
NewNodeManager returns a new NodeManager
func (*NodeManager) ClusterSizeDependantInterval ¶
func (n *NodeManager) ClusterSizeDependantInterval(baseInterval time.Duration) time.Duration
func (*NodeManager) Delete ¶
func (n *NodeManager) Delete(resource *v2.CiliumNode)
Delete is called after a CiliumNode resource has been deleted via the Kubernetes apiserver
func (*NodeManager) Get ¶
func (n *NodeManager) Get(nodeName string) *Node
Get returns the node with the given name
func (*NodeManager) GetNames ¶
func (n *NodeManager) GetNames() (allNodeNames []string)
GetNames returns the list of all node names
func (*NodeManager) GetNodesByIPWatermarkLocked ¶
func (n *NodeManager) GetNodesByIPWatermarkLocked() []*Node
GetNodesByIPWatermarkLocked returns all nodes that require addresses to be allocated or released, sorted by the number of addresses needed to be operated in descending order. Number of addresses to be released is negative value so that nodes with IP deficit are resolved first The caller must hold the NodeManager lock
func (*NodeManager) InstancesAPIIsReady ¶
func (n *NodeManager) InstancesAPIIsReady() bool
InstancesAPIIsReady returns true if the instances API is stable and ready
func (*NodeManager) Resync ¶
func (n *NodeManager) Resync(ctx context.Context, syncTime time.Time)
Resync will attend all nodes and resolves IP deficits. The order of attendance is defined by the number of IPs needed to reach the configured watermarks. Any updates to the node resource are synchronized to the Kubernetes apiserver.
func (*NodeManager) SetInstancesAPIReadiness ¶
func (n *NodeManager) SetInstancesAPIReadiness(ready bool)
SetInstancesAPIReadiness sets the readiness state of the instances API
func (*NodeManager) Start ¶
func (n *NodeManager) Start(ctx context.Context) error
Start kicks off the NodeManager by performing the initial state synchronization and starting the background sync goroutine
func (*NodeManager) Stop ¶
func (n *NodeManager) Stop()
func (*NodeManager) Upsert ¶
func (n *NodeManager) Upsert(resource *v2.CiliumNode)
Upsert is called whenever a CiliumNode resource has been updated in the Kubernetes apiserver. The CiliumNode will be created if it didn't exist before.
type NodeOperations ¶
type NodeOperations interface {
// UpdatedNode is called when an update to the CiliumNode is received.
UpdatedNode(obj *v2.CiliumNode)
// PopulateStatusFields is called to give the implementation a chance
// to populate any implementation specific fields in CiliumNode.Status.
PopulateStatusFields(resource *v2.CiliumNode)
// CreateInterface is called to create a new interface. This is only
// done if PrepareIPAllocation indicates that no more IPs are available
// (AllocationAction.AvailableForAllocation == 0) for allocation but
// interfaces are available for creation
// (AllocationAction.EmptyInterfaceSlots > 0). This function must
// create the interface *and* allocate up to
// AllocationAction.MaxIPsToAllocate.
CreateInterface(ctx context.Context, allocation *AllocationAction, scopedLog *slog.Logger) (int, string, error)
// ResyncInterfacesAndIPs is called to synchronize the latest list of
// interfaces and IPs associated with the node. This function is called
// sparingly as this information is kept in sync based on the success
// of the functions AllocateIPs(), ReleaseIPs() and CreateInterface().
// It returns all available ip in node and remaining available interfaces
// that can either be allocated or have not yet exhausted the instance specific quota of addresses
// and error occurred during execution.
ResyncInterfacesAndIPs(ctx context.Context, scopedLog *slog.Logger) (ipamTypes.AllocationMap, ipamStats.InterfaceStats, error)
// PrepareIPAllocation is called to calculate the number of IPs that
// can be allocated on the node and whether a new network interface
// must be attached to the node.
PrepareIPAllocation(scopedLog *slog.Logger) (*AllocationAction, error)
// AllocateIPs is called after invoking PrepareIPAllocation and needs
// to perform the actual allocation.
AllocateIPs(ctx context.Context, allocation *AllocationAction) error
AllocateStaticIP(ctx context.Context, staticIPTags ipamTypes.Tags) (string, error)
// PrepareIPRelease is called to calculate whether any IP excess needs
// to be resolved. It behaves identical to PrepareIPAllocation but
// indicates a need to release IPs.
PrepareIPRelease(excessIPs int, scopedLog *slog.Logger) *ReleaseAction
// ReleaseIPPrefixes is called after invoking PrepareIPRelease and needs to
// perform the release of IPPrefixes.
ReleaseIPPrefixes(ctx context.Context, release *ReleaseAction) error
// ReleaseIPs is called after invoking PrepareIPRelease and needs to
// perform the release of IPs.
ReleaseIPs(ctx context.Context, release *ReleaseAction) error
// GetMaximumAllocatableIPv4 returns the maximum amount of IPv4 addresses
// that can be allocated to the instance
GetMaximumAllocatableIPv4() int
// GetMinimumAllocatableIPv4 returns the minimum amount of IPv4 addresses that
// must be allocated to the instance.
GetMinimumAllocatableIPv4() int
// IsPrefixDelegated helps identify if a node supports prefix delegation
IsPrefixDelegated() bool
// GetAttachedCIDRs returns the CIDRs currently attached to the node's
// network interfaces, as observed by the cloud-specific implementation.
// Used by multi-pool mode to reconcile the tracking map against ground
// truth (drop CIDRs no longer attached, seed releases that survived an
// operator restart). Implementations that do not support multi-pool may
// return nil.
GetAttachedCIDRs() []netip.Prefix
// PrepareCIDRRelease maps released CIDRs back to their source
// network interfaces and returns release actions grouped by interface.
// Used by multi-pool mode where the agent removes CIDRs from
// Allocated instead of participating in the IP release handshake.
PrepareCIDRRelease(releasedCIDRs []netip.Prefix) []*ReleaseAction
// ReleaseCIDRs performs the release of the CIDRs listed in
// release.CIDRsToRelease. The cloud-specific implementation is responsible
// for appropriately handling single-IP CIDRs and larger ones by dispatching to
// the appropriate underlying APIs. Returns the subset of CIDRs that were
// successfully released so the caller can prune its tracking state even on
// partial failure.
ReleaseCIDRs(ctx context.Context, release *ReleaseAction) (released []netip.Prefix, err error)
}
NodeOperations is the interface an IPAM implementation must provide in order to provide IP allocation for a node. The structure implementing this API *must* be aware of the node connected to this implementation. This is achieved by considering the node context provided in AllocationImplementation.CreateNode() function and returning a NodeOperations implementation which performs operations in the context of that node.
type PoolMaintainer ¶
type PoolMaintainer interface {
Trigger()
Shutdown()
}
type ReleaseAction ¶
type ReleaseAction struct {
// InterfaceID is set to the identifier describing the interface on
// which the IPs must be released. This is optional, an IPAM
// implementation can leave this empty to indicate that no interface
// context is needed.
InterfaceID string
// PoolID is the IPAM pool identifier to release the IPs from. This can
// correspond to a subnet ID or it can also be left blank or set to a
// value such as "global" to indicate a single address pool.
PoolID ipamTypes.PoolID
// IPsToRelease is the list of IPs to release.
//
// Used by the CRD-mode release path. The multi-pool release path uses
// CIDRsToRelease instead.
IPsToRelease []string
// IPPrefixesToRelease is the list of prefixes to release.
//
// Used by the CRD-mode release path. The multi-pool release path uses
// CIDRsToRelease instead.
IPPrefixesToRelease []string
// CIDRsToRelease is the list of CIDRs to release. Single-IP entries
// (e.g. 10.0.0.5/32 for IPv4, 2001:db8::1/128 for IPv6) are detected via
// netip.Prefix.IsSingleIP() by the cloud-specific implementation, which
// dispatches to the appropriate underlying API (e.g.
// UnassignPrivateIpAddresses vs UnassignENIPrefixes on AWS). Used by the
// multi-pool release path.
CIDRsToRelease []netip.Prefix
}
ReleaseAction is the action to be taken to resolve allocation excess for a particular node. It is returned by NodeOperations.PrepareIPRelease() and passed into NodeOperations.ReleaseIPs().
type Statistics ¶
type Statistics struct {
// IPv4 represents IPv4-specific statistics.
IPv4 IPStatistics
// IPv6 represents IPv6-specific statistics.
IPv6 IPStatistics
// EmptyInterfaceSlots is the number of empty interface slots available
// for interfaces to be attached.
EmptyInterfaceSlots int
}
Statistics represent the IP allocation statistics of a node