Skip to content

Commit

Permalink
Derive VPC zones from VPC region instead of PowerVS region. (#1819)
Browse files Browse the repository at this point in the history
  • Loading branch information
kishen-v authored Jun 3, 2024
1 parent a36e496 commit 0d8b651
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
16 changes: 3 additions & 13 deletions cloud/scope/powervs_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -1050,17 +1050,12 @@ func (s *PowerVSClusterScope) ReconcileVPCSubnets() (bool, error) {
// check whether user has set the vpc subnets
if len(s.IBMPowerVSCluster.Spec.VPCSubnets) == 0 {
// if the user did not set any subnet, we try to create subnet in all the zones.
powerVSZone := s.Zone()
if powerVSZone == nil {
return false, fmt.Errorf("PowerVS zone is not set")
}
region := endpoints.ConstructRegionFromZone(*powerVSZone)
vpcZones, err := genUtil.VPCZonesForPowerVSRegion(region)
vpcZones, err := genUtil.VPCZonesForVPCRegion(*s.VPC().Region)
if err != nil {
return false, err
}
if len(vpcZones) == 0 {
return false, fmt.Errorf("failed to fetch VPC zones, no zone found for region %s", region)
return false, fmt.Errorf("failed to fetch VPC zones, no zone found for region %s", *s.VPC().Region)
}
for _, zone := range vpcZones {
subnet := infrav1beta2.Subnet{
Expand Down Expand Up @@ -1150,12 +1145,7 @@ func (s *PowerVSClusterScope) createVPCSubnet(subnet infrav1beta2.Subnet) (*stri
if subnet.Zone != nil {
zone = *subnet.Zone
} else {
powerVSZone := s.Zone()
if powerVSZone == nil {
return nil, fmt.Errorf("PowerVS zone is not set")
}
region := endpoints.ConstructRegionFromZone(*powerVSZone)
vpcZones, err := genUtil.VPCZonesForPowerVSRegion(region)
vpcZones, err := genUtil.VPCZonesForVPCRegion(*s.VPC().Region)
if err != nil {
return nil, err
}
Expand Down
10 changes: 10 additions & 0 deletions util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,3 +230,13 @@ func GetTransitGatewayLocationAndRouting(powerVSZone *string, vpcRegion *string)
// since VPC region is not set and used PowerVS region to calculate the transit gateway location, hence returning local routing as default.
return &location, ptr.To(false), nil
}

// VPCZonesForVPCRegion returns the VPC zones associated with the VPC region.
func VPCZonesForVPCRegion(region string) ([]string, error) {
for _, regionDetails := range Regions {
if regionDetails.VPCRegion == region {
return regionDetails.VPCZones, nil
}
}
return nil, fmt.Errorf("VPC zones corresponding to the VPC region %s is not found", region)
}

0 comments on commit 0d8b651

Please sign in to comment.