Skip to content

Commit fc64480

Browse files
committed
Persist API FloatingIP immediately on creation
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.
1 parent 010408d commit fc64480

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

pkg/cloud/services/loadbalancer/loadbalancer.go

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,16 @@ func (s *Service) ReconcileLoadBalancer(openStackCluster *infrav1.OpenStackClust
5050
loadBalancerName := getLoadBalancerName(clusterName)
5151
s.scope.Logger().Info("Reconciling load balancer", "name", loadBalancerName)
5252

53+
lbStatus := openStackCluster.Status.APIServerLoadBalancer
54+
if lbStatus == nil {
55+
lbStatus = &infrav1.LoadBalancer{}
56+
openStackCluster.Status.APIServerLoadBalancer = lbStatus
57+
}
58+
5359
var fixedIPAddress string
5460
switch {
61+
case lbStatus.InternalIP != "":
62+
fixedIPAddress = lbStatus.InternalIP
5563
case openStackCluster.Spec.APIServerFixedIP != "":
5664
fixedIPAddress = openStackCluster.Spec.APIServerFixedIP
5765
case openStackCluster.Spec.DisableAPIServerFloatingIP && openStackCluster.Spec.ControlPlaneEndpoint.IsValid():
@@ -82,14 +90,21 @@ func (s *Service) ReconcileLoadBalancer(openStackCluster *infrav1.OpenStackClust
8290
if err != nil {
8391
return false, err
8492
}
93+
94+
lbStatus.Name = lb.Name
95+
lbStatus.ID = lb.ID
96+
lbStatus.InternalIP = lb.VipAddress
97+
lbStatus.Tags = lb.Tags
98+
8599
if err := s.waitForLoadBalancerActive(lb.ID); err != nil {
86100
return false, fmt.Errorf("load balancer %q with id %s is not active after timeout: %v", loadBalancerName, lb.ID, err)
87101
}
88102

89-
var lbFloatingIP string
90103
if !openStackCluster.Spec.DisableAPIServerFloatingIP {
91104
var floatingIPAddress string
92105
switch {
106+
case lbStatus.IP != "":
107+
floatingIPAddress = lbStatus.IP
93108
case openStackCluster.Spec.APIServerFloatingIP != "":
94109
floatingIPAddress = openStackCluster.Spec.APIServerFloatingIP
95110
case openStackCluster.Spec.ControlPlaneEndpoint.IsValid():
@@ -99,10 +114,15 @@ func (s *Service) ReconcileLoadBalancer(openStackCluster *infrav1.OpenStackClust
99114
if err != nil {
100115
return false, err
101116
}
117+
118+
// Write the floating IP to the status immediately so we won't
119+
// create a new floating IP on the next reconcile if something
120+
// fails below.
121+
lbStatus.IP = fp.FloatingIP
122+
102123
if err = s.networkingService.AssociateFloatingIP(openStackCluster, fp, lb.VipPortID); err != nil {
103124
return false, err
104125
}
105-
lbFloatingIP = fp.FloatingIP
106126
}
107127

108128
allowedCIDRs := []string{}
@@ -147,15 +167,8 @@ func (s *Service) ReconcileLoadBalancer(openStackCluster *infrav1.OpenStackClust
147167
}
148168
}
149169
}
170+
lbStatus.AllowedCIDRs = allowedCIDRs
150171

151-
openStackCluster.Status.APIServerLoadBalancer = &infrav1.LoadBalancer{
152-
Name: lb.Name,
153-
ID: lb.ID,
154-
InternalIP: lb.VipAddress,
155-
IP: lbFloatingIP,
156-
AllowedCIDRs: allowedCIDRs,
157-
Tags: lb.Tags,
158-
}
159172
return false, nil
160173
}
161174

0 commit comments

Comments
 (0)