Skip to content

Commit 3d15db2

Browse files
committed
remove the flag but need to make an API call instead now to determine which interface generation to use
1 parent f34ebf2 commit 3d15db2

File tree

9 files changed

+62
-64
lines changed

9 files changed

+62
-64
lines changed

cloud/linode/cloud.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ var Options struct {
4949
LinodeExternalNetwork *net.IPNet
5050
NodeBalancerTags []string
5151
DefaultNBType string
52-
UseLinodeInterfaces bool
5352
NodeBalancerBackendIPv4Subnet string
5453
NodeBalancerBackendIPv4SubnetID int
5554
NodeBalancerBackendIPv4SubnetName string

cloud/linode/nodeipamcontroller.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ func startNodeIpamController(stopCh <-chan struct{}, cloud *linodeCloud, nodeInf
8787
nodeCIDRMaskSizes,
8888
ipam.CloudAllocatorType,
8989
Options.DisableIPv6NodeCIDRAllocation,
90-
Options.UseLinodeInterfaces,
9190
)
9291
if err != nil {
9392
return err

cloud/linode/route_controller.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,9 @@ func (rc *routeCache) refreshRoutes(ctx context.Context, client client.Client) {
5959
}
6060

6161
type routes struct {
62-
client client.Client
63-
instances *instances
64-
routeCache *routeCache
65-
useLinodeInterfaces bool
62+
client client.Client
63+
instances *instances
64+
routeCache *routeCache
6665
}
6766

6867
func newRoutes(client client.Client, instanceCache *instances) (cloudprovider.Routes, error) {
@@ -85,7 +84,6 @@ func newRoutes(client client.Client, instanceCache *instances) (cloudprovider.Ro
8584
routes: make(map[int][]linodego.VPCIP, 0),
8685
ttl: time.Duration(timeout) * time.Second,
8786
},
88-
useLinodeInterfaces: Options.UseLinodeInterfaces,
8987
}, nil
9088
}
9189

@@ -242,7 +240,7 @@ func (r *routes) DeleteRoute(ctx context.Context, clusterName string, route *clo
242240

243241
// handleInterfaces updates the VPC interface with adding or deleting routes
244242
func (r *routes) handleInterfaces(ctx context.Context, intfRoutes []string, linodeInterfaceRoutes []linodego.VPCInterfaceIPv4RangeCreateOptions, instance *linodego.Instance, intfVPCIP linodego.VPCIP, route *cloudprovider.Route) error {
245-
if Options.UseLinodeInterfaces {
243+
if instance.InterfaceGeneration == linodego.GenerationLinode {
246244
interfaceUpdateOptions := linodego.LinodeInterfaceUpdateOptions{
247245
VPC: &linodego.VPCInterfaceCreateOptions{
248246
IPv4: &linodego.VPCInterfaceIPv4CreateOptions{Ranges: linodeInterfaceRoutes},

cloud/linode/route_controller_test.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,6 @@ func TestCreateRoute(t *testing.T) {
323323
Options.VPCNames = []string{"dummy"}
324324
vpcIDs["dummy"] = 1
325325
Options.EnableRouteController = true
326-
Options.UseLinodeInterfaces = false
327326

328327
nodeID := 123
329328
name := "mock-instance"
@@ -399,7 +398,7 @@ func TestCreateRoute(t *testing.T) {
399398
},
400399
},
401400
}
402-
Options.UseLinodeInterfaces = true
401+
validInstance.InterfaceGeneration = linodego.GenerationLinode
403402
t.Run("should return no error if instance exists, connected to VPC we add a route with linode interfaces", func(t *testing.T) {
404403
ctrl := gomock.NewController(t)
405404
defer ctrl.Finish()
@@ -421,7 +420,7 @@ func TestCreateRoute(t *testing.T) {
421420
err = routeController.CreateRoute(ctx, "dummy", "dummy", route)
422421
assert.NoError(t, err)
423422
})
424-
Options.UseLinodeInterfaces = false
423+
validInstance.InterfaceGeneration = ""
425424

426425
v6Route := &cloudprovider.Route{
427426
Name: "route2",
@@ -510,7 +509,6 @@ func TestDeleteRoute(t *testing.T) {
510509
Options.VPCNames = []string{"dummy"}
511510
vpcIDs["dummy"] = 1
512511
Options.EnableRouteController = true
513-
Options.UseLinodeInterfaces = false
514512

515513
ctx := t.Context()
516514

@@ -588,7 +586,7 @@ func TestDeleteRoute(t *testing.T) {
588586
VPC: &linodego.VPCInterface{IPv4: linodego.VPCInterfaceIPv4{Ranges: nil}},
589587
}
590588

591-
Options.UseLinodeInterfaces = true
589+
validInstance.InterfaceGeneration = linodego.GenerationLinode
592590
t.Run("should return no error if instance exists, connected to VPC, route doesn't exist and we try to delete route with linode interfaces", func(t *testing.T) {
593591
ctrl := gomock.NewController(t)
594592
defer ctrl.Finish()
@@ -604,7 +602,7 @@ func TestDeleteRoute(t *testing.T) {
604602
err = routeController.DeleteRoute(ctx, "dummy", route)
605603
assert.NoError(t, err)
606604
})
607-
Options.UseLinodeInterfaces = false
605+
validInstance.InterfaceGeneration = ""
608606

609607
routesInVPC := []linodego.VPCIP{
610608
{
@@ -639,7 +637,7 @@ func TestDeleteRoute(t *testing.T) {
639637
assert.NoError(t, err)
640638
})
641639

642-
Options.UseLinodeInterfaces = true
640+
validInstance.InterfaceGeneration = linodego.GenerationLinode
643641
t.Run("should return no error if instance exists, connected to VPC and route is deleted with linode interfaces", func(t *testing.T) {
644642
ctrl := gomock.NewController(t)
645643
defer ctrl.Finish()

cloud/nodeipam/ipam/cidr_allocator.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,6 @@ type CIDRAllocatorParams struct {
9494
// NodeCIDRMaskSizes is list of node cidr mask sizes.
9595
NodeCIDRMaskSizes []int
9696
DisableIPv6NodeCIDRAllocation bool
97-
// UseLinodeInterfaces indicates whether to use Linode interfaces instead of legacy configuration interfaces.
98-
UseLinodeInterfaces bool
9997
}
10098

10199
// New creates a new CIDR range allocator.

cloud/nodeipam/ipam/cloud_allocator.go

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,6 @@ type cloudAllocator struct {
7070
nodeCIDRMaskSizeIPv6 int
7171
// disableIPv6NodeCIDRAllocation is true if we should not allocate IPv6 CIDRs for nodes.
7272
disableIPv6NodeCIDRAllocation bool
73-
74-
// useLinodeInterfaces is true if we should use Linode interfaces.
75-
useLinodeInterfaces bool
7673
}
7774

7875
const providerIDPrefix = "linode://"
@@ -112,7 +109,6 @@ func NewLinodeCIDRAllocator(ctx context.Context, linodeClient linode.Client, cli
112109
queue: workqueue.NewNamedRateLimitingQueue(workqueue.DefaultTypedControllerRateLimiter[any](), "cidrallocator_node"),
113110
nodeCIDRMaskSizeIPv6: allocatorParams.NodeCIDRMaskSizes[1],
114111
disableIPv6NodeCIDRAllocation: allocatorParams.DisableIPv6NodeCIDRAllocation,
115-
useLinodeInterfaces: allocatorParams.UseLinodeInterfaces,
116112
}
117113

118114
if allocatorParams.ServiceCIDR != nil {
@@ -370,42 +366,47 @@ func (c *cloudAllocator) allocateIPv6CIDR(ctx context.Context, node *v1.Node) (*
370366
return nil, fmt.Errorf("failed to parse Linode ID from ProviderID %s: %w", node.Spec.ProviderID, err)
371367
}
372368

369+
// fetch the instance so we can determine which interface generation to use
370+
instance, err := c.linodeClient.GetInstance(ctx, id)
371+
if err != nil {
372+
return nil, fmt.Errorf("failed get linode with id %d: %w", id, err)
373+
}
373374
ipv6Range := ""
374-
if !c.useLinodeInterfaces {
375-
// Retrieve the instance configuration for the Linode ID
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)
375+
if instance.InterfaceGeneration == linodego.GenerationLinode {
376+
ifaces, listErr := c.linodeClient.ListInterfaces(ctx, id, &linodego.ListOptions{})
377+
if listErr != nil || len(ifaces) == 0 {
378+
return nil, fmt.Errorf("failed to list interfaces: %w", listErr)
379379
}
380-
381-
for _, iface := range configs[0].Interfaces {
382-
if iface.Purpose == linodego.InterfacePurposeVPC {
383-
ipv6Range = getIPv6RangeFromInterface(iface)
380+
for _, iface := range ifaces {
381+
if iface.VPC != nil {
382+
ipv6Range = getIPv6RangeFromLinodeInterface(iface)
384383
if ipv6Range != "" {
385384
break
386385
}
387386
}
388387
}
389388

390389
if ipv6Range == "" {
391-
return nil, fmt.Errorf("failed to find ipv6 range in instance config: %v", configs[0])
390+
return nil, fmt.Errorf("failed to find ipv6 range in Linode interfaces: %v", ifaces)
392391
}
393392
} else {
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)
393+
// Retrieve the instance configuration for the Linode ID
394+
configs, listErr := c.linodeClient.ListInstanceConfigs(ctx, id, &linodego.ListOptions{})
395+
if listErr != nil || len(configs) == 0 {
396+
return nil, fmt.Errorf("failed to list instance configs: %w", listErr)
397397
}
398-
for _, iface := range ifaces {
399-
if iface.VPC != nil {
400-
ipv6Range = getIPv6RangeFromLinodeInterface(iface)
398+
399+
for _, iface := range configs[0].Interfaces {
400+
if iface.Purpose == linodego.InterfacePurposeVPC {
401+
ipv6Range = getIPv6RangeFromInterface(iface)
401402
if ipv6Range != "" {
402403
break
403404
}
404405
}
405406
}
406407

407408
if ipv6Range == "" {
408-
return nil, fmt.Errorf("failed to find ipv6 range in Linode interfaces: %v", ifaces)
409+
return nil, fmt.Errorf("failed to find ipv6 range in instance config: %v", configs[0])
409410
}
410411
}
411412

cloud/nodeipam/ipam/cloud_allocator_test.go

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ type testCase struct {
4646
expectedAllocatedCIDR map[int]string
4747
allocatedCIDRs map[int][]string
4848
// should controller creation fail?
49-
ctrlCreateFail bool
50-
useLinodeInterfaces bool
49+
ctrlCreateFail bool
50+
instance *linodego.Instance
5151
}
5252

5353
func TestOccupyPreExistingCIDR(t *testing.T) {
@@ -182,6 +182,7 @@ func TestAllocateOrOccupyCIDRSuccess(t *testing.T) {
182182
{
183183
description: "When there's no ServiceCIDR return first CIDR in range",
184184
linodeClient: client,
185+
instance: &linodego.Instance{ID: 12345},
185186
fakeNodeHandler: &testutil.FakeNodeHandler{
186187
Existing: []*v1.Node{
187188
{
@@ -220,6 +221,7 @@ func TestAllocateOrOccupyCIDRSuccess(t *testing.T) {
220221
{
221222
description: "Correctly filter out ServiceCIDR",
222223
linodeClient: client,
224+
instance: &linodego.Instance{ID: 12345},
223225
fakeNodeHandler: &testutil.FakeNodeHandler{
224226
Existing: []*v1.Node{
225227
{
@@ -262,6 +264,7 @@ func TestAllocateOrOccupyCIDRSuccess(t *testing.T) {
262264
{
263265
description: "Correctly ignore already allocated CIDRs",
264266
linodeClient: client,
267+
instance: &linodego.Instance{ID: 12345},
265268
fakeNodeHandler: &testutil.FakeNodeHandler{
266269
Existing: []*v1.Node{
267270
{
@@ -306,6 +309,7 @@ func TestAllocateOrOccupyCIDRSuccess(t *testing.T) {
306309
{
307310
description: "no double counting",
308311
linodeClient: client,
312+
instance: &linodego.Instance{ID: 12345},
309313
fakeNodeHandler: &testutil.FakeNodeHandler{
310314
Existing: []*v1.Node{
311315
{
@@ -376,9 +380,9 @@ func TestAllocateOrOccupyCIDRSuccess(t *testing.T) {
376380
},
377381
},
378382
{
379-
description: "When there's no ServiceCIDR return first CIDR in range with linode interfaces",
380-
linodeClient: client,
381-
useLinodeInterfaces: true,
383+
description: "When there's no ServiceCIDR return first CIDR in range with linode interfaces",
384+
linodeClient: client,
385+
instance: &linodego.Instance{ID: 12345, InterfaceGeneration: linodego.GenerationLinode},
382386
fakeNodeHandler: &testutil.FakeNodeHandler{
383387
Existing: []*v1.Node{
384388
{
@@ -415,9 +419,9 @@ func TestAllocateOrOccupyCIDRSuccess(t *testing.T) {
415419
},
416420
},
417421
{
418-
description: "Correctly filter out ServiceCIDR with linode interfaces",
419-
linodeClient: client,
420-
useLinodeInterfaces: true,
422+
description: "Correctly filter out ServiceCIDR with linode interfaces",
423+
linodeClient: client,
424+
instance: &linodego.Instance{ID: 12345, InterfaceGeneration: linodego.GenerationLinode},
421425
fakeNodeHandler: &testutil.FakeNodeHandler{
422426
Existing: []*v1.Node{
423427
{
@@ -458,9 +462,9 @@ func TestAllocateOrOccupyCIDRSuccess(t *testing.T) {
458462
},
459463
},
460464
{
461-
description: "Correctly ignore already allocated CIDRs with linode interfaces",
462-
linodeClient: client,
463-
useLinodeInterfaces: true,
465+
description: "Correctly ignore already allocated CIDRs with linode interfaces",
466+
linodeClient: client,
467+
instance: &linodego.Instance{ID: 12345, InterfaceGeneration: linodego.GenerationLinode},
464468
fakeNodeHandler: &testutil.FakeNodeHandler{
465469
Existing: []*v1.Node{
466470
{
@@ -503,9 +507,9 @@ func TestAllocateOrOccupyCIDRSuccess(t *testing.T) {
503507
},
504508
},
505509
{
506-
description: "no double counting with linode interfaces",
507-
linodeClient: client,
508-
useLinodeInterfaces: true,
510+
description: "no double counting with linode interfaces",
511+
linodeClient: client,
512+
instance: &linodego.Instance{ID: 12345, InterfaceGeneration: linodego.GenerationLinode},
509513
fakeNodeHandler: &testutil.FakeNodeHandler{
510514
Existing: []*v1.Node{
511515
{
@@ -582,7 +586,8 @@ func TestAllocateOrOccupyCIDRSuccess(t *testing.T) {
582586
testFunc := func(tc testCase) {
583587
fakeNodeInformer := test.FakeNodeInformer(tc.fakeNodeHandler)
584588
nodeList, _ := tc.fakeNodeHandler.List(tCtx, metav1.ListOptions{})
585-
if tc.useLinodeInterfaces {
589+
tc.linodeClient.EXPECT().GetInstance(gomock.Any(), gomock.Any()).AnyTimes().Return(tc.instance, nil)
590+
if tc.instance.InterfaceGeneration == linodego.GenerationLinode {
586591
tc.linodeClient.EXPECT().ListInterfaces(gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes().Return([]linodego.LinodeInterface{
587592
{
588593
ID: 12345,
@@ -780,7 +785,7 @@ type releaseTestCase struct {
780785
expectedAllocatedCIDRSecondRound map[int]string
781786
allocatedCIDRs map[int][]string
782787
cidrsToRelease [][]string
783-
useLinodeInterfaces bool
788+
instance *linodego.Instance
784789
}
785790

786791
func TestReleaseCIDRSuccess(t *testing.T) {
@@ -798,6 +803,7 @@ func TestReleaseCIDRSuccess(t *testing.T) {
798803
{
799804
description: "Correctly release preallocated CIDR",
800805
linodeClient: client,
806+
instance: &linodego.Instance{ID: 12345},
801807
fakeNodeHandler: &testutil.FakeNodeHandler{
802808
Existing: []*v1.Node{
803809
{
@@ -842,6 +848,7 @@ func TestReleaseCIDRSuccess(t *testing.T) {
842848
{
843849
description: "Correctly recycle CIDR",
844850
linodeClient: client,
851+
instance: &linodego.Instance{ID: 12345},
845852
fakeNodeHandler: &testutil.FakeNodeHandler{
846853
Existing: []*v1.Node{
847854
{
@@ -886,9 +893,9 @@ func TestReleaseCIDRSuccess(t *testing.T) {
886893
},
887894
},
888895
{
889-
description: "Correctly release preallocated CIDR with linode interfaces",
890-
useLinodeInterfaces: true,
891-
linodeClient: client,
896+
description: "Correctly release preallocated CIDR with linode interfaces",
897+
instance: &linodego.Instance{ID: 12345, InterfaceGeneration: linodego.GenerationLinode},
898+
linodeClient: client,
892899
fakeNodeHandler: &testutil.FakeNodeHandler{
893900
Existing: []*v1.Node{
894901
{
@@ -931,9 +938,9 @@ func TestReleaseCIDRSuccess(t *testing.T) {
931938
},
932939
},
933940
{
934-
description: "Correctly recycle CIDR with linode interfaces",
935-
useLinodeInterfaces: true,
936-
linodeClient: client,
941+
description: "Correctly recycle CIDR with linode interfaces",
942+
instance: &linodego.Instance{ID: 12345, InterfaceGeneration: linodego.GenerationLinode},
943+
linodeClient: client,
937944
fakeNodeHandler: &testutil.FakeNodeHandler{
938945
Existing: []*v1.Node{
939946
{
@@ -980,7 +987,8 @@ func TestReleaseCIDRSuccess(t *testing.T) {
980987
}
981988
logger, tCtx := ktesting.NewTestContext(t)
982989
testFunc := func(tc releaseTestCase) {
983-
if tc.useLinodeInterfaces {
990+
tc.linodeClient.EXPECT().GetInstance(gomock.Any(), gomock.Any()).AnyTimes().Return(tc.instance, nil)
991+
if tc.instance.InterfaceGeneration == linodego.GenerationLinode {
984992
tc.linodeClient.EXPECT().ListInterfaces(gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes().Return([]linodego.LinodeInterface{
985993
{
986994
ID: 12345,

cloud/nodeipam/node_ipam_controller.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ func NewNodeIpamController(
7171
nodeCIDRMaskSizes []int,
7272
allocatorType ipam.CIDRAllocatorType,
7373
disableIPv6NodeCIDRAllocation bool,
74-
useLinodeInterfaces bool,
7574
) (*Controller, error) {
7675
if kubeClient == nil {
7776
return nil, fmt.Errorf("kubeClient is nil when starting Controller")
@@ -107,7 +106,6 @@ func NewNodeIpamController(
107106
SecondaryServiceCIDR: ic.secondaryServiceCIDR,
108107
NodeCIDRMaskSizes: nodeCIDRMaskSizes,
109108
DisableIPv6NodeCIDRAllocation: disableIPv6NodeCIDRAllocation,
110-
UseLinodeInterfaces: useLinodeInterfaces,
111109
}
112110

113111
ic.cidrAllocator, err = ipam.New(ctx, ic.linodeClient, kubeClient, cloud, nodeInformer, ic.allocatorType, allocatorParams)

main.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ func main() {
9191
command.Flags().StringVar(&linode.Options.BGPNodeSelector, "bgp-node-selector", "", "node selector to use to perform shared IP fail-over with BGP (e.g. cilium-bgp-peering=true")
9292
command.Flags().StringVar(&linode.Options.IpHolderSuffix, "ip-holder-suffix", "", "suffix to append to the ip holder name when using shared IP fail-over with BGP (e.g. ip-holder-suffix=my-cluster-name")
9393
command.Flags().StringVar(&linode.Options.DefaultNBType, "default-nodebalancer-type", string(linodego.NBTypeCommon), "default type of NodeBalancer to create (options: common, premium)")
94-
command.Flags().BoolVar(&linode.Options.UseLinodeInterfaces, "use-linode-interfaces", false, "use Linode interfaces instead of legacy configuration interfaces (requires Linode Interfaces to be enabled on the account)")
9594
command.Flags().StringVar(&linode.Options.NodeBalancerBackendIPv4Subnet, "nodebalancer-backend-ipv4-subnet", "", "ipv4 subnet to use for NodeBalancer backends")
9695
command.Flags().StringSliceVar(&linode.Options.NodeBalancerTags, "nodebalancer-tags", []string{}, "Linode tags to apply to all NodeBalancers")
9796
command.Flags().BoolVar(&linode.Options.EnableIPv6ForLoadBalancers, "enable-ipv6-for-loadbalancers", false, "set both IPv4 and IPv6 addresses for all LoadBalancer services (when disabled, only IPv4 is used)")

0 commit comments

Comments
 (0)