Skip to content

Commit

Permalink
Merge pull request #3240 from Ankitasw/block-recreate-elb
Browse files Browse the repository at this point in the history
Block ELB re-creation after the cluster has been provisioned
  • Loading branch information
k8s-ci-robot committed Mar 1, 2022
2 parents 1767e07 + b2d895c commit db14d13
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
4 changes: 4 additions & 0 deletions pkg/cloud/scope/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,10 @@ func (s *ClusterScope) ControlPlaneLoadBalancerName() *string {
return nil
}

func (s *ClusterScope) ControlPlaneEndpoint() clusterv1.APIEndpoint {
return s.AWSCluster.Spec.ControlPlaneEndpoint
}

// ControlPlaneConfigMapName returns the name of the ConfigMap used to
// coordinate the bootstrapping of control plane nodes.
func (s *ClusterScope) ControlPlaneConfigMapName() string {
Expand Down
4 changes: 4 additions & 0 deletions pkg/cloud/scope/elb.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package scope
import (
infrav1 "sigs.k8s.io/cluster-api-provider-aws/api/v1beta1"
"sigs.k8s.io/cluster-api-provider-aws/pkg/cloud"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
)

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

// ControlPlaneLoadBalancerName returns the Classic ELB name
ControlPlaneLoadBalancerName() *string

// ControlPlaneEndpoint returns AWSCluster control plane endpoint
ControlPlaneEndpoint() clusterv1.APIEndpoint
}
9 changes: 6 additions & 3 deletions pkg/cloud/services/elb/loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,17 @@ func (s *Service) ReconcileLoadbalancers() error {
}

apiELB, err := s.describeClassicELB(spec.Name)
if IsNotFound(err) {
switch {
case IsNotFound(err) && s.scope.ControlPlaneEndpoint().IsValid():
// if elb is not found and owner cluster ControlPlaneEndpoint is already populated, then we should not recreate the elb.
return errors.Wrapf(err, "no loadbalancer exists for the AWSCluster %s, the cluster has become unrecoverable and should be deleted manually", s.scope.InfraClusterName())
case IsNotFound(err):
apiELB, err = s.createClassicELB(spec)
if err != nil {
return err
}

s.scope.V(2).Info("Created new classic load balancer for apiserver", "api-server-elb-name", apiELB.Name)
} else if err != nil {
case err != nil:
// Failed to describe the classic ELB
return err
}
Expand Down

0 comments on commit db14d13

Please sign in to comment.