@@ -57,7 +57,7 @@ import (
5757const (
5858 maxBootstrapDataBytesCloudInit = 16384
5959 vlanIPFormat = "%s/11"
60- ipv6Range = "/64" // Default IPv6 range for VPC interfaces
60+ defaultNodeIPv6CIDRRange = "/64" // Default IPv6 range for VPC interfaces
6161)
6262
6363var (
@@ -463,12 +463,12 @@ func getVPCInterfaceConfig(ctx context.Context, machineScope *scope.MachineScope
463463
464464 subnetName := machineScope .LinodeCluster .Spec .Network .SubnetName // name of subnet to use
465465
466- ipv6RangeConfig := []linodego.InstanceConfigInterfaceCreateOptionsIPv6Range {}
466+ var ipv6RangeConfig []linodego.InstanceConfigInterfaceCreateOptionsIPv6Range
467467 if subnetName != "" {
468468 for _ , subnet := range linodeVPC .Spec .Subnets {
469469 if subnet .Label == subnetName {
470470 subnetID = subnet .SubnetID
471- ipv6RangeConfig = getIPv6RangeConfig (subnet .IPv6 )
471+ ipv6RangeConfig = machineIPv6RangeConfig (subnet .IPv6 )
472472 break
473473 }
474474 }
@@ -478,7 +478,7 @@ func getVPCInterfaceConfig(ctx context.Context, machineScope *scope.MachineScope
478478 }
479479 } else {
480480 subnetID = linodeVPC .Spec .Subnets [0 ].SubnetID // get first subnet if nothing specified
481- ipv6RangeConfig = getIPv6RangeConfig (linodeVPC .Spec .Subnets [0 ].IPv6 )
481+ ipv6RangeConfig = machineIPv6RangeConfig (linodeVPC .Spec .Subnets [0 ].IPv6 )
482482 }
483483
484484 if subnetID == 0 {
@@ -506,6 +506,7 @@ func getVPCInterfaceConfig(ctx context.Context, machineScope *scope.MachineScope
506506 },
507507 }
508508
509+ // If IPv6 range config is not empty, add it to the interface configuration
509510 if len (ipv6RangeConfig ) > 0 {
510511 vpcIntfCreateOpts .IPv6 = & linodego.InstanceConfigInterfaceCreateOptionsIPv6 {
511512 Ranges : ipv6RangeConfig ,
@@ -537,12 +538,12 @@ func getVPCInterfaceConfigFromDirectID(ctx context.Context, machineScope *scope.
537538 }
538539
539540 // If subnet name specified, find matching subnet; otherwise use first subnet
540- ipv6RangeConfig := []linodego.InstanceConfigInterfaceCreateOptionsIPv6Range {}
541+ var ipv6RangeConfig []linodego.InstanceConfigInterfaceCreateOptionsIPv6Range
541542 if subnetName != "" {
542543 for _ , subnet := range vpc .Subnets {
543544 if subnet .Label == subnetName {
544545 subnetID = subnet .ID
545- ipv6RangeConfig = getIPv6RangeConfig (subnet .IPv6 )
546+ ipv6RangeConfig = machineIPv6RangeConfig (subnet .IPv6 )
546547 break
547548 }
548549 }
@@ -551,7 +552,7 @@ func getVPCInterfaceConfigFromDirectID(ctx context.Context, machineScope *scope.
551552 }
552553 } else {
553554 subnetID = vpc .Subnets [0 ].ID
554- ipv6RangeConfig = getIPv6RangeConfig (vpc .Subnets [0 ].IPv6 )
555+ ipv6RangeConfig = machineIPv6RangeConfig (vpc .Subnets [0 ].IPv6 )
555556 }
556557
557558 // Check if a VPC interface already exists
@@ -577,7 +578,7 @@ func getVPCInterfaceConfigFromDirectID(ctx context.Context, machineScope *scope.
577578 },
578579 }
579580
580- // If IPv6 ranges are specified , add them to the interface configuration
581+ // If IPv6 range config is not empty , add it to the interface configuration
581582 if len (ipv6RangeConfig ) > 0 {
582583 vpcIntfCreateOpts .IPv6 = & linodego.InstanceConfigInterfaceCreateOptionsIPv6 {
583584 Ranges : ipv6RangeConfig ,
@@ -587,15 +588,17 @@ func getVPCInterfaceConfigFromDirectID(ctx context.Context, machineScope *scope.
587588 return vpcIntfCreateOpts , nil
588589}
589590
590- // getIPv6RangeConfig returns the IPv6 range configuration for a given slice of VPC IPv6 ranges
591- func getIPv6RangeConfig (ipv6 []linodego.VPCIPv6Range ) []linodego.InstanceConfigInterfaceCreateOptionsIPv6Range {
592- ipv6RangeConfig := []linodego.InstanceConfigInterfaceCreateOptionsIPv6Range {}
593- if len (ipv6 ) > 0 {
594- ipv6RangeConfig = append (ipv6RangeConfig , linodego.InstanceConfigInterfaceCreateOptionsIPv6Range {
595- Range : ptr .To (ipv6Range ),
596- })
591+ // machineIPv6RangeConfig returns the IPv6 range configuration if subnet has IPv6 ranges
592+ // for now, we support only a single IPv6 range per subnet. If this changes, we may need to adjust this logic.
593+ func machineIPv6RangeConfig (ipv6 []linodego.VPCIPv6Range ) []linodego.InstanceConfigInterfaceCreateOptionsIPv6Range {
594+ if len (ipv6 ) == 0 {
595+ return nil // No IPv6 ranges available in subnet, return empty slice
596+ }
597+ return []linodego.InstanceConfigInterfaceCreateOptionsIPv6Range {
598+ {
599+ Range : ptr .To (defaultNodeIPv6CIDRRange ),
600+ },
597601 }
598- return ipv6RangeConfig
599602}
600603
601604func linodeMachineSpecToInstanceCreateConfig (machineSpec infrav1alpha2.LinodeMachineSpec , machineTags []string ) * linodego.InstanceCreateOptions {
0 commit comments