Skip to content

Commit

Permalink
Persist API FloatingIP immediately on creation
Browse files Browse the repository at this point in the history
If loadbalancer reconciliation failed at any time after the floating IP
was created, we would lead the floating IP and create a new one on the
next reconciliation.
  • Loading branch information
mdbooth committed Jan 16, 2024
1 parent 010408d commit fc64480
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions pkg/cloud/services/loadbalancer/loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,16 @@ func (s *Service) ReconcileLoadBalancer(openStackCluster *infrav1.OpenStackClust
loadBalancerName := getLoadBalancerName(clusterName)
s.scope.Logger().Info("Reconciling load balancer", "name", loadBalancerName)

lbStatus := openStackCluster.Status.APIServerLoadBalancer
if lbStatus == nil {
lbStatus = &infrav1.LoadBalancer{}
openStackCluster.Status.APIServerLoadBalancer = lbStatus
}

var fixedIPAddress string
switch {
case lbStatus.InternalIP != "":
fixedIPAddress = lbStatus.InternalIP
case openStackCluster.Spec.APIServerFixedIP != "":
fixedIPAddress = openStackCluster.Spec.APIServerFixedIP
case openStackCluster.Spec.DisableAPIServerFloatingIP && openStackCluster.Spec.ControlPlaneEndpoint.IsValid():
Expand Down Expand Up @@ -82,14 +90,21 @@ func (s *Service) ReconcileLoadBalancer(openStackCluster *infrav1.OpenStackClust
if err != nil {
return false, err
}

lbStatus.Name = lb.Name
lbStatus.ID = lb.ID
lbStatus.InternalIP = lb.VipAddress
lbStatus.Tags = lb.Tags

if err := s.waitForLoadBalancerActive(lb.ID); err != nil {
return false, fmt.Errorf("load balancer %q with id %s is not active after timeout: %v", loadBalancerName, lb.ID, err)
}

var lbFloatingIP string
if !openStackCluster.Spec.DisableAPIServerFloatingIP {
var floatingIPAddress string
switch {
case lbStatus.IP != "":
floatingIPAddress = lbStatus.IP
case openStackCluster.Spec.APIServerFloatingIP != "":
floatingIPAddress = openStackCluster.Spec.APIServerFloatingIP
case openStackCluster.Spec.ControlPlaneEndpoint.IsValid():
Expand All @@ -99,10 +114,15 @@ func (s *Service) ReconcileLoadBalancer(openStackCluster *infrav1.OpenStackClust
if err != nil {
return false, err
}

// Write the floating IP to the status immediately so we won't
// create a new floating IP on the next reconcile if something
// fails below.
lbStatus.IP = fp.FloatingIP

if err = s.networkingService.AssociateFloatingIP(openStackCluster, fp, lb.VipPortID); err != nil {
return false, err
}
lbFloatingIP = fp.FloatingIP
}

allowedCIDRs := []string{}
Expand Down Expand Up @@ -147,15 +167,8 @@ func (s *Service) ReconcileLoadBalancer(openStackCluster *infrav1.OpenStackClust
}
}
}
lbStatus.AllowedCIDRs = allowedCIDRs

openStackCluster.Status.APIServerLoadBalancer = &infrav1.LoadBalancer{
Name: lb.Name,
ID: lb.ID,
InternalIP: lb.VipAddress,
IP: lbFloatingIP,
AllowedCIDRs: allowedCIDRs,
Tags: lb.Tags,
}
return false, nil
}

Expand Down

0 comments on commit fc64480

Please sign in to comment.