Skip to content

Commit 937930a

Browse files
Optimize PowerVS method to fetch bucket region to avoid duplicacy
1 parent a893392 commit 937930a

File tree

3 files changed

+15
-20
lines changed

3 files changed

+15
-20
lines changed

cloud/scope/powervs/powervs_cluster.go

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2931,15 +2931,7 @@ func (s *ClusterScope) isResourceCreatedByController(resourceType infrav1.Resour
29312931
return false
29322932
}
29332933

2934-
// TODO: duplicate function, optimize it.
2934+
// bucketRegion returns the region to use for COS bucket for the ClusterScope.
29352935
func (s *ClusterScope) bucketRegion() string {
2936-
if s.COSInstance() != nil && s.COSInstance().BucketRegion != "" {
2937-
return s.COSInstance().BucketRegion
2938-
}
2939-
// if the bucket region is not set, use vpc region
2940-
vpcDetails := s.VPC()
2941-
if vpcDetails != nil && vpcDetails.Region != nil {
2942-
return *vpcDetails.Region
2943-
}
2944-
return ""
2936+
return bucketRegionFrom(s.COSInstance(), s.VPC())
29452937
}

cloud/scope/powervs/powervs_machine.go

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,15 +1146,7 @@ func (m *MachineScope) bucketName() string {
11461146
return fmt.Sprintf("%s-%s", m.IBMPowerVSCluster.GetName(), "cosbucket")
11471147
}
11481148

1149-
// TODO: duplicate function, optimize it.
1149+
// bucketRegion returns the region to use for COS bucket for the MachineScope.
11501150
func (m *MachineScope) bucketRegion() string {
1151-
if m.IBMPowerVSCluster.Spec.CosInstance != nil && m.IBMPowerVSCluster.Spec.CosInstance.BucketRegion != "" {
1152-
return m.IBMPowerVSCluster.Spec.CosInstance.BucketRegion
1153-
}
1154-
// if the bucket region is not set, use vpc region
1155-
vpcDetails := m.IBMPowerVSCluster.Spec.VPC
1156-
if vpcDetails != nil && vpcDetails.Region != nil {
1157-
return *vpcDetails.Region
1158-
}
1159-
return ""
1151+
return bucketRegionFrom(m.IBMPowerVSCluster.Spec.CosInstance, m.IBMPowerVSCluster.Spec.VPC)
11601152
}

cloud/scope/powervs/util.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,14 @@ func CheckCreateInfraAnnotation(cluster infrav1.IBMPowerVSCluster) bool {
5757
}
5858
return createInfra
5959
}
60+
61+
func bucketRegionFrom(cos *infrav1.CosInstance, vpc *infrav1.VPCResourceReference) string {
62+
if cos != nil && cos.BucketRegion != "" {
63+
return cos.BucketRegion
64+
}
65+
// if the bucket region is not set, use vpc region
66+
if vpc != nil && vpc.Region != nil {
67+
return *vpc.Region
68+
}
69+
return ""
70+
}

0 commit comments

Comments
 (0)