Skip to content

Commit 8af5328

Browse files
fix: create lbaas in specified subnet
1 parent 016cb84 commit 8af5328

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

controllers/openstackcluster_controller.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -627,11 +627,15 @@ func resolveLoadBalancerNetwork(openStackCluster *infrav1.OpenStackCluster, netw
627627
for _, s := range lbSpec.Subnets {
628628
matchFound := false
629629
for _, subnetID := range lbNet.Subnets {
630-
if s.ID != nil && subnetID == *s.ID {
630+
subnet, err := networkingService.GetSubnetByParam(&s)
631+
if s.ID != nil && subnetID == *s.ID && err == nil {
631632
matchFound = true
632633
lbNetStatus.Subnets = append(
633634
lbNetStatus.Subnets, infrav1.Subnet{
634-
ID: *s.ID,
635+
ID: subnet.ID,
636+
Name: subnet.Name,
637+
CIDR: subnet.CIDR,
638+
Tags: subnet.Tags,
635639
})
636640
}
637641
}
@@ -640,6 +644,8 @@ func resolveLoadBalancerNetwork(openStackCluster *infrav1.OpenStackCluster, netw
640644
return fmt.Errorf("no subnet match was found in the specified network (specified subnet: %v, available subnets: %v)", s, lbNet.Subnets)
641645
}
642646
}
647+
648+
openStackCluster.Status.APIServerLoadBalancer.LoadBalancerNetwork = lbNetStatus
643649
}
644650
}
645651

pkg/cloud/services/loadbalancer/loadbalancer.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -305,10 +305,11 @@ func (s *Service) getOrCreateAPILoadBalancer(openStackCluster *infrav1.OpenStack
305305
if vipNetworkID == "" && vipSubnetID == "" {
306306
// keep the default and create the VIP on the first cluster subnet
307307
vipSubnetID = openStackCluster.Status.Network.Subnets[0].ID
308+
s.scope.Logger().Info("No load balancer network specified, creating load balancer in the default subnet", "subnetID", vipSubnetID, "name", loadBalancerName)
309+
} else {
310+
s.scope.Logger().Info("Creating load balancer in subnet", "subnetID", vipSubnetID, "name", loadBalancerName)
308311
}
309312

310-
s.scope.Logger().Info("Creating load balancer in subnet", "subnetID", vipSubnetID, "name", loadBalancerName)
311-
312313
providers, err := s.loadbalancerClient.ListLoadBalancerProviders()
313314
if err != nil {
314315
return nil, err

0 commit comments

Comments
 (0)