Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cloud/linode/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const (
// DefaultClientTimeout is the default timeout for a client Linode API call
DefaultClientTimeout = 120 * time.Second
DefaultLinodeAPIURL = "https://api.linode.com"
MaxPageSize = 500
)

type TokenProvider func(context.Context) (string, error)
Expand Down
2 changes: 1 addition & 1 deletion cloud/linode/loadbalancers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4135,7 +4135,7 @@ func Test_getNodeBackendIP(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{
Name: "node-1",
Annotations: map[string]string{
annotations.AnnLinodeNodePrivateIP: "192.168.10.10",
annotations.AnnLinodeNodePrivateIP: "192.168.10.10",
annotations.AnnLinodeNodePublicIPv6: "2600:3c06::1/128",
},
},
Expand Down
19 changes: 10 additions & 9 deletions cloud/linode/node_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"k8s.io/client-go/util/workqueue"

"github.com/linode/linode-cloud-controller-manager/cloud/annotations"
linodeClient "github.com/linode/linode-cloud-controller-manager/cloud/linode/client"
"github.com/linode/linode-cloud-controller-manager/cloud/linode/client/mocks"
"github.com/linode/linode-cloud-controller-manager/cloud/linode/services"
)
Expand Down Expand Up @@ -51,7 +52,7 @@ func TestNodeController_Run(t *testing.T) {
stopCh := make(chan struct{})
go nodeCtrl.Run(stopCh)

client.EXPECT().ListInstances(gomock.Any(), nil).AnyTimes().Return([]linodego.Instance{}, &linodego.Error{Code: http.StatusTooManyRequests, Message: "Too many requests"})
client.EXPECT().ListInstances(gomock.Any(), &linodego.ListOptions{PageSize: linodeClient.MaxPageSize, Filter: "{}"}).AnyTimes().Return([]linodego.Instance{}, &linodego.Error{Code: http.StatusTooManyRequests, Message: "Too many requests"})
// Add the node to the informer
err = nodeCtrl.informer.Informer().GetStore().Add(node)
require.NoError(t, err, "expected no error when adding node to informer")
Expand Down Expand Up @@ -93,7 +94,7 @@ func TestNodeController_processNext(t *testing.T) {

t.Run("should return no error on unknown errors", func(t *testing.T) {
controller.addNodeToQueue(node)
client.EXPECT().ListInstances(gomock.Any(), nil).Times(1).Return([]linodego.Instance{}, errors.New("lookup failed"))
client.EXPECT().ListInstances(gomock.Any(), &linodego.ListOptions{PageSize: linodeClient.MaxPageSize, Filter: "{}"}).Times(1).Return([]linodego.Instance{}, errors.New("lookup failed"))
result := controller.processNext()
assert.True(t, result, "processNext should return true")
if queue.Len() != 0 {
Expand All @@ -115,7 +116,7 @@ func TestNodeController_processNext(t *testing.T) {
controller.addNodeToQueue(node)
publicIP := net.ParseIP("172.234.31.123")
privateIP := net.ParseIP("192.168.159.135")
client.EXPECT().ListInstances(gomock.Any(), nil).Times(1).Return([]linodego.Instance{
client.EXPECT().ListInstances(gomock.Any(), &linodego.ListOptions{PageSize: linodeClient.MaxPageSize, Filter: "{}"}).Times(1).Return([]linodego.Instance{
{ID: 111, Label: "test", IPv4: []*net.IP{&publicIP, &privateIP}, HostUUID: "111"},
}, nil)
result := controller.processNext()
Expand Down Expand Up @@ -143,7 +144,7 @@ func TestNodeController_processNext(t *testing.T) {
controller.addNodeToQueue(node2)
publicIP := net.ParseIP("172.234.31.123")
privateIP := net.ParseIP("192.168.159.135")
client.EXPECT().ListInstances(gomock.Any(), nil).Times(1).Return([]linodego.Instance{
client.EXPECT().ListInstances(gomock.Any(), &linodego.ListOptions{PageSize: linodeClient.MaxPageSize, Filter: "{}"}).Times(1).Return([]linodego.Instance{
{ID: 112, Label: "test-node2", IPv4: []*net.IP{&publicIP, &privateIP}, HostUUID: "112"},
}, nil)
result := controller.processNext()
Expand Down Expand Up @@ -171,7 +172,7 @@ func TestNodeController_processNext(t *testing.T) {
client := mocks.NewMockClient(ctrl)
controller.instances = services.NewInstances(client)
retryInterval = 1 * time.Nanosecond
client.EXPECT().ListInstances(gomock.Any(), nil).Times(1).Return([]linodego.Instance{}, &linodego.Error{Code: http.StatusTooManyRequests, Message: "Too many requests"})
client.EXPECT().ListInstances(gomock.Any(), &linodego.ListOptions{PageSize: linodeClient.MaxPageSize, Filter: "{}"}).Times(1).Return([]linodego.Instance{}, &linodego.Error{Code: http.StatusTooManyRequests, Message: "Too many requests"})
result := controller.processNext()
time.Sleep(1 * time.Second)
assert.True(t, result, "processNext should return true")
Expand All @@ -187,7 +188,7 @@ func TestNodeController_processNext(t *testing.T) {
client := mocks.NewMockClient(ctrl)
controller.instances = services.NewInstances(client)
retryInterval = 1 * time.Nanosecond
client.EXPECT().ListInstances(gomock.Any(), nil).Times(1).Return([]linodego.Instance{}, &linodego.Error{Code: http.StatusInternalServerError, Message: "Too many requests"})
client.EXPECT().ListInstances(gomock.Any(), &linodego.ListOptions{PageSize: linodeClient.MaxPageSize, Filter: "{}"}).Times(1).Return([]linodego.Instance{}, &linodego.Error{Code: http.StatusInternalServerError, Message: "Too many requests"})
result := controller.processNext()
time.Sleep(1 * time.Second)
assert.True(t, result, "processNext should return true")
Expand Down Expand Up @@ -228,7 +229,7 @@ func TestNodeController_handleNode(t *testing.T) {
publicIP := net.ParseIP("172.234.31.123")
privateIP := net.ParseIP("192.168.159.135")
publicIPv6SLAAC := "2001:db::f03c:91ff:fe2b:1a2b"
client.EXPECT().ListInstances(gomock.Any(), nil).Times(1).Return([]linodego.Instance{
client.EXPECT().ListInstances(gomock.Any(), &linodego.ListOptions{PageSize: linodeClient.MaxPageSize, Filter: "{}"}).Times(1).Return([]linodego.Instance{
{ID: 123, Label: "test-node", IPv4: []*net.IP{&publicIP, &privateIP}, IPv6: publicIPv6SLAAC, HostUUID: "123"},
}, nil)
err = nodeCtrl.handleNode(t.Context(), node)
Expand All @@ -251,15 +252,15 @@ func TestNodeController_handleNode(t *testing.T) {
client = mocks.NewMockClient(ctrl)
nodeCtrl.instances = services.NewInstances(client)
nodeCtrl.metadataLastUpdate["test-node"] = time.Now().Add(-2 * nodeCtrl.ttl)
client.EXPECT().ListInstances(gomock.Any(), nil).Times(1).Return([]linodego.Instance{}, errors.New("lookup failed"))
client.EXPECT().ListInstances(gomock.Any(), &linodego.ListOptions{PageSize: linodeClient.MaxPageSize, Filter: "{}"}).Times(1).Return([]linodego.Instance{}, errors.New("lookup failed"))
err = nodeCtrl.handleNode(t.Context(), node)
require.Error(t, err, "expected error during handleNode, got nil")

// All fields already set
client = mocks.NewMockClient(ctrl)
nodeCtrl.instances = services.NewInstances(client)
nodeCtrl.metadataLastUpdate["test-node"] = time.Now().Add(-2 * nodeCtrl.ttl)
client.EXPECT().ListInstances(gomock.Any(), nil).Times(1).Return([]linodego.Instance{
client.EXPECT().ListInstances(gomock.Any(), &linodego.ListOptions{PageSize: linodeClient.MaxPageSize, Filter: "{}"}).Times(1).Return([]linodego.Instance{
{ID: 123, Label: "test-node", IPv4: []*net.IP{&publicIP, &privateIP}, IPv6: publicIPv6SLAAC, HostUUID: "123"},
}, nil)
err = nodeCtrl.handleNode(t.Context(), node)
Expand Down
1 change: 1 addition & 0 deletions cloud/linode/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,5 @@ var Options struct {
NodeCIDRMaskSizeIPv4 int
NodeCIDRMaskSizeIPv6 int
NodeBalancerPrefix string
LinodeTagFilter string
}
31 changes: 16 additions & 15 deletions cloud/linode/route_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"testing"

"github.com/golang/mock/gomock"
linodeClient "github.com/linode/linode-cloud-controller-manager/cloud/linode/client"
"github.com/linode/linodego"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -53,7 +54,7 @@ func TestListRoutes(t *testing.T) {
routeController, err := newRoutes(client, instanceCache)
require.NoError(t, err)

client.EXPECT().ListInstances(gomock.Any(), gomock.Any()).Times(1).Return([]linodego.Instance{}, nil)
client.EXPECT().ListInstances(gomock.Any(), &linodego.ListOptions{PageSize: linodeClient.MaxPageSize, Filter: "{}"}).Times(1).Return([]linodego.Instance{}, nil)
client.EXPECT().ListVPCIPAddresses(gomock.Any(), gomock.Any(), gomock.Any()).Times(2).Return([]linodego.VPCIP{}, nil)
client.EXPECT().ListVPCIPv6Addresses(gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes().Return([]linodego.VPCIP{}, nil)
routes, err := routeController.ListRoutes(ctx, "test")
Expand All @@ -78,7 +79,7 @@ func TestListRoutes(t *testing.T) {
routeController, err := newRoutes(client, instanceCache)
require.NoError(t, err)

client.EXPECT().ListInstances(gomock.Any(), nil).Times(1).Return([]linodego.Instance{validInstance}, nil)
client.EXPECT().ListInstances(gomock.Any(), &linodego.ListOptions{PageSize: linodeClient.MaxPageSize, Filter: "{}"}).Times(1).Return([]linodego.Instance{validInstance}, nil)
client.EXPECT().ListVPCIPAddresses(gomock.Any(), gomock.Any(), gomock.Any()).Times(2).Return([]linodego.VPCIP{}, nil)
client.EXPECT().ListVPCIPv6Addresses(gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes().Return([]linodego.VPCIP{}, nil)
routes, err := routeController.ListRoutes(ctx, "test")
Expand Down Expand Up @@ -106,7 +107,7 @@ func TestListRoutes(t *testing.T) {
routeController, err := newRoutes(client, instanceCache)
require.NoError(t, err)

client.EXPECT().ListInstances(gomock.Any(), nil).Times(1).Return([]linodego.Instance{validInstance}, nil)
client.EXPECT().ListInstances(gomock.Any(), &linodego.ListOptions{PageSize: linodeClient.MaxPageSize, Filter: "{}"}).Times(1).Return([]linodego.Instance{validInstance}, nil)
client.EXPECT().ListVPCIPAddresses(gomock.Any(), gomock.Any(), gomock.Any()).Times(4).Return(noRoutesInVPC, nil)
client.EXPECT().ListVPCIPv6Addresses(gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes().Return([]linodego.VPCIP{}, nil)
routes, err := routeController.ListRoutes(ctx, "test")
Expand Down Expand Up @@ -155,7 +156,7 @@ func TestListRoutes(t *testing.T) {
routeController, err := newRoutes(client, instanceCache)
require.NoError(t, err)

client.EXPECT().ListInstances(gomock.Any(), nil).Times(1).Return([]linodego.Instance{validInstance}, nil)
client.EXPECT().ListInstances(gomock.Any(), &linodego.ListOptions{PageSize: linodeClient.MaxPageSize, Filter: "{}"}).Times(1).Return([]linodego.Instance{validInstance}, nil)
client.EXPECT().ListVPCIPAddresses(gomock.Any(), gomock.Any(), gomock.Any()).Times(4).Return(routesInVPC, nil)
client.EXPECT().ListVPCIPv6Addresses(gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes().Return([]linodego.VPCIP{}, nil)
routes, err := routeController.ListRoutes(ctx, "test")
Expand Down Expand Up @@ -204,7 +205,7 @@ func TestListRoutes(t *testing.T) {
routeController, err := newRoutes(client, instanceCache)
require.NoError(t, err)

client.EXPECT().ListInstances(gomock.Any(), nil).Times(1).Return([]linodego.Instance{validInstance}, nil)
client.EXPECT().ListInstances(gomock.Any(), &linodego.ListOptions{PageSize: linodeClient.MaxPageSize, Filter: "{}"}).Times(1).Return([]linodego.Instance{validInstance}, nil)
client.EXPECT().ListVPCIPAddresses(gomock.Any(), gomock.Any(), gomock.Any()).Times(4).Return(routesInDifferentVPC, nil)
client.EXPECT().ListVPCIPv6Addresses(gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes().Return([]linodego.VPCIP{}, nil)
routes, err := routeController.ListRoutes(ctx, "test")
Expand Down Expand Up @@ -300,7 +301,7 @@ func TestListRoutes(t *testing.T) {

registeredK8sNodeCache.addNodeToCache(node2)

client.EXPECT().ListInstances(gomock.Any(), nil).Times(1).Return([]linodego.Instance{validInstance, validInstance2, validInstance3}, nil)
client.EXPECT().ListInstances(gomock.Any(), &linodego.ListOptions{PageSize: linodeClient.MaxPageSize, Filter: "{}"}).Times(1).Return([]linodego.Instance{validInstance, validInstance2, validInstance3}, nil)
c1 := client.EXPECT().ListVPCIPAddresses(gomock.Any(), gomock.Any(), gomock.Any()).Times(1).Return(routesInVPC, nil)
c2 := client.EXPECT().ListVPCIPAddresses(gomock.Any(), gomock.Any(), gomock.Any()).After(c1).Times(1).Return(routesInVPC2, nil)
c3 := client.EXPECT().ListVPCIPAddresses(gomock.Any(), gomock.Any(), gomock.Any()).After(c2).Times(1).Return(routesInVPC, nil)
Expand Down Expand Up @@ -385,7 +386,7 @@ func TestCreateRoute(t *testing.T) {
routeController, err := newRoutes(client, instanceCache)
require.NoError(t, err)

client.EXPECT().ListInstances(gomock.Any(), nil).Times(1).Return([]linodego.Instance{validInstance}, nil)
client.EXPECT().ListInstances(gomock.Any(), &linodego.ListOptions{PageSize: linodeClient.MaxPageSize, Filter: "{}"}).Times(1).Return([]linodego.Instance{validInstance}, nil)
client.EXPECT().ListVPCIPAddresses(gomock.Any(), gomock.Any(), gomock.Any()).Times(2).Return(noRoutesInVPC, nil)
client.EXPECT().ListVPCIPv6Addresses(gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes().Return([]linodego.VPCIP{}, nil)
client.EXPECT().UpdateInstanceConfigInterface(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Times(1).Return(&instanceConfigIntfWithVPCAndRoute, nil)
Expand Down Expand Up @@ -416,7 +417,7 @@ func TestCreateRoute(t *testing.T) {
routeController, err := newRoutes(client, instanceCache)
require.NoError(t, err)

client.EXPECT().ListInstances(gomock.Any(), nil).Times(1).Return([]linodego.Instance{validInstance}, nil)
client.EXPECT().ListInstances(gomock.Any(), &linodego.ListOptions{PageSize: linodeClient.MaxPageSize, Filter: "{}"}).Times(1).Return([]linodego.Instance{validInstance}, nil)
client.EXPECT().ListVPCIPAddresses(gomock.Any(), gomock.Any(), gomock.Any()).Times(2).Return(noRoutesInVPC, nil)
client.EXPECT().ListVPCIPv6Addresses(gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes().Return([]linodego.VPCIP{}, nil)
client.EXPECT().UpdateInterface(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Times(1).Return(&interfaceWithVPCAndRoute, nil)
Expand Down Expand Up @@ -485,7 +486,7 @@ func TestCreateRoute(t *testing.T) {
routeController, err := newRoutes(client, instanceCache)
require.NoError(t, err)

client.EXPECT().ListInstances(gomock.Any(), nil).Times(1).Return([]linodego.Instance{validInstance}, nil)
client.EXPECT().ListInstances(gomock.Any(), &linodego.ListOptions{PageSize: linodeClient.MaxPageSize, Filter: "{}"}).Times(1).Return([]linodego.Instance{validInstance}, nil)
client.EXPECT().ListVPCIPAddresses(gomock.Any(), gomock.Any(), gomock.Any()).Times(2).Return(routesInVPC, nil)
client.EXPECT().ListVPCIPv6Addresses(gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes().Return([]linodego.VPCIP{}, nil)
err = routeController.CreateRoute(ctx, "dummy", "dummy", route)
Expand All @@ -500,7 +501,7 @@ func TestCreateRoute(t *testing.T) {
routeController, err := newRoutes(client, instanceCache)
require.NoError(t, err)

client.EXPECT().ListInstances(gomock.Any(), nil).Times(1).Return([]linodego.Instance{}, nil)
client.EXPECT().ListInstances(gomock.Any(), &linodego.ListOptions{PageSize: linodeClient.MaxPageSize, Filter: "{}"}).Times(1).Return([]linodego.Instance{}, nil)
client.EXPECT().ListVPCIPAddresses(gomock.Any(), gomock.Any(), gomock.Any()).Times(1).Return([]linodego.VPCIP{}, nil)
client.EXPECT().ListVPCIPv6Addresses(gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes().Return([]linodego.VPCIP{}, nil)
err = routeController.CreateRoute(ctx, "dummy", "dummy", route)
Expand Down Expand Up @@ -544,7 +545,7 @@ func TestDeleteRoute(t *testing.T) {
routeController, err := newRoutes(client, instanceCache)
require.NoError(t, err)

client.EXPECT().ListInstances(gomock.Any(), nil).Times(1).Return([]linodego.Instance{}, nil)
client.EXPECT().ListInstances(gomock.Any(), &linodego.ListOptions{PageSize: linodeClient.MaxPageSize, Filter: "{}"}).Times(1).Return([]linodego.Instance{}, nil)
client.EXPECT().ListVPCIPAddresses(gomock.Any(), gomock.Any(), gomock.Any()).Times(1).Return([]linodego.VPCIP{}, nil)
client.EXPECT().ListVPCIPv6Addresses(gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes().Return([]linodego.VPCIP{}, nil)
err = routeController.DeleteRoute(ctx, "dummy", route)
Expand Down Expand Up @@ -576,7 +577,7 @@ func TestDeleteRoute(t *testing.T) {
routeController, err := newRoutes(client, instanceCache)
require.NoError(t, err)

client.EXPECT().ListInstances(gomock.Any(), nil).Times(1).Return([]linodego.Instance{validInstance}, nil)
client.EXPECT().ListInstances(gomock.Any(), &linodego.ListOptions{PageSize: linodeClient.MaxPageSize, Filter: "{}"}).Times(1).Return([]linodego.Instance{validInstance}, nil)
client.EXPECT().ListVPCIPAddresses(gomock.Any(), gomock.Any(), gomock.Any()).Times(2).Return(noRoutesInVPC, nil)
client.EXPECT().ListVPCIPv6Addresses(gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes().Return([]linodego.VPCIP{}, nil)
client.EXPECT().UpdateInstanceConfigInterface(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Times(1).Return(&instanceConfigIntfWithVPCAndNoRoute, nil)
Expand All @@ -598,7 +599,7 @@ func TestDeleteRoute(t *testing.T) {
routeController, err := newRoutes(client, instanceCache)
require.NoError(t, err)

client.EXPECT().ListInstances(gomock.Any(), nil).Times(1).Return([]linodego.Instance{validInstance}, nil)
client.EXPECT().ListInstances(gomock.Any(), &linodego.ListOptions{PageSize: linodeClient.MaxPageSize, Filter: "{}"}).Times(1).Return([]linodego.Instance{validInstance}, nil)
client.EXPECT().ListVPCIPAddresses(gomock.Any(), gomock.Any(), gomock.Any()).Times(2).Return(noRoutesInVPC, nil)
client.EXPECT().ListVPCIPv6Addresses(gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes().Return([]linodego.VPCIP{}, nil)
client.EXPECT().UpdateInterface(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Times(1).Return(&interfaceWitVPCAndNoRoute, nil)
Expand Down Expand Up @@ -632,7 +633,7 @@ func TestDeleteRoute(t *testing.T) {
routeController, err := newRoutes(client, instanceCache)
require.NoError(t, err)

client.EXPECT().ListInstances(gomock.Any(), nil).Times(1).Return([]linodego.Instance{validInstance}, nil)
client.EXPECT().ListInstances(gomock.Any(), &linodego.ListOptions{PageSize: linodeClient.MaxPageSize, Filter: "{}"}).Times(1).Return([]linodego.Instance{validInstance}, nil)
client.EXPECT().ListVPCIPAddresses(gomock.Any(), gomock.Any(), gomock.Any()).Times(2).Return(routesInVPC, nil)
client.EXPECT().ListVPCIPv6Addresses(gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes().Return([]linodego.VPCIP{}, nil)
client.EXPECT().UpdateInstanceConfigInterface(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Times(1).Return(&instanceConfigIntfWithVPCAndNoRoute, nil)
Expand All @@ -649,7 +650,7 @@ func TestDeleteRoute(t *testing.T) {
routeController, err := newRoutes(client, instanceCache)
require.NoError(t, err)

client.EXPECT().ListInstances(gomock.Any(), nil).Times(1).Return([]linodego.Instance{validInstance}, nil)
client.EXPECT().ListInstances(gomock.Any(), &linodego.ListOptions{PageSize: linodeClient.MaxPageSize, Filter: "{}"}).Times(1).Return([]linodego.Instance{validInstance}, nil)
client.EXPECT().ListVPCIPAddresses(gomock.Any(), gomock.Any(), gomock.Any()).Times(2).Return(routesInVPC, nil)
client.EXPECT().ListVPCIPv6Addresses(gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes().Return([]linodego.VPCIP{}, nil)
client.EXPECT().UpdateInterface(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Times(1).Return(&interfaceWitVPCAndNoRoute, nil)
Expand Down
Loading
Loading