Skip to content

Commit e4ed9f6

Browse files
authored
Merge pull request #1573 from shiftstack/issue1570
🐛 Always filter cluster subnets by cluster network ID
2 parents 4cb7f12 + 1f39166 commit e4ed9f6

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

controllers/openstackcluster_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ func reconcileNetworkComponents(scope *scope.Scope, cluster *clusterv1.Cluster,
456456
openStackCluster.Status.Network.Name = networkList[0].Name
457457
openStackCluster.Status.Network.Tags = networkList[0].Tags
458458

459-
subnet, err := networkingService.GetSubnetByFilter(&openStackCluster.Spec.Subnet)
459+
subnet, err := networkingService.GetNetworkSubnetByFilter(openStackCluster.Status.Network.ID, &openStackCluster.Spec.Subnet)
460460
if err != nil {
461461
err = fmt.Errorf("failed to find subnet: %w", err)
462462

pkg/cloud/services/networking/network.go

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -351,16 +351,31 @@ func (s *Service) GetSubnetsByFilter(opts subnets.ListOptsBuilder) ([]subnets.Su
351351
// GetSubnetByFilter gets a single subnet specified by the given SubnetFilter.
352352
// It returns an ErrFilterMatch if no or multiple subnets are found.
353353
func (s *Service) GetSubnetByFilter(filter *infrav1.SubnetFilter) (*subnets.Subnet, error) {
354+
return s.getSubnetByFilter(filter.ToListOpt())
355+
}
356+
357+
// GetNetworkSubnetByFilter gets a single subnet of the given network, specified by the given SubnetFilter.
358+
// It returns an ErrFilterMatch if no or multiple subnets are found.
359+
func (s *Service) GetNetworkSubnetByFilter(networkID string, filter *infrav1.SubnetFilter) (*subnets.Subnet, error) {
360+
listOpt := filter.ToListOpt()
361+
listOpt.NetworkID = networkID
362+
363+
return s.getSubnetByFilter(listOpt)
364+
}
365+
366+
// getSubnetByFilter gets a single subnet specified by the given gophercloud ListOpts.
367+
// It returns an ErrFilterMatch if no or multiple subnets are found.
368+
func (s *Service) getSubnetByFilter(listOpts subnets.ListOpts) (*subnets.Subnet, error) {
354369
// If the ID is set, we can just get the subnet by ID.
355-
if filter.ID != "" {
356-
subnet, err := s.client.GetSubnet(filter.ID)
370+
if listOpts.ID != "" {
371+
subnet, err := s.client.GetSubnet(listOpts.ID)
357372
if capoerrors.IsNotFound(err) {
358373
return nil, ErrNoMatches
359374
}
360375
return subnet, err
361376
}
362377

363-
subnets, err := s.GetSubnetsByFilter(filter.ToListOpt())
378+
subnets, err := s.GetSubnetsByFilter(listOpts)
364379
if err != nil {
365380
return nil, err
366381
}

0 commit comments

Comments
 (0)