@@ -484,28 +484,13 @@ func (l *loadbalancers) updateNodeBalancer(
484484 klog .Infof ("No preexisting nodebalancer for port %v found." , port .Port )
485485 }
486486
487+ useIPv6Backends := resolveIPv6NodeBalancerBackendState (service )
487488 // Add all of the Nodes to the config
488- subnetID := 0
489- if options .Options .NodeBalancerBackendIPv4SubnetID != 0 {
490- subnetID = options .Options .NodeBalancerBackendIPv4SubnetID
491- }
492- backendIPv4Range , ok := service .GetAnnotations ()[annotations .NodeBalancerBackendIPv4Range ]
493- if ok {
494- if err = validateNodeBalancerBackendIPv4Range (backendIPv4Range ); err != nil {
495- return err
496- }
497- }
498- if len (options .Options .VPCNames ) > 0 && ! options .Options .DisableNodeBalancerVPCBackends {
499- var id int
500- id , err = l .getSubnetIDForSVC (ctx , service )
501- if err != nil {
502- sentry .CaptureError (ctx , err )
503- return fmt .Errorf ("Error getting subnet ID for service %s: %w" , service .Name , err )
504- }
505- subnetID = id
489+ subnetID , err := l .getBackendSubnetID (ctx , service , useIPv6Backends )
490+ if err != nil {
491+ sentry .CaptureError (ctx , err )
492+ return fmt .Errorf ("Error getting subnet ID for service %s: %w" , service .Name , err )
506493 }
507-
508- useIPv6Backends := resolveIPv6NodeBalancerBackendState (service )
509494 newNBNodes , err := l .buildNodeBalancerConfigNodes (service , nodes , port .NodePort , subnetID , useIPv6Backends , newNBCfg .Protocol , oldNBNodeIDs )
510495 if err != nil {
511496 sentry .CaptureError (ctx , err )
@@ -937,6 +922,7 @@ func (l *loadbalancers) getSubnetIDByVPCAndSubnetNames(ctx context.Context, vpcN
937922
938923func (l * loadbalancers ) createNodeBalancer (ctx context.Context , clusterName string , service * v1.Service , configs []* linodego.NodeBalancerConfigCreateOptions ) (lb * linodego.NodeBalancer , err error ) {
939924 connThrottle := getConnectionThrottle (service )
925+ useIPv6Backends := resolveIPv6NodeBalancerBackendState (service )
940926
941927 label := l .GetLoadBalancerName (ctx , clusterName , service )
942928 tags := l .GetLoadBalancerTags (ctx , clusterName , service )
@@ -950,7 +936,7 @@ func (l *loadbalancers) createNodeBalancer(ctx context.Context, clusterName stri
950936 Type : nbType ,
951937 }
952938
953- if len (options .Options .VPCNames ) > 0 && ! options .Options .DisableNodeBalancerVPCBackends {
939+ if ! useIPv6Backends && len (options .Options .VPCNames ) > 0 && ! options .Options .DisableNodeBalancerVPCBackends {
954940 createOpts .VPCs , err = l .getVPCCreateOptions (ctx , service )
955941 if err != nil {
956942 return nil , err
@@ -1151,23 +1137,9 @@ func (l *loadbalancers) buildLoadBalancerRequest(ctx context.Context, clusterNam
11511137 configs := make ([]* linodego.NodeBalancerConfigCreateOptions , 0 , len (ports ))
11521138 useIPv6Backends := resolveIPv6NodeBalancerBackendState (service )
11531139
1154- subnetID := 0
1155- if options .Options .NodeBalancerBackendIPv4SubnetID != 0 {
1156- subnetID = options .Options .NodeBalancerBackendIPv4SubnetID
1157- }
1158- // Check for the NodeBalancerBackendIPv4Range annotation
1159- backendIPv4Range , ok := service .GetAnnotations ()[annotations .NodeBalancerBackendIPv4Range ]
1160- if ok {
1161- if err := validateNodeBalancerBackendIPv4Range (backendIPv4Range ); err != nil {
1162- return nil , err
1163- }
1164- }
1165- if len (options .Options .VPCNames ) > 0 && ! options .Options .DisableNodeBalancerVPCBackends {
1166- id , err := l .getSubnetIDForSVC (ctx , service )
1167- if err != nil {
1168- return nil , err
1169- }
1170- subnetID = id
1140+ subnetID , err := l .getBackendSubnetID (ctx , service , useIPv6Backends )
1141+ if err != nil {
1142+ return nil , err
11711143 }
11721144
11731145 for _ , port := range ports {
@@ -1221,12 +1193,40 @@ func (l *loadbalancers) buildNodeBalancerNodeConfigRebuildOptions(service *v1.Se
12211193 if protocol != linodego .ProtocolUDP {
12221194 nodeOptions .Mode = "accept"
12231195 }
1224- if subnetID != 0 {
1196+ if ! useIPv6Backends && subnetID != 0 {
12251197 nodeOptions .SubnetID = subnetID
12261198 }
12271199 return nodeOptions , nil
12281200}
12291201
1202+ func (l * loadbalancers ) getBackendSubnetID (ctx context.Context , service * v1.Service , useIPv6Backends bool ) (int , error ) {
1203+ if useIPv6Backends {
1204+ return 0 , nil
1205+ }
1206+
1207+ subnetID := 0
1208+ if options .Options .NodeBalancerBackendIPv4SubnetID != 0 {
1209+ subnetID = options .Options .NodeBalancerBackendIPv4SubnetID
1210+ }
1211+
1212+ backendIPv4Range , ok := service .GetAnnotations ()[annotations .NodeBalancerBackendIPv4Range ]
1213+ if ok {
1214+ if err := validateNodeBalancerBackendIPv4Range (backendIPv4Range ); err != nil {
1215+ return 0 , err
1216+ }
1217+ }
1218+
1219+ if len (options .Options .VPCNames ) > 0 && ! options .Options .DisableNodeBalancerVPCBackends {
1220+ id , err := l .getSubnetIDForSVC (ctx , service )
1221+ if err != nil {
1222+ return 0 , err
1223+ }
1224+ subnetID = id
1225+ }
1226+
1227+ return subnetID , nil
1228+ }
1229+
12301230func resolveIPv6NodeBalancerBackendState (service * v1.Service ) bool {
12311231 useIPv6 := getServiceBoolAnnotation (service , annotations .AnnLinodeEnableIPv6Backends )
12321232 if useIPv6 != nil {
0 commit comments