Skip to content

Commit 7c73f39

Browse files
bavarianbidik8s-infra-cherrypick-robot
authored andcommitted
fix nil-pointer in initial reconciliation loop
in the initial reconciliation loop, a nil-pointer occurs if the cluster is configured with a bastion host. In this initial run the status field is still empty. Signed-off-by: Mario Constanti <[email protected]>
1 parent e33f1db commit 7c73f39

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

pkg/cloud/services/loadbalancer/loadbalancer.go

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -227,16 +227,26 @@ func (s *Service) getOrUpdateAllowedCIDRS(openStackCluster *infrav1.OpenStackClu
227227
if len(openStackCluster.Spec.APIServerLoadBalancer.AllowedCIDRs) > 0 {
228228
allowedCIDRs = append(allowedCIDRs, openStackCluster.Spec.APIServerLoadBalancer.AllowedCIDRs...)
229229

230-
if openStackCluster.Spec.Bastion.Enabled {
231-
allowedCIDRs = append(allowedCIDRs, openStackCluster.Status.Bastion.FloatingIP, openStackCluster.Status.Bastion.IP)
232-
}
230+
// In the first reconciliation loop, only the Ready field is set in openStackCluster.Status
231+
// All other fields are empty/nil
232+
if openStackCluster.Status.Bastion != nil {
233+
if openStackCluster.Status.Bastion.FloatingIP != "" {
234+
allowedCIDRs = append(allowedCIDRs, openStackCluster.Status.Bastion.FloatingIP)
235+
}
233236

234-
if openStackCluster.Status.Network.Subnet.CIDR != "" {
235-
allowedCIDRs = append(allowedCIDRs, openStackCluster.Status.Network.Subnet.CIDR)
237+
if openStackCluster.Status.Bastion.IP != "" {
238+
allowedCIDRs = append(allowedCIDRs, openStackCluster.Status.Bastion.IP)
239+
}
236240
}
237241

238-
if len(openStackCluster.Status.Network.Router.IPs) > 0 {
239-
allowedCIDRs = append(allowedCIDRs, openStackCluster.Status.Network.Router.IPs...)
242+
if openStackCluster.Status.Network != nil {
243+
if openStackCluster.Status.Network.Subnet.CIDR != "" {
244+
allowedCIDRs = append(allowedCIDRs, openStackCluster.Status.Network.Subnet.CIDR)
245+
}
246+
247+
if len(openStackCluster.Status.Network.Router.IPs) > 0 {
248+
allowedCIDRs = append(allowedCIDRs, openStackCluster.Status.Network.Router.IPs...)
249+
}
240250
}
241251
}
242252

0 commit comments

Comments
 (0)