Skip to content

Commit

Permalink
Merge pull request #1447 from k8s-infra-cherrypick-robot/cherry-pick-…
Browse files Browse the repository at this point in the history
…1445-to-release-0.7

[release-0.7] 🐛 fix nil-pointer in initial reconciliation loop with empty status field
  • Loading branch information
k8s-ci-robot authored Jan 17, 2023
2 parents e33f1db + 7c73f39 commit 2d8a5bd
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions pkg/cloud/services/loadbalancer/loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,16 +227,26 @@ func (s *Service) getOrUpdateAllowedCIDRS(openStackCluster *infrav1.OpenStackClu
if len(openStackCluster.Spec.APIServerLoadBalancer.AllowedCIDRs) > 0 {
allowedCIDRs = append(allowedCIDRs, openStackCluster.Spec.APIServerLoadBalancer.AllowedCIDRs...)

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

if openStackCluster.Status.Network.Subnet.CIDR != "" {
allowedCIDRs = append(allowedCIDRs, openStackCluster.Status.Network.Subnet.CIDR)
if openStackCluster.Status.Bastion.IP != "" {
allowedCIDRs = append(allowedCIDRs, openStackCluster.Status.Bastion.IP)
}
}

if len(openStackCluster.Status.Network.Router.IPs) > 0 {
allowedCIDRs = append(allowedCIDRs, openStackCluster.Status.Network.Router.IPs...)
if openStackCluster.Status.Network != nil {
if openStackCluster.Status.Network.Subnet.CIDR != "" {
allowedCIDRs = append(allowedCIDRs, openStackCluster.Status.Network.Subnet.CIDR)
}

if len(openStackCluster.Status.Network.Router.IPs) > 0 {
allowedCIDRs = append(allowedCIDRs, openStackCluster.Status.Network.Router.IPs...)
}
}
}

Expand Down

0 comments on commit 2d8a5bd

Please sign in to comment.