Skip to content

Commit 2d8a5bd

Browse files
authored
Merge pull request #1447 from k8s-infra-cherrypick-robot/cherry-pick-1445-to-release-0.7
[release-0.7] 🐛 fix nil-pointer in initial reconciliation loop with empty status field
2 parents e33f1db + 7c73f39 commit 2d8a5bd

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)