@@ -191,29 +191,7 @@ func (r *routes) CreateRoute(ctx context.Context, clusterName string, nameHint s
191
191
Range : route .DestinationCIDR ,
192
192
})
193
193
194
- if Options .UseLinodeInterfaces {
195
- interfaceUpdateOptions := linodego.LinodeInterfaceUpdateOptions {
196
- VPC : & linodego.VPCInterfaceCreateOptions {
197
- IPv4 : & linodego.VPCInterfaceIPv4CreateOptions {Ranges : linodeInterfaceRoutes },
198
- },
199
- }
200
- resp , err := r .client .UpdateInterface (ctx , instance .ID , intfVPCIP .InterfaceID , interfaceUpdateOptions )
201
- if err != nil {
202
- return err
203
- }
204
- klog .V (4 ).Infof ("Added routes for node %s. Current routes: %v" , route .TargetNode , resp .VPC .IPv4 .Ranges )
205
- } else {
206
- interfaceUpdateOptions := linodego.InstanceConfigInterfaceUpdateOptions {
207
- IPRanges : & intfRoutes ,
208
- }
209
- resp , err := r .client .UpdateInstanceConfigInterface (ctx , instance .ID , intfVPCIP .ConfigID , intfVPCIP .InterfaceID , interfaceUpdateOptions )
210
- if err != nil {
211
- return err
212
- }
213
- klog .V (4 ).Infof ("Added routes for node %s. Current routes: %v" , route .TargetNode , resp .IPRanges )
214
- }
215
-
216
- return nil
194
+ return r .handleInterfaces (ctx , intfRoutes , linodeInterfaceRoutes , instance , intfVPCIP , route )
217
195
}
218
196
219
197
// DeleteRoute removes route's subnet from ip_ranges of target node's VPC interface
@@ -259,6 +237,11 @@ func (r *routes) DeleteRoute(ctx context.Context, clusterName string, route *clo
259
237
return fmt .Errorf ("unable to remove route %s for node %s. no valid interface found" , route .DestinationCIDR , route .TargetNode )
260
238
}
261
239
240
+ return r .handleInterfaces (ctx , intfRoutes , linodeInterfaceRoutes , instance , intfVPCIP , route )
241
+ }
242
+
243
+ // handleInterfaces updates the VPC interface with adding or deleting routes
244
+ func (r * routes ) handleInterfaces (ctx context.Context , intfRoutes []string , linodeInterfaceRoutes []linodego.VPCInterfaceIPv4RangeCreateOptions , instance * linodego.Instance , intfVPCIP linodego.VPCIP , route * cloudprovider.Route ) error {
262
245
if Options .UseLinodeInterfaces {
263
246
interfaceUpdateOptions := linodego.LinodeInterfaceUpdateOptions {
264
247
VPC : & linodego.VPCInterfaceCreateOptions {
@@ -269,7 +252,7 @@ func (r *routes) DeleteRoute(ctx context.Context, clusterName string, route *clo
269
252
if err != nil {
270
253
return err
271
254
}
272
- klog .V (4 ).Infof ("Deleted route for node %s. Current routes: %v" , route .TargetNode , resp .VPC .IPv4 .Ranges )
255
+ klog .V (4 ).Infof ("Updated routes for node %s. Current routes: %v" , route .TargetNode , resp .VPC .IPv4 .Ranges )
273
256
} else {
274
257
interfaceUpdateOptions := linodego.InstanceConfigInterfaceUpdateOptions {
275
258
IPRanges : & intfRoutes ,
@@ -278,7 +261,7 @@ func (r *routes) DeleteRoute(ctx context.Context, clusterName string, route *clo
278
261
if err != nil {
279
262
return err
280
263
}
281
- klog .V (4 ).Infof ("Deleted route for node %s. Current routes: %v" , route .TargetNode , resp .IPRanges )
264
+ klog .V (4 ).Infof ("Updated routes for node %s. Current routes: %v" , route .TargetNode , resp .IPRanges )
282
265
}
283
266
284
267
return nil
0 commit comments