@@ -143,7 +143,7 @@ func (s *Service) ReconcileLoadBalancer(openStackCluster *infrav1.OpenStackClust
143
143
func getAPIServerVIPAddress (openStackCluster * infrav1.OpenStackCluster ) (string , error ) {
144
144
switch {
145
145
// We only use call this function when creating the loadbalancer, so this case should never be used
146
- case openStackCluster .Status .APIServerLoadBalancer .InternalIP != "" :
146
+ case openStackCluster .Status .APIServerLoadBalancer != nil && openStackCluster . Status . APIServerLoadBalancer .InternalIP != "" :
147
147
return openStackCluster .Status .APIServerLoadBalancer .InternalIP , nil
148
148
149
149
// Explicit fixed IP in the cluster spec
@@ -167,7 +167,7 @@ func getAPIServerVIPAddress(openStackCluster *infrav1.OpenStackCluster) (string,
167
167
func getAPIServerFloatingIP (openStackCluster * infrav1.OpenStackCluster ) (string , error ) {
168
168
switch {
169
169
// The floating IP was created previously
170
- case openStackCluster .Status .APIServerLoadBalancer .IP != "" :
170
+ case openStackCluster .Status .APIServerLoadBalancer != nil && openStackCluster . Status . APIServerLoadBalancer .IP != "" :
171
171
return openStackCluster .Status .APIServerLoadBalancer .IP , nil
172
172
173
173
// Explicit floating IP in the cluster spec
@@ -214,7 +214,7 @@ func getCanonicalAllowedCIDRs(openStackCluster *infrav1.OpenStackCluster) []stri
214
214
}
215
215
}
216
216
217
- if len (openStackCluster .Status .Router .IPs ) > 0 {
217
+ if openStackCluster . Status . Router != nil && len (openStackCluster .Status .Router .IPs ) > 0 {
218
218
allowedCIDRs = append (allowedCIDRs , openStackCluster .Status .Router .IPs ... )
219
219
}
220
220
}
@@ -260,6 +260,10 @@ func (s *Service) getOrCreateAPILoadBalancer(openStackCluster *infrav1.OpenStack
260
260
return lb , nil
261
261
}
262
262
263
+ if openStackCluster .Status .Network == nil {
264
+ return nil , fmt .Errorf ("network is not yet available in OpenStackCluster.Status" )
265
+ }
266
+
263
267
// Create the VIP on the first cluster subnet
264
268
subnetID := openStackCluster .Status .Network .Subnets [0 ].ID
265
269
s .scope .Logger ().Info ("Creating load balancer in subnet" , "subnetID" , subnetID , "name" , loadBalancerName )
@@ -312,6 +316,10 @@ func (s *Service) reconcileAPILoadBalancerListener(lb *loadbalancers.LoadBalance
312
316
loadBalancerName := getLoadBalancerName (clusterName )
313
317
lbPortObjectsName := fmt .Sprintf ("%s-%d" , loadBalancerName , port )
314
318
319
+ if openStackCluster .Status .APIServerLoadBalancer == nil {
320
+ return fmt .Errorf ("APIServerLoadBalancer is not yet available in OpenStackCluster.Status" )
321
+ }
322
+
315
323
allowedCIDRs := openStackCluster .Status .APIServerLoadBalancer .AllowedCIDRs
316
324
317
325
listener , err := s .getOrCreateListener (openStackCluster , lbPortObjectsName , lb .ID , allowedCIDRs , port )
0 commit comments