@@ -489,7 +489,7 @@ func getVPCInterfaceConfig(ctx context.Context, machineScope *scope.MachineScope
489489 if netInterface .Purpose == linodego .InterfacePurposeVPC {
490490 interfaces [i ].SubnetID = & subnetID
491491 // If IPv6 range config is not empty, add it to the interface configuration
492- if ipv6Config != nil {
492+ if ! isIPv6ConfigEmpty ( ipv6Config ) {
493493 interfaces [i ].IPv6 = ipv6Config
494494 }
495495 return nil , nil //nolint:nilnil // it is important we don't return an interface if a VPC interface already exists
@@ -506,7 +506,7 @@ func getVPCInterfaceConfig(ctx context.Context, machineScope *scope.MachineScope
506506 }
507507
508508 // If IPv6 config is not empty, add it to the interface configuration
509- if ipv6Config != nil {
509+ if ! isIPv6ConfigEmpty ( ipv6Config ) {
510510 vpcIntfCreateOpts .IPv6 = ipv6Config
511511 }
512512
@@ -556,7 +556,7 @@ func getVPCInterfaceConfigFromDirectID(ctx context.Context, machineScope *scope.
556556 for i , netInterface := range interfaces {
557557 if netInterface .Purpose == linodego .InterfacePurposeVPC {
558558 interfaces [i ].SubnetID = & subnetID
559- if ipv6Config != nil {
559+ if ! isIPv6ConfigEmpty ( ipv6Config ) {
560560 interfaces [i ].IPv6 = ipv6Config
561561 }
562562 return nil , nil //nolint:nilnil // it is important we don't return an interface if a VPC interface already exists
@@ -574,25 +574,34 @@ func getVPCInterfaceConfigFromDirectID(ctx context.Context, machineScope *scope.
574574 }
575575
576576 // If IPv6 range config is not empty, add it to the interface configuration
577- if ipv6Config != nil {
577+ if ! isIPv6ConfigEmpty ( ipv6Config ) {
578578 vpcIntfCreateOpts .IPv6 = ipv6Config
579579 }
580580
581581 return vpcIntfCreateOpts , nil
582582}
583583
584- // getMachineIPv6Config returns the IPv6 configuration if subnet has IPv6 ranges.
584+ // isIPv6ConfigEmpty checks if the IPv6 configuration is empty.
585+ func isIPv6ConfigEmpty (opts * linodego.InstanceConfigInterfaceCreateOptionsIPv6 ) bool {
586+ return opts == nil ||
587+ len (opts .SLAAC ) == 0 &&
588+ len (opts .Ranges ) == 0 &&
589+ (opts .IsPublic == nil )
590+ }
591+
592+ // getMachineIPv6Config returns the IPv6 configuration for a LinodeMachine.
585593// It checks the LinodeMachine's IPv6Options for SLAAC and Ranges settings.
586594// If `EnableSLAAC` is set, it will enable SLAAC with the default IPv6 CIDR range.
587595// If `EnableRanges` is set, it will enable IPv6 ranges with the default IPv6 CIDR range.
588596// If `IsPublicIPv6` is set, it will be used to determine if the IPv6 range should be publicly routable or not.
589597func getMachineIPv6Config (machineScope * scope.MachineScope , numIPv6RangesInSubnet int ) * linodego.InstanceConfigInterfaceCreateOptionsIPv6 {
598+ intfOpts := & linodego.InstanceConfigInterfaceCreateOptionsIPv6 {}
599+
590600 // If there are no IPv6 ranges in the subnet or if IPv6 options are not specified, return nil.
591601 if numIPv6RangesInSubnet == 0 || machineScope .LinodeMachine .Spec .IPv6Options == nil {
592- return nil
602+ return intfOpts
593603 }
594604
595- intfOpts := & linodego.InstanceConfigInterfaceCreateOptionsIPv6 {}
596605 if machineScope .LinodeMachine .Spec .IPv6Options .IsPublicIPv6 != nil {
597606 // Set the public IPv6 flag based on the IsPublicIPv6 specification.
598607 intfOpts .IsPublic = machineScope .LinodeMachine .Spec .IPv6Options .IsPublicIPv6
0 commit comments