github.com/cilium/cilium@v1.16.2/pkg/ipam/types.go (about) 1 // SPDX-License-Identifier: Apache-2.0 2 // Copyright Authors of Cilium 3 4 package ipam 5 6 import ( 7 "net" 8 9 "github.com/davecgh/go-spew/spew" 10 11 agentK8s "github.com/cilium/cilium/daemon/k8s" 12 "github.com/cilium/cilium/pkg/datapath/types" 13 "github.com/cilium/cilium/pkg/k8s/client" 14 "github.com/cilium/cilium/pkg/lock" 15 "github.com/cilium/cilium/pkg/node" 16 "github.com/cilium/cilium/pkg/option" 17 ) 18 19 // AllocationResult is the result of an allocation 20 type AllocationResult struct { 21 // IP is the allocated IP 22 IP net.IP 23 24 // IPPoolName is the IPAM pool from which the above IP was allocated from 25 IPPoolName Pool 26 27 // CIDRs is a list of all CIDRs to which the IP has direct access to. 28 // This is primarily useful if the IP has been allocated out of a VPC 29 // subnet range and the VPC provides routing to a set of CIDRs in which 30 // the IP is routable. 31 CIDRs []string 32 33 // PrimaryMAC is the MAC address of the primary interface. This is useful 34 // when the IP is a secondary address of an interface which is 35 // represented on the node as a Linux device and all routing of the IP 36 // must occur through that master interface. 37 PrimaryMAC string 38 39 // GatewayIP is the IP of the gateway which must be used for this IP. 40 // If the allocated IP is derived from a VPC, then the gateway 41 // represented the gateway of the VPC or VPC subnet. 42 GatewayIP string 43 44 // ExpirationUUID is the UUID of the expiration timer. This field is 45 // only set if AllocateNextWithExpiration is used. 46 ExpirationUUID string 47 48 // InterfaceNumber is a field for generically identifying an interface. 49 // This is only useful in ENI mode. 50 InterfaceNumber string 51 } 52 53 // Allocator is the interface for an IP allocator implementation 54 type Allocator interface { 55 // Allocate allocates a specific IP or fails 56 Allocate(ip net.IP, owner string, pool Pool) (*AllocationResult, error) 57 58 // AllocateWithoutSyncUpstream allocates a specific IP without syncing 59 // upstream or fails 60 AllocateWithoutSyncUpstream(ip net.IP, owner string, pool Pool) (*AllocationResult, error) 61 62 // Release releases a previously allocated IP or fails 63 Release(ip net.IP, pool Pool) error 64 65 // AllocateNext allocates the next available IP or fails if no more IPs 66 // are available 67 AllocateNext(owner string, pool Pool) (*AllocationResult, error) 68 69 // AllocateNextWithoutSyncUpstream allocates the next available IP without syncing 70 // upstream or fails if no more IPs are available 71 AllocateNextWithoutSyncUpstream(owner string, pool Pool) (*AllocationResult, error) 72 73 // Dump returns a map of all allocated IPs per pool with the IP represented as key in the 74 // map. Dump must also provide a status one-liner to represent the overall status, e.g. 75 // number of IPs allocated and overall health information if available. 76 Dump() (map[Pool]map[string]string, string) 77 78 // Capacity returns the total IPAM allocator capacity (not the current 79 // available). 80 Capacity() uint64 81 82 // RestoreFinished marks the status of restoration as done 83 RestoreFinished() 84 } 85 86 // IPAM is the configuration used for a particular IPAM type. 87 type IPAM struct { 88 nodeAddressing types.NodeAddressing 89 config *option.DaemonConfig 90 91 IPv6Allocator Allocator 92 IPv4Allocator Allocator 93 94 // metadata provides information about a particular IP owner. 95 metadata Metadata 96 97 // owner maps an IP to the owner per pool. 98 owner map[Pool]map[string]string 99 100 // expirationTimers is a map of all expiration timers. Each entry 101 // represents a IP allocation which is protected by an expiration 102 // timer. 103 expirationTimers map[timerKey]expirationTimer 104 105 // mutex covers access to all members of this struct 106 allocatorMutex lock.RWMutex 107 108 // excludedIPS contains excluded IPs and their respective owners per pool. The key is a 109 // combination pool:ip to avoid having to maintain a map of maps. 110 excludedIPs map[string]string 111 112 localNodeStore *node.LocalNodeStore 113 k8sEventReg K8sEventRegister 114 nodeResource agentK8s.LocalCiliumNodeResource 115 mtuConfig MtuConfiguration 116 clientset client.Clientset 117 nodeDiscovery Owner 118 } 119 120 // DebugStatus implements debug.StatusObject to provide debug status collection 121 // ability 122 func (ipam *IPAM) DebugStatus() string { 123 ipam.allocatorMutex.RLock() 124 str := spew.Sdump( 125 "owners", ipam.owner, 126 "expiration timers", ipam.expirationTimers, 127 "excluded ips", ipam.excludedIPs, 128 ) 129 ipam.allocatorMutex.RUnlock() 130 return str 131 } 132 133 // Pool is the IP pool from which to allocate. 134 type Pool string 135 136 func (p Pool) String() string { 137 return string(p) 138 } 139 140 type timerKey struct { 141 ip string 142 pool Pool 143 } 144 145 type expirationTimer struct { 146 uuid string 147 stop chan<- struct{} 148 }