@@ -41,7 +41,8 @@ const (
4141 DisableIPv6SysctlTemplate = "net.ipv6.conf.%s.disable_ipv6"
4242
4343 // dependency labels
44- interfaceVrfDep = "interface-assigned-to-vrf"
44+ interfaceVrfDep = "interface-assigned-to-vrf"
45+ interfaceAddrDep = "address-assigned-to-interface"
4546)
4647
4748// InterfaceAddressDescriptor (un)assigns IP address to/from Linux interface.
@@ -81,17 +82,19 @@ func (d *InterfaceAddressDescriptor) SetInterfaceIndex(intfIndex ifaceidx.LinuxI
8182}
8283
8384// IsInterfaceAddressKey returns true if the key represents assignment of an IP address
84- // to a Linux interface (that needs to be applied). KVs representing addresses
85- // already allocated from netalloc plugin are excluded.
85+ // to a Linux interface (that needs to be applied or is expected to exist).
86+ // KVs representing addresses already allocated from netalloc plugin are excluded.
8687func (d * InterfaceAddressDescriptor ) IsInterfaceAddressKey (key string ) bool {
87- _ , _ , _ , source , _ , isAddrKey := interfaces .ParseInterfaceAddressKey (key )
88+ _ , _ , _ , _ , source , _ , isAddrKey := interfaces .ParseInterfaceAddressKey (key )
8889 return isAddrKey &&
89- (source == netalloc_api .IPAddressSource_STATIC || source == netalloc_api .IPAddressSource_ALLOC_REF )
90+ (source == netalloc_api .IPAddressSource_STATIC ||
91+ source == netalloc_api .IPAddressSource_ALLOC_REF ||
92+ source == netalloc_api .IPAddressSource_EXISTING )
9093}
9194
9295// Validate validates IP address to be assigned to an interface.
9396func (d * InterfaceAddressDescriptor ) Validate (key string , emptyVal proto.Message ) (err error ) {
94- iface , addr , _ , _ , invalidKey , _ := interfaces .ParseInterfaceAddressKey (key )
97+ iface , addr , _ , _ , _ , invalidKey , _ := interfaces .ParseInterfaceAddressKey (key )
9598 if invalidKey {
9699 return errors .New ("invalid key" )
97100 }
@@ -101,7 +104,11 @@ func (d *InterfaceAddressDescriptor) Validate(key string, emptyVal proto.Message
101104
102105// Create assigns IP address to an interface.
103106func (d * InterfaceAddressDescriptor ) Create (key string , emptyVal proto.Message ) (metadata kvs.Metadata , err error ) {
104- iface , addr , _ , _ , _ , _ := interfaces .ParseInterfaceAddressKey (key )
107+ iface , addr , _ , _ , source , _ , _ := interfaces .ParseInterfaceAddressKey (key )
108+ if source == netalloc_api .IPAddressSource_EXISTING {
109+ // already exists, nothing to do
110+ return nil , nil
111+ }
105112
106113 ifMeta , found := d .intfIndex .LookupByName (iface )
107114 if ! found {
@@ -160,7 +167,11 @@ func (d *InterfaceAddressDescriptor) Create(key string, emptyVal proto.Message)
160167
161168// Delete unassigns IP address from an interface.
162169func (d * InterfaceAddressDescriptor ) Delete (key string , emptyVal proto.Message , metadata kvs.Metadata ) (err error ) {
163- iface , addr , _ , _ , _ , _ := interfaces .ParseInterfaceAddressKey (key )
170+ iface , addr , _ , _ , source , _ , _ := interfaces .ParseInterfaceAddressKey (key )
171+ if source == netalloc_api .IPAddressSource_EXISTING {
172+ // already existed before Create, nothing to do
173+ return nil
174+ }
164175
165176 ifMeta , found := d .intfIndex .LookupByName (iface )
166177 if ! found {
@@ -197,13 +208,19 @@ func (d *InterfaceAddressDescriptor) Delete(key string, emptyVal proto.Message,
197208
198209// Dependencies mentions (non-default) VRF and a potential allocation of the IP address as dependencies.
199210func (d * InterfaceAddressDescriptor ) Dependencies (key string , emptyVal proto.Message ) (deps []kvs.Dependency ) {
200- iface , addr , vrf , _ , _ , _ := interfaces .ParseInterfaceAddressKey (key )
211+ iface , addr , vrf , hostName , source , _ , _ := interfaces .ParseInterfaceAddressKey (key )
201212 if vrf != "" {
202213 deps = append (deps , kvs.Dependency {
203214 Label : interfaceVrfDep ,
204215 Key : interfaces .InterfaceVrfKey (iface , vrf ),
205216 })
206217 }
218+ if source == netalloc_api .IPAddressSource_EXISTING {
219+ deps = append (deps , kvs.Dependency {
220+ Label : interfaceAddrDep ,
221+ Key : interfaces .InterfaceHostNameWithAddrKey (hostName , addr ),
222+ })
223+ }
207224 allocDep , hasAllocDep := d .addrAlloc .GetAddressAllocDep (addr , iface , "" )
208225 if hasAllocDep {
209226 deps = append (deps , allocDep )
0 commit comments