Skip to content

Commit 8764780

Browse files
authored
[fix] Ignore ipv6 routes (#368)
* Add local cache of 'configured' IPv6 routes to send to cloud-provider * Added unit tests for CreateRoute
1 parent 2209b29 commit 8764780

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

cloud/linode/route_controller.go

+18
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package linode
33
import (
44
"context"
55
"fmt"
6+
"net"
67
"os"
78
"strconv"
89
"strings"
@@ -19,6 +20,8 @@ import (
1920
"github.com/linode/linode-cloud-controller-manager/cloud/linode/client"
2021
)
2122

23+
var ipv6ConfiguredRoutes []*cloudprovider.Route
24+
2225
type routeCache struct {
2326
Mu sync.RWMutex
2427
routes map[int][]linodego.VPCIP
@@ -128,6 +131,17 @@ func (r *routes) getInstanceFromName(ctx context.Context, name string) (*linodeg
128131

129132
// CreateRoute adds route's subnet to ip_ranges of target node's VPC interface
130133
func (r *routes) CreateRoute(ctx context.Context, clusterName string, nameHint string, route *cloudprovider.Route) error {
134+
// ignore IPv6 CIDRs but make sure something gets assigned to them to avoid errors
135+
ipAddr, _, err := net.ParseCIDR(route.DestinationCIDR)
136+
if err != nil {
137+
return err
138+
}
139+
if ipAddr.To4() == nil {
140+
// "configure" the route so route controller doesn't keep creating it
141+
ipv6ConfiguredRoutes = append(ipv6ConfiguredRoutes, route)
142+
return nil
143+
}
144+
131145
instance, err := r.getInstanceFromName(ctx, string(route.TargetNode))
132146
if err != nil {
133147
return err
@@ -272,5 +286,9 @@ func (r *routes) ListRoutes(ctx context.Context, clusterName string) ([]*cloudpr
272286
}
273287
}
274288
}
289+
290+
// add in "configured" IPv6 routes so cloud-provider is happy
291+
configuredRoutes = append(configuredRoutes, ipv6ConfiguredRoutes...)
292+
275293
return configuredRoutes, nil
276294
}

cloud/linode/route_controller_test.go

+34
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,40 @@ func TestCreateRoute(t *testing.T) {
381381
assert.NoError(t, err)
382382
})
383383

384+
v6Route := &cloudprovider.Route{
385+
Name: "route2",
386+
TargetNode: types.NodeName(name),
387+
DestinationCIDR: "fd00::/64",
388+
}
389+
t.Run("should return no error if given a route with an IPv6 address", func(t *testing.T) {
390+
ctrl := gomock.NewController(t)
391+
defer ctrl.Finish()
392+
client := mocks.NewMockClient(ctrl)
393+
instanceCache := newInstances(client)
394+
routeController, err := newRoutes(client, instanceCache)
395+
require.NoError(t, err)
396+
397+
err = routeController.CreateRoute(ctx, "dummy", "dummy", v6Route)
398+
assert.NoError(t, err)
399+
})
400+
401+
badV6Route := &cloudprovider.Route{
402+
Name: "route2",
403+
TargetNode: types.NodeName(name),
404+
DestinationCIDR: ":/64",
405+
}
406+
t.Run("should return error if IP address is not v4 or v6", func(t *testing.T) {
407+
ctrl := gomock.NewController(t)
408+
defer ctrl.Finish()
409+
client := mocks.NewMockClient(ctrl)
410+
instanceCache := newInstances(client)
411+
routeController, err := newRoutes(client, instanceCache)
412+
require.NoError(t, err)
413+
414+
err = routeController.CreateRoute(ctx, "dummy", "dummy", badV6Route)
415+
assert.Error(t, err)
416+
})
417+
384418
addressRange1 := "10.10.10.0/24"
385419
routesInVPC := []linodego.VPCIP{
386420
{

0 commit comments

Comments
 (0)