@@ -50,8 +50,16 @@ func (s *Service) ReconcileLoadBalancer(openStackCluster *infrav1.OpenStackClust
50
50
loadBalancerName := getLoadBalancerName (clusterName )
51
51
s .scope .Logger ().Info ("Reconciling load balancer" , "name" , loadBalancerName )
52
52
53
+ lbStatus := openStackCluster .Status .APIServerLoadBalancer
54
+ if lbStatus == nil {
55
+ lbStatus = & infrav1.LoadBalancer {}
56
+ openStackCluster .Status .APIServerLoadBalancer = lbStatus
57
+ }
58
+
53
59
var fixedIPAddress string
54
60
switch {
61
+ case lbStatus .InternalIP != "" :
62
+ fixedIPAddress = lbStatus .InternalIP
55
63
case openStackCluster .Spec .APIServerFixedIP != "" :
56
64
fixedIPAddress = openStackCluster .Spec .APIServerFixedIP
57
65
case openStackCluster .Spec .DisableAPIServerFloatingIP && openStackCluster .Spec .ControlPlaneEndpoint .IsValid ():
@@ -82,14 +90,21 @@ func (s *Service) ReconcileLoadBalancer(openStackCluster *infrav1.OpenStackClust
82
90
if err != nil {
83
91
return false , err
84
92
}
93
+
94
+ lbStatus .Name = lb .Name
95
+ lbStatus .ID = lb .ID
96
+ lbStatus .InternalIP = lb .VipAddress
97
+ lbStatus .Tags = lb .Tags
98
+
85
99
if err := s .waitForLoadBalancerActive (lb .ID ); err != nil {
86
100
return false , fmt .Errorf ("load balancer %q with id %s is not active after timeout: %v" , loadBalancerName , lb .ID , err )
87
101
}
88
102
89
- var lbFloatingIP string
90
103
if ! openStackCluster .Spec .DisableAPIServerFloatingIP {
91
104
var floatingIPAddress string
92
105
switch {
106
+ case lbStatus .IP != "" :
107
+ floatingIPAddress = lbStatus .IP
93
108
case openStackCluster .Spec .APIServerFloatingIP != "" :
94
109
floatingIPAddress = openStackCluster .Spec .APIServerFloatingIP
95
110
case openStackCluster .Spec .ControlPlaneEndpoint .IsValid ():
@@ -99,10 +114,15 @@ func (s *Service) ReconcileLoadBalancer(openStackCluster *infrav1.OpenStackClust
99
114
if err != nil {
100
115
return false , err
101
116
}
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
+
102
123
if err = s .networkingService .AssociateFloatingIP (openStackCluster , fp , lb .VipPortID ); err != nil {
103
124
return false , err
104
125
}
105
- lbFloatingIP = fp .FloatingIP
106
126
}
107
127
108
128
allowedCIDRs := []string {}
@@ -147,15 +167,8 @@ func (s *Service) ReconcileLoadBalancer(openStackCluster *infrav1.OpenStackClust
147
167
}
148
168
}
149
169
}
170
+ lbStatus .AllowedCIDRs = allowedCIDRs
150
171
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
- }
159
172
return false , nil
160
173
}
161
174
0 commit comments