Skip to content

Commit 9d26186

Browse files
committed
fix lint
1 parent 6ee2fd1 commit 9d26186

File tree

2 files changed

+14
-31
lines changed

2 files changed

+14
-31
lines changed

cloud/linode/route_controller.go

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -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

cloud/nodeipam/ipam/cloud_allocator.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -373,9 +373,9 @@ func (c *cloudAllocator) allocateIPv6CIDR(ctx context.Context, node *v1.Node) (*
373373
ipv6Range := ""
374374
if !c.useLinodeInterfaces {
375375
// Retrieve the instance configuration for the Linode ID
376-
configs, err := c.linodeClient.ListInstanceConfigs(ctx, id, &linodego.ListOptions{})
377-
if err != nil || len(configs) == 0 {
378-
return nil, fmt.Errorf("failed to list instance configs: %w", err)
376+
configs, listErr := c.linodeClient.ListInstanceConfigs(ctx, id, &linodego.ListOptions{})
377+
if listErr != nil || len(configs) == 0 {
378+
return nil, fmt.Errorf("failed to list instance configs: %w", listErr)
379379
}
380380

381381
for _, iface := range configs[0].Interfaces {
@@ -391,9 +391,9 @@ func (c *cloudAllocator) allocateIPv6CIDR(ctx context.Context, node *v1.Node) (*
391391
return nil, fmt.Errorf("failed to find ipv6 range in instance config: %v", configs[0])
392392
}
393393
} else {
394-
ifaces, err := c.linodeClient.ListInterfaces(ctx, id, &linodego.ListOptions{})
395-
if err != nil || len(ifaces) == 0 {
396-
return nil, fmt.Errorf("failed to list interfaces: %w", err)
394+
ifaces, listErr := c.linodeClient.ListInterfaces(ctx, id, &linodego.ListOptions{})
395+
if listErr != nil || len(ifaces) == 0 {
396+
return nil, fmt.Errorf("failed to list interfaces: %w", listErr)
397397
}
398398
for _, iface := range ifaces {
399399
if iface.VPC != nil {

0 commit comments

Comments
 (0)