@@ -87,7 +87,7 @@ func (s *Service) reconcileV2LB(lbSpec *infrav1.AWSLoadBalancerSpec) error {
87
87
}
88
88
89
89
// Get default api server spec.
90
- spec , err := s .getAPIServerLBSpec (name , lbSpec )
90
+ desiredLB , err := s .getAPIServerLBSpec (name , lbSpec )
91
91
if err != nil {
92
92
return err
93
93
}
@@ -97,7 +97,7 @@ func (s *Service) reconcileV2LB(lbSpec *infrav1.AWSLoadBalancerSpec) error {
97
97
// if elb is not found and owner cluster ControlPlaneEndpoint is already populated, then we should not recreate the elb.
98
98
return errors .Wrapf (err , "no loadbalancer exists for the AWSCluster %s, the cluster has become unrecoverable and should be deleted manually" , s .scope .InfraClusterName ())
99
99
case IsNotFound (err ):
100
- lb , err = s .createLB (spec , lbSpec )
100
+ lb , err = s .createLB (desiredLB , lbSpec )
101
101
if err != nil {
102
102
s .scope .Error (err , "failed to create LB" )
103
103
return err
@@ -113,41 +113,42 @@ func (s *Service) reconcileV2LB(lbSpec *infrav1.AWSLoadBalancerSpec) error {
113
113
lb .LoadBalancerType = lbSpec .LoadBalancerType
114
114
if lb .IsManaged (s .scope .Name ()) {
115
115
// Reconcile the target groups and listeners from the spec and the ones currently attached to the load balancer.
116
- _ , _ , err := s .reconcileTargetGroupsAndListeners (lb , lbSpec )
116
+ // Pass in the ARN that AWS gave us, as well as the rest of the desired specification.
117
+ _ , _ , err := s .reconcileTargetGroupsAndListeners (lb .ARN , desiredLB , lbSpec )
117
118
if err != nil {
118
119
return errors .Wrapf (err , "failed to create target groups/listeners for load balancer %q" , lb .Name )
119
120
}
120
121
121
- if ! cmp .Equal (spec .ELBAttributes , lb .ELBAttributes ) {
122
- if err := s .configureLBAttributes (lb .ARN , spec .ELBAttributes ); err != nil {
122
+ if ! cmp .Equal (desiredLB .ELBAttributes , lb .ELBAttributes ) {
123
+ if err := s .configureLBAttributes (lb .ARN , desiredLB .ELBAttributes ); err != nil {
123
124
return err
124
125
}
125
126
}
126
127
127
- if err := s .reconcileV2LBTags (lb , spec .Tags ); err != nil {
128
+ if err := s .reconcileV2LBTags (lb , desiredLB .Tags ); err != nil {
128
129
return errors .Wrapf (err , "failed to reconcile tags for apiserver load balancer %q" , lb .Name )
129
130
}
130
131
131
- // Reconcile the subnets and availability zones from the spec
132
+ // Reconcile the subnets and availability zones from the desiredLB
132
133
// and the ones currently attached to the load balancer.
133
- if len (lb .SubnetIDs ) != len (spec .SubnetIDs ) {
134
+ if len (lb .SubnetIDs ) != len (desiredLB .SubnetIDs ) {
134
135
_ , err := s .ELBV2Client .SetSubnets (& elbv2.SetSubnetsInput {
135
136
LoadBalancerArn : & lb .ARN ,
136
- Subnets : aws .StringSlice (spec .SubnetIDs ),
137
+ Subnets : aws .StringSlice (desiredLB .SubnetIDs ),
137
138
})
138
139
if err != nil {
139
140
return errors .Wrapf (err , "failed to set subnets for apiserver load balancer '%s'" , lb .Name )
140
141
}
141
142
}
142
- if len (lb .AvailabilityZones ) != len (spec .AvailabilityZones ) {
143
- lb .AvailabilityZones = spec .AvailabilityZones
143
+ if len (lb .AvailabilityZones ) != len (desiredLB .AvailabilityZones ) {
144
+ lb .AvailabilityZones = desiredLB .AvailabilityZones
144
145
}
145
146
146
- // Reconcile the security groups from the spec and the ones currently attached to the load balancer
147
- if shouldReconcileSGs (s .scope , lb , spec .SecurityGroupIDs ) {
147
+ // Reconcile the security groups from the desiredLB and the ones currently attached to the load balancer
148
+ if shouldReconcileSGs (s .scope , lb , desiredLB .SecurityGroupIDs ) {
148
149
_ , err := s .ELBV2Client .SetSecurityGroups (& elbv2.SetSecurityGroupsInput {
149
150
LoadBalancerArn : & lb .ARN ,
150
- SecurityGroups : aws .StringSlice (spec .SecurityGroupIDs ),
151
+ SecurityGroups : aws .StringSlice (desiredLB .SecurityGroupIDs ),
151
152
})
152
153
if err != nil {
153
154
return errors .Wrapf (err , "failed to apply security groups to load balancer %q" , lb .Name )
@@ -401,6 +402,7 @@ func (s *Service) createLB(spec *infrav1.LoadBalancer, lbSpec *infrav1.AWSLoadBa
401
402
res := spec .DeepCopy ()
402
403
s .scope .Debug ("applying load balancer DNS to result" , "dns" , * out .LoadBalancers [0 ].DNSName )
403
404
res .DNSName = * out .LoadBalancers [0 ].DNSName
405
+ res .ARN = * out .LoadBalancers [0 ].LoadBalancerArn
404
406
return res , nil
405
407
}
406
408
@@ -1530,22 +1532,22 @@ func (s *Service) reconcileV2LBTags(lb *infrav1.LoadBalancer, desiredTags map[st
1530
1532
1531
1533
// reconcileTargetGroupsAndListeners reconciles a Load Balancer's defined listeners with corresponding AWS Target Groups and Listeners.
1532
1534
// These are combined into a single function since they are tightly integrated.
1533
- func (s * Service ) reconcileTargetGroupsAndListeners (spec * infrav1.LoadBalancer , lbSpec * infrav1.AWSLoadBalancerSpec ) ([]* elbv2.TargetGroup , []* elbv2.Listener , error ) {
1535
+ func (s * Service ) reconcileTargetGroupsAndListeners (lbARN string , spec * infrav1.LoadBalancer , lbSpec * infrav1.AWSLoadBalancerSpec ) ([]* elbv2.TargetGroup , []* elbv2.Listener , error ) {
1534
1536
existingTargetGroups , err := s .ELBV2Client .DescribeTargetGroups (
1535
1537
& elbv2.DescribeTargetGroupsInput {
1536
- LoadBalancerArn : aws .String (spec . ARN ),
1538
+ LoadBalancerArn : aws .String (lbARN ),
1537
1539
})
1538
1540
if err != nil {
1539
- s .scope .Error (err , "could not describe target groups for load balancer" , "arn" , spec . ARN )
1541
+ s .scope .Error (err , "could not describe target groups for load balancer" , "arn" , lbARN )
1540
1542
return nil , nil , err
1541
1543
}
1542
1544
1543
1545
existingListeners , err := s .ELBV2Client .DescribeListeners (
1544
1546
& elbv2.DescribeListenersInput {
1545
- LoadBalancerArn : aws .String (spec . ARN ),
1547
+ LoadBalancerArn : aws .String (lbARN ),
1546
1548
})
1547
1549
if err != nil {
1548
- s .scope .Error (err , "could not describe listeners for load balancer" , "arn" , spec . ARN )
1550
+ s .scope .Error (err , "could not describe listeners for load balancer" , "arn" , lbARN )
1549
1551
}
1550
1552
1551
1553
if len (existingTargetGroups .TargetGroups ) == len (existingListeners .Listeners ) && len (existingListeners .Listeners ) == len (spec .ELBListeners ) {
@@ -1596,7 +1598,7 @@ func (s *Service) reconcileTargetGroupsAndListeners(spec *infrav1.LoadBalancer,
1596
1598
}
1597
1599
1598
1600
if listener == nil {
1599
- listener , err = s .createListener (ln , group , spec . ARN , spec .Tags )
1601
+ listener , err = s .createListener (ln , group , lbARN , spec .Tags )
1600
1602
if err != nil {
1601
1603
return nil , nil , err
1602
1604
}
0 commit comments