Skip to content

Commit db14d13

Browse files
authored
Merge pull request #3240 from Ankitasw/block-recreate-elb
Block ELB re-creation after the cluster has been provisioned
2 parents 1767e07 + b2d895c commit db14d13

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

pkg/cloud/scope/cluster.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,10 @@ func (s *ClusterScope) ControlPlaneLoadBalancerName() *string {
193193
return nil
194194
}
195195

196+
func (s *ClusterScope) ControlPlaneEndpoint() clusterv1.APIEndpoint {
197+
return s.AWSCluster.Spec.ControlPlaneEndpoint
198+
}
199+
196200
// ControlPlaneConfigMapName returns the name of the ConfigMap used to
197201
// coordinate the bootstrapping of control plane nodes.
198202
func (s *ClusterScope) ControlPlaneConfigMapName() string {

pkg/cloud/scope/elb.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package scope
1919
import (
2020
infrav1 "sigs.k8s.io/cluster-api-provider-aws/api/v1beta1"
2121
"sigs.k8s.io/cluster-api-provider-aws/pkg/cloud"
22+
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
2223
)
2324

2425
// ELBScope is a scope for use with the ELB reconciling service.
@@ -45,4 +46,7 @@ type ELBScope interface {
4546

4647
// ControlPlaneLoadBalancerName returns the Classic ELB name
4748
ControlPlaneLoadBalancerName() *string
49+
50+
// ControlPlaneEndpoint returns AWSCluster control plane endpoint
51+
ControlPlaneEndpoint() clusterv1.APIEndpoint
4852
}

pkg/cloud/services/elb/loadbalancer.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,17 @@ func (s *Service) ReconcileLoadbalancers() error {
7777
}
7878

7979
apiELB, err := s.describeClassicELB(spec.Name)
80-
if IsNotFound(err) {
80+
switch {
81+
case IsNotFound(err) && s.scope.ControlPlaneEndpoint().IsValid():
82+
// if elb is not found and owner cluster ControlPlaneEndpoint is already populated, then we should not recreate the elb.
83+
return errors.Wrapf(err, "no loadbalancer exists for the AWSCluster %s, the cluster has become unrecoverable and should be deleted manually", s.scope.InfraClusterName())
84+
case IsNotFound(err):
8185
apiELB, err = s.createClassicELB(spec)
8286
if err != nil {
8387
return err
8488
}
85-
8689
s.scope.V(2).Info("Created new classic load balancer for apiserver", "api-server-elb-name", apiELB.Name)
87-
} else if err != nil {
90+
case err != nil:
8891
// Failed to describe the classic ELB
8992
return err
9093
}

0 commit comments

Comments
 (0)