@@ -41,7 +41,8 @@ const (
41
41
DisableIPv6SysctlTemplate = "net.ipv6.conf.%s.disable_ipv6"
42
42
43
43
// dependency labels
44
- interfaceVrfDep = "interface-assigned-to-vrf"
44
+ interfaceVrfDep = "interface-assigned-to-vrf"
45
+ interfaceAddrDep = "address-assigned-to-interface"
45
46
)
46
47
47
48
// InterfaceAddressDescriptor (un)assigns IP address to/from Linux interface.
@@ -81,17 +82,19 @@ func (d *InterfaceAddressDescriptor) SetInterfaceIndex(intfIndex ifaceidx.LinuxI
81
82
}
82
83
83
84
// 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.
86
87
func (d * InterfaceAddressDescriptor ) IsInterfaceAddressKey (key string ) bool {
87
- _ , _ , _ , source , _ , isAddrKey := interfaces .ParseInterfaceAddressKey (key )
88
+ _ , _ , _ , _ , source , _ , isAddrKey := interfaces .ParseInterfaceAddressKey (key )
88
89
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 )
90
93
}
91
94
92
95
// Validate validates IP address to be assigned to an interface.
93
96
func (d * InterfaceAddressDescriptor ) Validate (key string , emptyVal proto.Message ) (err error ) {
94
- iface , addr , _ , _ , invalidKey , _ := interfaces .ParseInterfaceAddressKey (key )
97
+ iface , addr , _ , _ , _ , invalidKey , _ := interfaces .ParseInterfaceAddressKey (key )
95
98
if invalidKey {
96
99
return errors .New ("invalid key" )
97
100
}
@@ -101,7 +104,11 @@ func (d *InterfaceAddressDescriptor) Validate(key string, emptyVal proto.Message
101
104
102
105
// Create assigns IP address to an interface.
103
106
func (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
+ }
105
112
106
113
ifMeta , found := d .intfIndex .LookupByName (iface )
107
114
if ! found {
@@ -160,7 +167,11 @@ func (d *InterfaceAddressDescriptor) Create(key string, emptyVal proto.Message)
160
167
161
168
// Delete unassigns IP address from an interface.
162
169
func (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
+ }
164
175
165
176
ifMeta , found := d .intfIndex .LookupByName (iface )
166
177
if ! found {
@@ -197,13 +208,19 @@ func (d *InterfaceAddressDescriptor) Delete(key string, emptyVal proto.Message,
197
208
198
209
// Dependencies mentions (non-default) VRF and a potential allocation of the IP address as dependencies.
199
210
func (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 )
201
212
if vrf != "" {
202
213
deps = append (deps , kvs.Dependency {
203
214
Label : interfaceVrfDep ,
204
215
Key : interfaces .InterfaceVrfKey (iface , vrf ),
205
216
})
206
217
}
218
+ if source == netalloc_api .IPAddressSource_EXISTING {
219
+ deps = append (deps , kvs.Dependency {
220
+ Label : interfaceAddrDep ,
221
+ Key : interfaces .InterfaceHostNameWithAddrKey (hostName , addr ),
222
+ })
223
+ }
207
224
allocDep , hasAllocDep := d .addrAlloc .GetAddressAllocDep (addr , iface , "" )
208
225
if hasAllocDep {
209
226
deps = append (deps , allocDep )
0 commit comments