@@ -84,7 +84,14 @@ func fillCreateConfig(createConfig *linodego.InstanceCreateOptions, machineScope
8484 if machineScope .LinodeMachine .Spec .PrivateIP != nil {
8585 createConfig .PrivateIP = * machineScope .LinodeMachine .Spec .PrivateIP
8686 } else {
87- createConfig .PrivateIP = true
87+ if machineScope .LinodeMachine .Spec .LinodeInterfaces == nil {
88+ // Supported only for legacy network interfaces.
89+ createConfig .PrivateIP = true
90+ } else {
91+ // Network Helper is not supported for the new network interfaces.
92+ createConfig .NetworkHelper = ptr .To (false )
93+ createConfig .InterfaceGeneration = linodego .GenerationLinode
94+ }
8895 }
8996
9097 if createConfig .Tags == nil {
@@ -638,12 +645,21 @@ func getVPCLinodeInterfaceConfig(ctx context.Context, machineScope *scope.Machin
638645 }
639646
640647 // Check if a VPC interface already exists
641- for i , netInterface := range linodeInterfaces {
648+ for iface , netInterface := range linodeInterfaces {
642649 if netInterface .VPC != nil {
643- linodeInterfaces [i ].VPC .SubnetID = subnetID
650+ linodeInterfaces [iface ].VPC .SubnetID = subnetID
644651 // If IPv6 range config is not empty, add it to the interface configuration
645652 if ! isVPCInterfaceIPv6ConfigEmpty (ipv6Config ) {
646- linodeInterfaces [i ].VPC .IPv6 = ipv6Config
653+ linodeInterfaces [iface ].VPC .IPv6 = ipv6Config
654+ }
655+ if netInterface .VPC .IPv4 == nil {
656+ linodeInterfaces [iface ].VPC .IPv4 = & linodego.VPCInterfaceIPv4CreateOptions {
657+ Addresses : []linodego.VPCInterfaceIPv4AddressCreateOptions {{
658+ Primary : ptr .To (true ),
659+ NAT1To1Address : ptr .To ("auto" ),
660+ Address : "auto" ,
661+ }},
662+ }
647663 }
648664 return nil , nil //nolint:nilnil // it is important we don't return an interface if a VPC interface already exists
649665 }
@@ -656,7 +672,8 @@ func getVPCLinodeInterfaceConfig(ctx context.Context, machineScope *scope.Machin
656672 IPv4 : & linodego.VPCInterfaceIPv4CreateOptions {
657673 Addresses : []linodego.VPCInterfaceIPv4AddressCreateOptions {{
658674 Primary : ptr .To (true ),
659- NAT1To1Address : ptr .To ("any" ),
675+ NAT1To1Address : ptr .To ("auto" ),
676+ Address : "auto" ,
660677 }},
661678 },
662679 },
@@ -667,6 +684,8 @@ func getVPCLinodeInterfaceConfig(ctx context.Context, machineScope *scope.Machin
667684 vpcIntfCreateOpts .VPC .IPv6 = ipv6Config
668685 }
669686
687+ logger .Info ("Creating LinodeInterfaceCreateOptions" , "VPC" , * vpcIntfCreateOpts )
688+
670689 return vpcIntfCreateOpts , nil
671690}
672691
@@ -738,7 +757,7 @@ func getVPCLinodeInterfaceConfigFromDirectID(ctx context.Context, machineScope *
738757 IPv4 : & linodego.VPCInterfaceIPv4CreateOptions {
739758 Addresses : []linodego.VPCInterfaceIPv4AddressCreateOptions {{
740759 Primary : ptr .To (true ),
741- NAT1To1Address : ptr .To ("any " ),
760+ NAT1To1Address : ptr .To ("auto " ),
742761 }},
743762 },
744763 },
@@ -905,7 +924,6 @@ func getVPCInterfaceIPv6Config(machineScope *scope.MachineScope, numIPv6RangesIn
905924
906925// Unfortunately, this is necessary since DeepCopy can't be generated for linodego.LinodeInterfaceCreateOptions
907926// so here we manually create the options for Linode interfaces.
908- // /
909927//
910928//nolint:gocognit,cyclop,gocritic,nestif,nolintlint // Also, unfortunately, this cannot be made any reasonably simpler with how complicated the linodego struct is
911929func constructLinodeInterfaceCreateOpts (createOpts []infrav1alpha2.LinodeInterfaceCreateOptions ) []linodego.LinodeInterfaceCreateOptions {
@@ -946,7 +964,8 @@ func constructLinodeInterfaceCreateOpts(createOpts []infrav1alpha2.LinodeInterfa
946964 ipv4Addrs = []linodego.VPCInterfaceIPv4AddressCreateOptions {
947965 {
948966 Primary : ptr .To (true ),
949- NAT1To1Address : ptr .To ("any" ),
967+ NAT1To1Address : ptr .To ("auto" ),
968+ Address : "auto" , // Default to auto-assigned address
950969 },
951970 }
952971 }
@@ -1021,37 +1040,39 @@ func constructLinodeInterfaceCreateOpts(createOpts []infrav1alpha2.LinodeInterfa
10211040 return linodeInterfaces
10221041}
10231042
1043+ // for converting LinodeMachineSpec to linodego.InstanceCreateOptions. Any defaulting should be done in fillCreateConfig instead
10241044func linodeMachineSpecToInstanceCreateConfig (machineSpec infrav1alpha2.LinodeMachineSpec , machineTags []string ) * linodego.InstanceCreateOptions {
1025- interfaces := make ([]linodego.InstanceConfigInterfaceCreateOptions , len (machineSpec .Interfaces ))
1026- for idx , iface := range machineSpec .Interfaces {
1027- interfaces [idx ] = linodego.InstanceConfigInterfaceCreateOptions {
1028- IPAMAddress : iface .IPAMAddress ,
1029- Label : iface .Label ,
1030- Purpose : iface .Purpose ,
1031- Primary : iface .Primary ,
1032- SubnetID : iface .SubnetID ,
1033- IPRanges : iface .IPRanges ,
1034- }
1035- }
1036- privateIP := false
1037- if machineSpec .PrivateIP != nil {
1038- privateIP = * machineSpec .PrivateIP
1039- }
10401045 instCreateOpts := & linodego.InstanceCreateOptions {
10411046 Region : machineSpec .Region ,
10421047 Type : machineSpec .Type ,
10431048 AuthorizedKeys : machineSpec .AuthorizedKeys ,
10441049 AuthorizedUsers : machineSpec .AuthorizedUsers ,
10451050 RootPass : machineSpec .RootPass ,
10461051 Image : machineSpec .Image ,
1047- Interfaces : interfaces ,
1048- PrivateIP : privateIP ,
10491052 Tags : machineTags ,
10501053 FirewallID : machineSpec .FirewallID ,
10511054 DiskEncryption : linodego .InstanceDiskEncryption (machineSpec .DiskEncryption ),
10521055 }
1056+
1057+ if machineSpec .PrivateIP != nil {
1058+ instCreateOpts .PrivateIP = * machineSpec .PrivateIP
1059+ }
1060+
10531061 if len (machineSpec .LinodeInterfaces ) > 0 {
10541062 instCreateOpts .LinodeInterfaces = constructLinodeInterfaceCreateOpts (machineSpec .LinodeInterfaces )
1063+ } else {
1064+ interfaces := make ([]linodego.InstanceConfigInterfaceCreateOptions , len (machineSpec .Interfaces ))
1065+ for idx , iface := range machineSpec .Interfaces {
1066+ interfaces [idx ] = linodego.InstanceConfigInterfaceCreateOptions {
1067+ IPAMAddress : iface .IPAMAddress ,
1068+ Label : iface .Label ,
1069+ Purpose : iface .Purpose ,
1070+ Primary : iface .Primary ,
1071+ SubnetID : iface .SubnetID ,
1072+ IPRanges : iface .IPRanges ,
1073+ }
1074+ }
1075+ instCreateOpts .Interfaces = interfaces
10551076 }
10561077
10571078 return instCreateOpts
@@ -1478,6 +1499,14 @@ func configureFirewall(ctx context.Context, machineScope *scope.MachineScope, cr
14781499 }
14791500
14801501 createConfig .FirewallID = fwID
1502+
1503+ // If using LinodeInterfaces that needs to know about the firewall ID
1504+ if machineScope .LinodeMachine .Spec .LinodeInterfaces != nil {
1505+ for i := range createConfig .LinodeInterfaces {
1506+ createConfig .LinodeInterfaces [i ].FirewallID = ptr .To (fwID )
1507+ }
1508+ }
1509+
14811510 return nil
14821511}
14831512
0 commit comments