Documentation ¶
Index ¶
- Constants
- Variables
- type AddressInfo
- type CheckpointData
- type CheckpointEntry
- type Checkpointer
- type DataStore
- func (ds *DataStore) AddENI(eniID string, deviceNumber int, isPrimary, isTrunk bool) error
- func (ds *DataStore) AddIPv4AddressToStore(eniID string, ipv4 string) error
- func (ds *DataStore) AllocatedIPs() []PodIPInfo
- func (ds *DataStore) AssignPodIPv4Address(ipamKey IPAMKey) (string, int, error)
- func (ds *DataStore) DelIPv4AddressFromStore(eniID string, ipv4 string, force bool) error
- func (ds *DataStore) FreeableIPs(eniID string) []string
- func (ds *DataStore) GetENIIPs(eniID string) ([]string, error)
- func (ds *DataStore) GetENIInfos() *ENIInfos
- func (ds *DataStore) GetENINeedsIP(maxIPperENI int, skipPrimary bool) *ENI
- func (ds *DataStore) GetENIs() int
- func (ds *DataStore) GetStats() (int, int)
- func (ds *DataStore) GetTrunkENI() string
- func (ds *DataStore) ReadBackingStore() error
- func (ds *DataStore) RemoveENIFromDataStore(eniID string, force bool) error
- func (ds *DataStore) RemoveUnusedENIFromStore(warmIPTarget int, minimumIPTarget int) string
- func (ds *DataStore) UnassignPodIPv4Address(ipamKey IPAMKey) (ip string, deviceNumber int, err error)
- type ENI
- type ENIInfos
- type ENIPool
- type IPAMKey
- 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 BackfillNetworkIface = "unknown"
const BackfillNetworkName = "_migrated-from-cri"
Placeholders used for unknown values when reading from CRI.
const CheckpointFormatVersion = "vpc-cni-ipam/1"
CheckpointFormatVersion is the version stamp used on stored checkpoints.
const CheckpointMigrationPhase = 1
We need to know which IPs are already allocated across ipamd/datastore restarts. In vpc-cni <=1.6, we "stored" the allocated IPs by querying kubelet's CRI. Since this requires scary access to CRI socket, and may race with CRI's internal logic, we are transitioning away from from this to storing allocations ourself in a file (similar to host-ipam CNI plugin).
Because we don't want to require a node restart during CNI upgrade/downgrade, we need an "expand/contract" style upgrade to keep the two stores in sync:
Migration phase0 (CNI 1.6): Read/write from CRI only. Migration phase1 (CNI 1.7): Read from CRI. Write to CRI+file. Migration phase2 (CNI 1.8?): Read from file. Write to CRI+file. Migration phase3 (hypothetical): Read/write from file only.
Note phase3 is not necessary since writes to CRI are implicit. At/after phase2, we can remove any code protected by CheckpointMigrationPhase<2.
Variables ¶
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 ¶
This section is empty.
Types ¶
type AddressInfo ¶
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
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 DataStore ¶
type DataStore struct { CheckpointMigrationPhase int // contains filtered or unexported fields }
DataStore contains node level ENI/IP
func NewDataStore ¶
func NewDataStore(log logger.Logger, backingStore Checkpointer) *DataStore
NewDataStore returns DataStore structure
func (*DataStore) AddIPv4AddressToStore ¶
AddIPv4AddressToStore add an IP 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) AssignPodIPv4Address ¶
AssignPodIPv4Address assigns an IPv4 address to pod It returns the assigned IPv4 address, device number, error
func (*DataStore) DelIPv4AddressFromStore ¶
DelIPv4AddressFromStore delete an IP of ENI from datastore
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) GetENIIPs ¶ added in v1.6.4
GetENIIPs returns the known (allocated & unallocated) ENI IPs.
func (*DataStore) GetENIInfos ¶
GetENIInfos provides ENI IP information to introspection endpoint
func (*DataStore) GetENINeedsIP ¶
GetENINeedsIP finds an ENI in the datastore that needs more IP addresses allocated
func (*DataStore) GetStats ¶
GetStats returns total number of IP addresses and number of assigned IP addresses
func (*DataStore) GetTrunkENI ¶ added in v1.6.4
func (*DataStore) ReadBackingStore ¶ added in v1.6.4
ReadBackingStore initialises 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 return nil on success or an error.
func (*DataStore) RemoveUnusedENIFromStore ¶
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) UnassignPodIPv4Address ¶
func (ds *DataStore) UnassignPodIPv4Address(ipamKey IPAMKey) (ip string, deviceNumber int, err error)
UnassignPodIPv4Address a) find out the IP address based on PodName and PodNameSpace b) mark IP address as unassigned c) returns IP address, ENI's device number, error
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 // 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") IPv4Addresses map[string]*AddressInfo // 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
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, *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 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.