@@ -191,29 +191,7 @@ func (r *routes) CreateRoute(ctx context.Context, clusterName string, nameHint s
191191 Range : route .DestinationCIDR ,
192192 })
193193
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 )
217195}
218196
219197// 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
259237 return fmt .Errorf ("unable to remove route %s for node %s. no valid interface found" , route .DestinationCIDR , route .TargetNode )
260238 }
261239
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 {
262245 if Options .UseLinodeInterfaces {
263246 interfaceUpdateOptions := linodego.LinodeInterfaceUpdateOptions {
264247 VPC : & linodego.VPCInterfaceCreateOptions {
@@ -269,7 +252,7 @@ func (r *routes) DeleteRoute(ctx context.Context, clusterName string, route *clo
269252 if err != nil {
270253 return err
271254 }
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 )
273256 } else {
274257 interfaceUpdateOptions := linodego.InstanceConfigInterfaceUpdateOptions {
275258 IPRanges : & intfRoutes ,
@@ -278,7 +261,7 @@ func (r *routes) DeleteRoute(ctx context.Context, clusterName string, route *clo
278261 if err != nil {
279262 return err
280263 }
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 )
282265 }
283266
284267 return nil
0 commit comments