@@ -266,27 +266,11 @@ func buildInstanceAddrs(ctx context.Context, machineScope *scope.MachineScope, i
266266 }
267267
268268 if machineScope .LinodeCluster .Spec .Network .UseVlan {
269- switch {
270- case machineScope .LinodeCluster .Spec .Network .UseNewNetworkInterfaces :
271- // TODO
272- default :
273- // get the default instance config
274- configs , err := machineScope .LinodeClient .ListInstanceConfigs (ctx , instanceID , & linodego.ListOptions {})
275- if err != nil || len (configs ) == 0 {
276- return nil , fmt .Errorf ("list instance configs: %w" , err )
277- }
278-
279- // Iterate over interfaces in config and find VLAN specific ips
280- for _ , iface := range configs [0 ].Interfaces {
281- if iface .Purpose == linodego .InterfacePurposeVLAN {
282- // vlan addresses have a /11 appended to them - we should strip it out.
283- ips = append (ips , clusterv1.MachineAddress {
284- Address : netip .MustParsePrefix (iface .IPAMAddress ).Addr ().String (),
285- Type : clusterv1 .MachineInternalIP ,
286- })
287- }
288- }
269+ vlanIps , err := handleVlanIps (ctx , machineScope , instanceID )
270+ if err != nil {
271+ return nil , fmt .Errorf ("handle vlan ips: %w" , err )
289272 }
273+ ips = append (ips , vlanIps ... )
290274 }
291275
292276 // if a node has private ip, store it as well
@@ -302,6 +286,46 @@ func buildInstanceAddrs(ctx context.Context, machineScope *scope.MachineScope, i
302286 return ips , nil
303287}
304288
289+ func handleVlanIps (ctx context.Context , machineScope * scope.MachineScope , instanceID int ) ([]clusterv1.MachineAddress , error ) {
290+ ips := []clusterv1.MachineAddress {}
291+ switch {
292+ case machineScope .LinodeCluster .Spec .Network .UseNewNetworkInterfaces :
293+ ifaces , err := machineScope .LinodeClient .ListInterfaces (ctx , instanceID , & linodego.ListOptions {})
294+ if err != nil || len (ifaces ) == 0 {
295+ return ips , fmt .Errorf ("list interfaces: %w" , err )
296+ }
297+ // Iterate over interfaces in config and find VLAN specific ips
298+ for _ , iface := range ifaces {
299+ if iface .VLAN != nil {
300+ // vlan addresses have a /11 appended to them - we should strip it out.
301+ ips = append (ips , clusterv1.MachineAddress {
302+ Address : netip .MustParsePrefix (* iface .VLAN .IPAMAddress ).Addr ().String (),
303+ Type : clusterv1 .MachineInternalIP ,
304+ })
305+ }
306+ }
307+ default :
308+ // get the default instance config
309+ configs , err := machineScope .LinodeClient .ListInstanceConfigs (ctx , instanceID , & linodego.ListOptions {})
310+ if err != nil || len (configs ) == 0 {
311+ return ips , fmt .Errorf ("list instance configs: %w" , err )
312+ }
313+
314+ // Iterate over interfaces in config and find VLAN specific ips
315+ for _ , iface := range configs [0 ].Interfaces {
316+ if iface .Purpose == linodego .InterfacePurposeVLAN {
317+ // vlan addresses have a /11 appended to them - we should strip it out.
318+ ips = append (ips , clusterv1.MachineAddress {
319+ Address : netip .MustParsePrefix (iface .IPAMAddress ).Addr ().String (),
320+ Type : clusterv1 .MachineInternalIP ,
321+ })
322+ }
323+ }
324+ }
325+
326+ return ips , nil
327+ }
328+
305329func linodeClusterToLinodeMachines (logger logr.Logger , tracedClient client.Client ) handler.MapFunc {
306330 logger = logger .WithName ("LinodeMachineReconciler" ).WithName ("linodeClusterToLinodeMachines" )
307331
@@ -1281,7 +1305,8 @@ func getVPCRefFromScope(machineScope *scope.MachineScope) *corev1.ObjectReferenc
12811305
12821306// configureVlanInterface adds a VLAN interface to the configuration
12831307func configureVlanInterface (ctx context.Context , machineScope * scope.MachineScope , createConfig * linodego.InstanceCreateOptions , logger logr.Logger ) error {
1284- if machineScope .LinodeCluster .Spec .Network .UseNewNetworkInterfaces {
1308+ switch {
1309+ case machineScope .LinodeCluster .Spec .Network .UseNewNetworkInterfaces :
12851310 iface , err := getVlanLinodeInterfaceConfig (ctx , machineScope , createConfig .LinodeInterfaces , logger )
12861311 if err != nil {
12871312 logger .Error (err , "Failed to get VLAN interface config" )
@@ -1292,7 +1317,7 @@ func configureVlanInterface(ctx context.Context, machineScope *scope.MachineScop
12921317 // add VLAN interface as first interface
12931318 createConfig .LinodeInterfaces = slices .Insert (createConfig .LinodeInterfaces , 0 , * iface )
12941319 }
1295- } else {
1320+ default :
12961321 iface , err := getVlanInterfaceConfig (ctx , machineScope , createConfig .Interfaces , logger )
12971322 if err != nil {
12981323 logger .Error (err , "Failed to get VLAN interface config" )
0 commit comments