Skip to content

Commit

Permalink
remove ensureSubnets check and update unit test to add AZ info
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviassss committed Dec 15, 2023
1 parent f21fcc4 commit 6f75cb4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
8 changes: 2 additions & 6 deletions pkg/providers/v1/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -4155,19 +4155,15 @@ func (c *Cloud) EnsureLoadBalancer(ctx context.Context, clusterName string, apiS
return nil, err
}

// try to get the existing subnets of existing LBs from AZs
// try to get the ensured subnets of the LBs from AZs
var ensuredSubnetIDs []string
var subnetCidrs []string
for _, az := range v2LoadBalancer.AvailabilityZones {
ensuredSubnetIDs = append(ensuredSubnetIDs, *az.SubnetId)
}
// for newly created LBs, the ensured subnets are nil since the loadbalancer.AvailabilityZones are none
// we use discovered subnets in this case
if len(ensuredSubnetIDs) == 0 {
klog.Infof("did not find existing subnets on LB %s, use discovered subnets %d", loadBalancerName, discoveredSubnetIDs)
subnetCidrs, err = c.getSubnetCidrs(discoveredSubnetIDs)
return nil, fmt.Errorf("did not find ensured subnets on LB %s", loadBalancerName)
} else {
klog.Infof("use exising subnets on LB %s, subnet IDs: %d", loadBalancerName, ensuredSubnetIDs)
subnetCidrs, err = c.getSubnetCidrs(ensuredSubnetIDs)
}
if err != nil {
Expand Down
6 changes: 6 additions & 0 deletions pkg/providers/v1/aws_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2759,6 +2759,12 @@ func (m *MockedFakeELBV2) CreateLoadBalancer(request *elbv2.CreateLoadBalancerIn
LoadBalancerName: request.Name,
Type: aws.String(elbv2.LoadBalancerTypeEnumNetwork),
VpcId: aws.String("vpc-abc123def456abc78"),
AvailabilityZones: []*elbv2.AvailabilityZone{
{
ZoneName: aws.String("us-west-2a"),
SubnetId: aws.String("subnet-abc123de"),
},
},
}
m.LoadBalancers = append(m.LoadBalancers, newLB)

Expand Down

0 comments on commit 6f75cb4

Please sign in to comment.