Skip to content

Commit

Permalink
fix: EnablePrefixForIpv6SourceNat is only applicable to NLB (#3958)
Browse files Browse the repository at this point in the history
  • Loading branch information
wweiwei-li authored Dec 6, 2024
1 parent 616e39b commit 2b3f870
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
12 changes: 7 additions & 5 deletions pkg/deploy/elbv2/load_balancer_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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",
Expand Down
5 changes: 4 additions & 1 deletion pkg/deploy/elbv2/load_balancer_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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{
{
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 2b3f870

Please sign in to comment.