Documentation
¶
Index ¶
- Constants
- Variables
- func DivCeil(x, y int) int
- func GetPrefixDelegationDefaults() (int, int, int)
- type AddressInfo
- type CheckpointData
- type CheckpointEntry
- type Checkpointer
- type CidrInfo
- type CidrStats
- type DataStore
- func (ds *DataStore) AddENI(eniID string, deviceNumber int, isPrimary, isTrunk, isEFA bool, ...) error
- func (ds *DataStore) AddIPv4CidrToStore(eniID string, ipv4Cidr net.IPNet, isPrefix bool) error
- func (ds *DataStore) AddIPv6CidrToStore(eniID string, ipv6Cidr net.IPNet, isPrefix bool) error
- func (ds *DataStore) AllocatedIPs() []PodIPInfo
- func (ds *DataStore) AssignPodIPAddress(ipamKey IPAMKey, ipamMetadata IPAMMetadata, isIPv4Enabled bool, ...) (ipv4Address string, ipv6Address string, deviceNumber int, routeTableId int, ...)
- func (ds *DataStore) AssignPodIPv4Address(ipamKey IPAMKey, ipamMetadata IPAMMetadata) (ipv4address string, deviceNumber int, routeTableId int, err error)
- func (ds *DataStore) AssignPodIPv6Address(ipamKey IPAMKey, ipamMetadata IPAMMetadata) (ipv6Address string, deviceNumber int, routeTableId int, err error)
- func (ds *DataStore) CheckFreeableENIexists() bool
- func (ds *DataStore) DelIPv4CidrFromStore(eniID string, cidr net.IPNet, force bool) error
- func (ds *DataStore) DelIPv6CidrFromStore(eniID string, cidr net.IPNet, force bool) error
- func (ds *DataStore) DeleteFromContainerRule(entry *CheckpointEntry)
- func (ds *DataStore) DeleteToContainerRule(entry *CheckpointEntry)
- func (ds *DataStore) FindFreeableCidrs(eniID string) []CidrInfo
- func (ds *DataStore) FreeableIPs(eniID string) []net.IPNet
- func (ds *DataStore) FreeablePrefixes(eniID string) []net.IPNet
- func (ds *DataStore) GetAllocatableENIs(maxIPperENI int, skipPrimary bool) []*ENI
- func (ds *DataStore) GetEFAENIs() map[string]bool
- func (ds *DataStore) GetENICIDRs(eniID string) ([]string, []string, error)
- func (ds *DataStore) GetENIInfos() *ENIInfos
- func (ds *DataStore) GetENIs() int
- func (ds *DataStore) GetFreePrefixes() int
- func (ds *DataStore) GetIPStats(addressFamily string) *DataStoreStats
- func (ds *DataStore) GetNetworkCard() int
- func (ds *DataStore) GetTrunkENI() string
- func (ds *DataStore) IsENIExcludedForPodIPs(eniID string) bool
- func (ds *DataStore) PruneStaleAllocations(staleAllocations []CheckpointEntry)
- func (ds *DataStore) ReadBackingStore(isv6Enabled bool) error
- func (ds *DataStore) RemoveENIFromDataStore(eniID string, force bool) error
- func (ds *DataStore) RemoveUnusedENIFromStore(warmIPTarget, minimumIPTarget, warmPrefixTarget int) string
- func (ds *DataStore) SetENIExcludedForPodIPs(eniID string, excluded bool) error
- func (ds *DataStore) UnassignPodIPAddress(ipamKey IPAMKey) (e *ENI, ip string, deviceNumber int, interfaces int, routeTableId int, ...)
- type DataStoreAccess
- type DataStoreStats
- type ENI
- type ENIInfos
- type ENIPool
- type IPAMKey
- type IPAMMetadata
- type JSONFile
- type NullCheckpoint
- type PodIPInfo
- type TestCheckpoint
Constants ¶
const ( // DuplicatedENIError is an error when caller tries to add an duplicate ENI to data store DuplicatedENIError = "data store: duplicate ENI" // IPAlreadyInStoreError is an error when caller tries to add an duplicate IP address to data store IPAlreadyInStoreError = "datastore: IP already in data store" // UnknownIPError is an error when caller tries to delete an IP which is unknown to data store UnknownIPError = "datastore: unknown IP" // IPInUseError is an error when caller tries to delete an IP where IP is still assigned to a Pod IPInUseError = "datastore: IP is used and can not be deleted" // ENIInUseError is an error when caller tries to delete an ENI where there are IP still assigned to a pod ENIInUseError = "datastore: ENI is used and can not be deleted" // UnknownENIError is an error when caller tries to access an ENI which is unknown to datastore UnknownENIError = "datastore: unknown ENI" )
const CheckpointFormatVersion = "vpc-cni-ipam/1"
CheckpointFormatVersion is the version stamp used on stored checkpoints.
Variables ¶
var ErrNoAvailableIPInDataStore = errors.New("AssignPodIPAddress: no available IP/Prefix addresses")
ErrNoAvailableIPInDataStore is an error when IPAM cannot assign an IP address from the datastore
var ErrUnknownPod = errors.New("datastore: unknown pod")
ErrUnknownPod is an error when there is no pod in data store matching pod name, namespace, sandbox id
Functions ¶
func GetPrefixDelegationDefaults ¶ added in v1.9.0
Function to return PD defaults supported by VPC
Types ¶
type AddressInfo ¶
type AddressInfo struct {
Address string
IPAMKey IPAMKey
IPAMMetadata IPAMMetadata
AssignedTime time.Time
UnassignedTime time.Time
}
AddressInfo contains information about an IP, Exported fields will be marshaled for introspection.
func (AddressInfo) Assigned ¶
func (addr AddressInfo) Assigned() bool
Assigned returns true iff the address is allocated to a pod/sandbox.
type CheckpointData ¶ added in v1.6.4
type CheckpointData struct {
Version string `json:"version"`
Allocations []CheckpointEntry `json:"allocations"`
}
CheckpointData is the format of stored checkpoints. Note this is deliberately a "dumb" format since efficiency is less important than version stability here.
type CheckpointEntry ¶ added in v1.6.4
type CheckpointEntry struct {
IPAMKey
IPv4 string `json:"ipv4,omitempty"`
IPv6 string `json:"ipv6,omitempty"`
AllocationTimestamp int64 `json:"allocationTimestamp"`
Metadata IPAMMetadata `json:"metadata"`
}
CheckpointEntry is a "row" in the conceptual IPAM datastore, as stored in checkpoints.
type Checkpointer ¶ added in v1.6.4
Checkpointer can persist data and (hopefully) restore it later
type CidrInfo ¶ added in v1.9.0
type CidrInfo struct {
// Either v4/v6 Host or LPM Prefix
Cidr net.IPNet
// Key is individual IP addresses from the Prefix - /32 (v4) or /128 (v6)
IPAddresses map[string]*AddressInfo
// true if Cidr here is an LPM prefix
IsPrefix bool
// IP Address Family of the Cidr
AddressFamily string
}
CidrInfo
func (*CidrInfo) AssignedIPAddressesInCidr ¶ added in v1.10.0
AssignedIPAddressesInCidr is the number of IP addresses already assigned in the IPv4 CIDR
func (*CidrInfo) GetIPStatsFromCidr ¶ added in v1.10.0
Gets number of assigned IPs and the IPs in cooldown from a given CIDR
type DataStore ¶
type DataStore struct {
// contains filtered or unexported fields
}
DataStore contains node level ENI/IP
func NewDataStore ¶
func NewDataStore(log logger.Logger, backingStore Checkpointer, isPDEnabled bool, networkCard int) *DataStore
NewDataStore returns DataStore structure
func (*DataStore) AddENI ¶
func (ds *DataStore) AddENI(eniID string, deviceNumber int, isPrimary, isTrunk, isEFA bool, routeTableID int, subnetID string) error
AddENI add ENI to data store
func (*DataStore) AddIPv4CidrToStore ¶ added in v1.9.0
AddIPv4AddressToStore adds IPv4 CIDR of an ENI to data store
func (*DataStore) AddIPv6CidrToStore ¶ added in v1.10.0
AddIPv6AddressToStore adds IPv6 CIDR of an ENI to data store
func (*DataStore) AllocatedIPs ¶ added in v1.6.4
AllocatedIPs returns a recent snapshot of allocated sandbox<->IPs. Note result may already be stale by the time you look at it.
func (*DataStore) AssignPodIPAddress ¶ added in v1.10.0
func (*DataStore) AssignPodIPv4Address ¶
func (ds *DataStore) AssignPodIPv4Address(ipamKey IPAMKey, ipamMetadata IPAMMetadata) (ipv4address string, deviceNumber int, routeTableId int, err error)
AssignPodIPv4Address assigns an IPv4 address to pod It returns the assigned IPv4 address, device number, route table ID, and error
func (*DataStore) AssignPodIPv6Address ¶ added in v1.10.0
func (ds *DataStore) AssignPodIPv6Address(ipamKey IPAMKey, ipamMetadata IPAMMetadata) (ipv6Address string, deviceNumber int, routeTableId int, err error)
AssignPodIPv6Address assigns an IPv6 address to a pod. Returns the assigned IPv6 address, device number, route table ID, and an error.
func (*DataStore) CheckFreeableENIexists ¶ added in v1.9.0
CheckFreeableENIexists will return true if there is an ENI which is unused. Could have just called getDeletaleENI, this is just to optimize a bit.
func (*DataStore) DelIPv4CidrFromStore ¶ added in v1.9.0
func (*DataStore) DelIPv6CidrFromStore ¶ added in v1.22.0
DelIPv6CidrFromStore deletes IPv6 CIDR from the datastore
func (*DataStore) DeleteFromContainerRule ¶ added in v1.13.0
func (ds *DataStore) DeleteFromContainerRule(entry *CheckpointEntry)
func (*DataStore) DeleteToContainerRule ¶ added in v1.13.0
func (ds *DataStore) DeleteToContainerRule(entry *CheckpointEntry)
func (*DataStore) FindFreeableCidrs ¶ added in v1.9.0
FindFreeableCidrs finds and returns Cidrs that are not assigned to Pods but are attached to ENIs on the node.
func (*DataStore) FreeableIPs ¶ added in v1.6.4
FreeableIPs returns a list of unused and potentially freeable IPs. Note result may already be stale by the time you look at it.
func (*DataStore) FreeablePrefixes ¶ added in v1.9.0
FreeablePrefixes returns a list of unused and potentially freeable prefixes (both IPv4 and IPv6). Note result may already be stale by the time you look at it.
func (*DataStore) GetAllocatableENIs ¶ added in v1.18.3
GetAllocatableENIs finds ENIs in the datastore that needs more IP addresses allocated
func (*DataStore) GetEFAENIs ¶ added in v1.7.6
GetEFAENIs returns the a map containing all attached EFA ENIs
func (*DataStore) GetENICIDRs ¶ added in v1.9.0
GetENICIDRs returns the known (allocated & unallocated) ENI secondary IPs and Prefixes
func (*DataStore) GetENIInfos ¶
GetENIInfos provides ENI and IP information about the datastore
func (*DataStore) GetFreePrefixes ¶ added in v1.9.0
GetFreePrefixes return free prefixes
func (*DataStore) GetIPStats ¶ added in v1.11.0
func (ds *DataStore) GetIPStats(addressFamily string) *DataStoreStats
GetIPStats returns DataStoreStats for addressFamily
func (*DataStore) GetNetworkCard ¶ added in v1.20.0
func (*DataStore) GetTrunkENI ¶ added in v1.6.4
GetTrunkENI returns the trunk ENI ID or an empty string
func (*DataStore) IsENIExcludedForPodIPs ¶ added in v1.22.0
IsENIExcludedForPodIPs returns whether an ENI is excluded from pod IP allocation
func (*DataStore) PruneStaleAllocations ¶ added in v1.13.0
func (ds *DataStore) PruneStaleAllocations(staleAllocations []CheckpointEntry)
For each stale allocation, cleanup leaked IP rules if they exist
func (*DataStore) ReadBackingStore ¶ added in v1.6.4
ReadBackingStore initializes the IP allocation state from the configured backing store. Should be called before using data store.
func (*DataStore) RemoveENIFromDataStore ¶
RemoveENIFromDataStore removes an ENI from the datastore. It returns nil on success, or an error.
func (*DataStore) RemoveUnusedENIFromStore ¶
func (ds *DataStore) RemoveUnusedENIFromStore(warmIPTarget, minimumIPTarget, warmPrefixTarget int) string
RemoveUnusedENIFromStore removes a deletable ENI from the data store. It returns the name of the ENI which has been removed from the data store and needs to be deleted, or empty string if no ENI could be removed.
func (*DataStore) SetENIExcludedForPodIPs ¶ added in v1.22.0
SetENIExcludedForPodIPs marks an ENI as excluded from pod IP allocation
func (*DataStore) UnassignPodIPAddress ¶ added in v1.10.0
func (ds *DataStore) UnassignPodIPAddress(ipamKey IPAMKey) (e *ENI, ip string, deviceNumber int, interfaces int, routeTableId int, err error)
UnassignPodIPAddress: a) Finds the IP address based on PodName and PodNamespace. b) Marks the IP address as unassigned. Returns:
- *ENI: the ENI object associated with the IP address
- ip string: the IP address being unassigned
- deviceNumber int: the ENI's device number
- interfaces int: the number of interfaces associated with the pod
- routeTableId int: the ENI's route table ID
- err error: error if any occurred during unassignment
type DataStoreAccess ¶ added in v1.20.0
type DataStoreAccess struct {
DataStores []*DataStore
}
func InitializeDataStores ¶ added in v1.20.0
func (*DataStoreAccess) GetDataStore ¶ added in v1.20.0
func (ds *DataStoreAccess) GetDataStore(networkCard int) *DataStore
func (*DataStoreAccess) ReadAllDataStores ¶ added in v1.20.0
func (ds *DataStoreAccess) ReadAllDataStores(enableIPv6 bool) error
type DataStoreStats ¶ added in v1.11.0
type DataStoreStats struct {
// Total number of addresses allocated
TotalIPs int
// Total number of prefixes allocated
TotalPrefixes int
// Number of assigned addresses
AssignedIPs int
// Number of addresses in cooldown
CooldownIPs int
}
func (*DataStoreStats) AvailableAddresses ¶ added in v1.11.0
func (stats *DataStoreStats) AvailableAddresses() int
func (*DataStoreStats) String ¶ added in v1.11.0
func (stats *DataStoreStats) String() string
type ENI ¶ added in v1.6.4
type ENI struct {
// AWS ENI ID
ID string
// IsPrimary indicates whether ENI is a primary ENI
IsPrimary bool
// IsTrunk indicates whether this ENI is used to provide pods with dedicated ENIs
IsTrunk bool
// IsEFA indicates whether this ENI is tagged as an EFA
IsEFA bool
// DeviceNumber is the device number of ENI (0 means the primary ENI)
DeviceNumber int
// IPv4Addresses shows whether each address is assigned, the key is IP address, which must
// be in dot-decimal notation with no leading zeros and no whitespace(eg: "10.1.0.253")
// Key is the IP address - PD: "IP/28" and SIP: "IP/32"
AvailableIPv4Cidrs map[string]*CidrInfo
//IPv6CIDRs contains information tied to IPv6 Prefixes attached to the ENI
IPv6Cidrs map[string]*CidrInfo
// IsExcludedForPodIPs indicates whether this ENI should be excluded from pod IP allocation
IsExcludedForPodIPs bool
// RouteTableID is the route table ID associated with the ENI on the host
RouteTableID int
// SubnetID is the subnet which the ENI was created
SubnetID string
// contains filtered or unexported fields
}
ENI represents a single ENI. Exported fields will be marshaled for introspection.
func (*ENI) AssignedIPv4Addresses ¶ added in v1.6.4
AssignedIPv4Addresses is the number of IP addresses already assigned
func (*ENI) AssignedIPv6Addresses ¶ added in v1.22.0
AssignedIPv6Addresses is the number of IPv6 addresses already assigned
type ENIInfos ¶
type ENIInfos struct {
// TotalIPs is the total number of IP addresses
TotalIPs int
// assigned is the number of IP addresses that has been assigned
AssignedIPs int
// ENIs contains ENI IP pool information
ENIs map[string]ENI
}
ENIInfos contains ENI IP information
type ENIPool ¶ added in v1.6.4
ENIPool is a collection of ENI, keyed by ENI ID
func (*ENIPool) AssignedIPv4Addresses ¶ added in v1.6.4
AssignedIPv4Addresses is the number of IP addresses already assigned
func (*ENIPool) FindAddressForSandbox ¶ added in v1.6.4
func (p *ENIPool) FindAddressForSandbox(ipamKey IPAMKey) (*ENI, *CidrInfo, *AddressInfo)
FindAddressForSandbox returns ENI and AddressInfo or (nil, nil) if not found
type IPAMKey ¶ added in v1.6.4
type IPAMKey struct {
NetworkName string `json:"networkName"`
ContainerID string `json:"containerID"`
IfName string `json:"ifName"`
}
IPAMKey is the IPAM primary key. Quoting CNI spec:
Plugins that store state should do so using a primary key of (network name, CNI_CONTAINERID, CNI_IFNAME).
type IPAMMetadata ¶ added in v1.11.0
type IPAMMetadata struct {
K8SPodNamespace string `json:"k8sPodNamespace,omitempty"`
K8SPodName string `json:"k8sPodName,omitempty"`
InterfacesCount int `json:"interfacesCount,omitempty"`
}
IPAMMetadata is the metadata associated with IP allocations.
type JSONFile ¶ added in v1.6.4
type JSONFile struct {
// contains filtered or unexported fields
}
JSONFile is a checkpointer that writes to a JSON file
func NewJSONFile ¶ added in v1.6.4
NewJSONFile creates a new JsonFile
func (*JSONFile) Checkpoint ¶ added in v1.6.4
Checkpoint implements the Checkpointer interface
type NullCheckpoint ¶ added in v1.6.4
type NullCheckpoint struct{}
NullCheckpoint discards data and always returns "not found". For testing only!
func (NullCheckpoint) Checkpoint ¶ added in v1.6.4
func (c NullCheckpoint) Checkpoint(data interface{}) error
Checkpoint implements the Checkpointer interface in the most trivial sense, by just discarding data.
func (NullCheckpoint) Restore ¶ added in v1.6.4
func (c NullCheckpoint) Restore(into interface{}) error
Restore implements the Checkpointer interface in the most trivial sense, by always returning "not found".
type PodIPInfo ¶
type PodIPInfo struct {
IPAMKey IPAMKey
// IP is the IPv4 address of pod
IP string
// DeviceNumber is the device number of the ENI
DeviceNumber int
}
PodIPInfo contains pod's IP and the device number of the ENI
type TestCheckpoint ¶ added in v1.6.4
type TestCheckpoint struct {
Error error
Data interface{}
}
TestCheckpoint maintains a snapshot in memory.
func NewTestCheckpoint ¶ added in v1.6.4
func NewTestCheckpoint(data interface{}) *TestCheckpoint
NewTestCheckpoint creates a new TestCheckpoint.
func (*TestCheckpoint) Checkpoint ¶ added in v1.6.4
func (c *TestCheckpoint) Checkpoint(data interface{}) error
Checkpoint implements the Checkpointer interface.
func (*TestCheckpoint) Restore ¶ added in v1.6.4
func (c *TestCheckpoint) Restore(into interface{}) error
Restore implements the Checkpointer interface.