diff --git a/pkg/deploy/elbv2/load_balancer_manager.go b/pkg/deploy/elbv2/load_balancer_manager.go index 0727c1643..742a987eb 100644 --- a/pkg/deploy/elbv2/load_balancer_manager.go +++ b/pkg/deploy/elbv2/load_balancer_manager.go @@ -3,6 +3,7 @@ package elbv2 import ( "context" "fmt" + awssdk "github.com/aws/aws-sdk-go-v2/aws" elbv2sdk "github.com/aws/aws-sdk-go-v2/service/elasticloadbalancingv2" elbv2types "github.com/aws/aws-sdk-go-v2/service/elasticloadbalancingv2/types" @@ -179,14 +180,15 @@ func (m *defaultLoadBalancerManager) updateSDKLoadBalancerWithSubnetMappings(ctx resLBEnablePrefixForIpv6SourceNatValue = string(resLB.Spec.EnablePrefixForIpv6SourceNat) - if desiredSubnets.Equal(currentSubnets) && desiredSubnetsSourceNATPrefixes.Equal(currentSubnetsSourceNATPrefixes) && sdkLBEnablePrefixForIpv6SourceNatValue == resLBEnablePrefixForIpv6SourceNatValue { + if desiredSubnets.Equal(currentSubnets) && desiredSubnetsSourceNATPrefixes.Equal(currentSubnetsSourceNATPrefixes) && ((sdkLBEnablePrefixForIpv6SourceNatValue == resLBEnablePrefixForIpv6SourceNatValue) || (resLBEnablePrefixForIpv6SourceNatValue == "")) { return nil } - req := &elbv2sdk.SetSubnetsInput{ - LoadBalancerArn: sdkLB.LoadBalancer.LoadBalancerArn, - SubnetMappings: buildSDKSubnetMappings(resLB.Spec.SubnetMappings), - EnablePrefixForIpv6SourceNat: elbv2types.EnablePrefixForIpv6SourceNatEnum(resLBEnablePrefixForIpv6SourceNatValue), + LoadBalancerArn: sdkLB.LoadBalancer.LoadBalancerArn, + SubnetMappings: buildSDKSubnetMappings(resLB.Spec.SubnetMappings), + } + if resLB.Spec.Type == elbv2model.LoadBalancerTypeNetwork { + req.EnablePrefixForIpv6SourceNat = elbv2types.EnablePrefixForIpv6SourceNatEnum(resLBEnablePrefixForIpv6SourceNatValue) } changeDesc := fmt.Sprintf("%v => %v", currentSubnets.List(), desiredSubnets.List()) m.logger.Info("modifying loadBalancer subnetMappings", diff --git a/pkg/deploy/elbv2/load_balancer_manager_test.go b/pkg/deploy/elbv2/load_balancer_manager_test.go index e35f75346..520dc9e85 100644 --- a/pkg/deploy/elbv2/load_balancer_manager_test.go +++ b/pkg/deploy/elbv2/load_balancer_manager_test.go @@ -2,10 +2,11 @@ package elbv2 import ( "context" + "testing" + elbv2types "github.com/aws/aws-sdk-go-v2/service/elasticloadbalancingv2/types" "github.com/go-logr/logr" "sigs.k8s.io/aws-load-balancer-controller/pkg/aws/services" - "testing" awssdk "github.com/aws/aws-sdk-go-v2/aws" elbv2sdk "github.com/aws/aws-sdk-go-v2/service/elasticloadbalancingv2" @@ -552,6 +553,7 @@ func Test_defaultLoadBalancerManager_updateSDKLoadBalancerWithSubnetMappings(t * resLB: &elbv2model.LoadBalancer{ ResourceMeta: coremodel.NewResourceMeta(stack, "AWS::ElasticLoadBalancingV2::LoadBalancer", "id-1"), Spec: elbv2model.LoadBalancerSpec{ + Type: elbv2model.LoadBalancerTypeNetwork, EnablePrefixForIpv6SourceNat: enablePrefixForIpv6SourceNatOn, SubnetMappings: []elbv2model.SubnetMapping{ { @@ -591,6 +593,7 @@ func Test_defaultLoadBalancerManager_updateSDKLoadBalancerWithSubnetMappings(t * resLB: &elbv2model.LoadBalancer{ ResourceMeta: coremodel.NewResourceMeta(stack, "AWS::ElasticLoadBalancingV2::LoadBalancer", "id-1"), Spec: elbv2model.LoadBalancerSpec{ + Type: elbv2model.LoadBalancerTypeNetwork, SubnetMappings: []elbv2model.SubnetMapping{ { SubnetID: "subnet-A",