Skip to content

Commit 0d56a06

Browse files
Merge pull request openshift#7941 from hamzy/PowerVS-COS-region-configurable
OCPBUGS-27788: PowerVS: COS region configurable
2 parents 225c5f7 + aeca514 commit 0d56a06

File tree

6 files changed

+70
-37
lines changed

6 files changed

+70
-37
lines changed

pkg/asset/machines/master.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ func (m *Master) Generate(dependencies asset.Parents) error {
450450

451451
vsphere.ConfigMasters(machines, clusterID.InfraID)
452452
case powervstypes.Name:
453-
mpool := defaultPowerVSMachinePoolPlatform()
453+
mpool := defaultPowerVSMachinePoolPlatform(ic)
454454
mpool.Set(ic.Platform.PowerVS.DefaultMachinePlatform)
455455
mpool.Set(pool.Platform.PowerVS)
456456
// Only the service instance is guaranteed to exist and be passed via the install config

pkg/asset/machines/worker.go

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,13 +177,28 @@ func defaultVSphereMachinePoolPlatform() vspheretypes.MachinePool {
177177
}
178178
}
179179

180-
func defaultPowerVSMachinePoolPlatform() powervstypes.MachinePool {
181-
return powervstypes.MachinePool{
180+
func defaultPowerVSMachinePoolPlatform(ic *types.InstallConfig) powervstypes.MachinePool {
181+
var (
182+
defaultMp powervstypes.MachinePool
183+
sysTypes []string
184+
err error
185+
)
186+
187+
defaultMp = powervstypes.MachinePool{
182188
MemoryGiB: 32,
183189
Processors: intstr.FromString("0.5"),
184190
ProcType: machinev1.PowerVSProcessorTypeShared,
185191
SysType: "s922",
186192
}
193+
194+
sysTypes, err = powervstypes.AvailableSysTypes(ic.PowerVS.Region)
195+
if err == nil {
196+
defaultMp.SysType = sysTypes[0]
197+
} else {
198+
logrus.Warnf("For given region %v, AvailableSysTypes returns %v", ic.PowerVS.Region, err)
199+
}
200+
201+
return defaultMp
187202
}
188203

189204
func defaultNutanixMachinePoolPlatform() nutanixtypes.MachinePool {
@@ -615,7 +630,7 @@ func (w *Worker) Generate(dependencies asset.Parents) error {
615630
machineSets = append(machineSets, set)
616631
}
617632
case powervstypes.Name:
618-
mpool := defaultPowerVSMachinePoolPlatform()
633+
mpool := defaultPowerVSMachinePoolPlatform(ic)
619634
mpool.Set(ic.Platform.PowerVS.DefaultMachinePlatform)
620635
mpool.Set(pool.Platform.PowerVS)
621636
pool.Platform.PowerVS = &mpool

pkg/asset/rhcos/image.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,19 @@ func osImage(config *types.InstallConfig) (string, error) {
183183
}
184184

185185
if streamArch.Images.PowerVS != nil {
186-
vpcRegion := powervs.Regions[config.Platform.PowerVS.Region].VPCRegion
186+
var (
187+
vpcRegion string
188+
err error
189+
)
190+
if config.Platform.PowerVS.VPCRegion != "" {
191+
vpcRegion = config.Platform.PowerVS.VPCRegion
192+
} else {
193+
vpcRegion = powervs.Regions[config.Platform.PowerVS.Region].VPCRegion
194+
}
195+
vpcRegion, err = powervs.COSRegionForVPCRegion(vpcRegion)
196+
if err != nil {
197+
return "", fmt.Errorf("%s: No Power COS region found", st.FormatPrefix(archName))
198+
}
187199
img := streamArch.Images.PowerVS.Regions[vpcRegion]
188200
logrus.Debug("Power VS using image ", img.Object)
189201
return fmt.Sprintf("%s/%s", img.Bucket, img.Object), nil

pkg/destroy/powervs/powervs.go

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -110,36 +110,6 @@ func fetchUserDetails(bxSession *bxsession.Session, generation int) (*User, erro
110110
return &user, nil
111111
}
112112

113-
// GetRegion converts from a zone into a region.
114-
func GetRegion(zone string) (region string, err error) {
115-
err = nil
116-
switch {
117-
case strings.HasPrefix(zone, "dal"), strings.HasPrefix(zone, "us-south"):
118-
region = "us-south"
119-
case strings.HasPrefix(zone, "sao"):
120-
region = "sao"
121-
case strings.HasPrefix(zone, "us-east"):
122-
region = "us-east"
123-
case strings.HasPrefix(zone, "tor"):
124-
region = "tor"
125-
case strings.HasPrefix(zone, "eu-de-"):
126-
region = "eu-de"
127-
case strings.HasPrefix(zone, "lon"):
128-
region = "lon"
129-
case strings.HasPrefix(zone, "syd"):
130-
region = "syd"
131-
case strings.HasPrefix(zone, "tok"):
132-
region = "tok"
133-
case strings.HasPrefix(zone, "osa"):
134-
region = "osa"
135-
case strings.HasPrefix(zone, "mon"):
136-
region = "mon"
137-
default:
138-
return "", fmt.Errorf("region not found for the zone: %s", zone)
139-
}
140-
return
141-
}
142-
143113
// ClusterUninstaller holds the various options for the cluster we want to delete.
144114
type ClusterUninstaller struct {
145115
APIKey string

pkg/tfvars/powervs/powervs.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ type TFVarsSources struct {
7474
func TFVars(sources TFVarsSources) ([]byte, error) {
7575
masterConfig := sources.MasterConfigs[0]
7676

77-
cosRegion, err := powervstypes.VPCRegionForPowerVSRegion(sources.Region)
77+
cosRegion, err := powervstypes.COSRegionForVPCRegion(sources.VPCRegion)
7878
if err != nil {
79-
return nil, fmt.Errorf("failed to find COS region for PowerVS region")
79+
return nil, fmt.Errorf("failed to find COS region for VPC region")
8080
}
8181

8282
var processor, dnsGUID string

pkg/types/powervs/powervs_regions.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
type Region struct {
1515
Description string
1616
VPCRegion string
17+
COSRegion string
1718
Zones []string
1819
SysTypes []string
1920
}
@@ -23,30 +24,35 @@ var Regions = map[string]Region{
2324
"dal": {
2425
Description: "Dallas, USA",
2526
VPCRegion: "us-south",
27+
COSRegion: "us-south",
2628
Zones: []string{"dal10"},
2729
SysTypes: []string{"s922", "e980"},
2830
},
2931
"eu-de": {
3032
Description: "Frankfurt, Germany",
3133
VPCRegion: "eu-de",
34+
COSRegion: "eu-de",
3235
Zones: []string{"eu-de-1", "eu-de-2"},
3336
SysTypes: []string{"s922", "e980"},
3437
},
3538
"mad": {
3639
Description: "Madrid, Spain",
3740
VPCRegion: "eu-es",
41+
COSRegion: "eu-de", // @HACK - PowerVS says COS not supported in this region
3842
Zones: []string{"mad02", "mad04"},
3943
SysTypes: []string{"s1022"},
4044
},
4145
"sao": {
4246
Description: "São Paulo, Brazil",
4347
VPCRegion: "br-sao",
48+
COSRegion: "br-sao",
4449
Zones: []string{"sao04"},
4550
SysTypes: []string{"s922", "e980"},
4651
},
4752
"wdc": {
4853
Description: "Washington DC, USA",
4954
VPCRegion: "us-east",
55+
COSRegion: "us-east",
5056
Zones: []string{"wdc06", "wdc07"},
5157
SysTypes: []string{"s922", "e980"},
5258
},
@@ -136,3 +142,33 @@ func AllKnownSysTypes() sets.Set[string] {
136142
}
137143
return sysTypes
138144
}
145+
146+
// COSRegionForVPCRegion returns the corresponding COS region for the given VPC region.
147+
func COSRegionForVPCRegion(vpcRegion string) (string, error) {
148+
for r := range Regions {
149+
if vpcRegion == Regions[r].VPCRegion {
150+
return Regions[r].COSRegion, nil
151+
}
152+
}
153+
154+
return "", fmt.Errorf("COS region corresponding to a VPC region %s not found ", vpcRegion)
155+
}
156+
157+
// COSRegionForPowerVSRegion returns the IBM COS region for the specified PowerVS region.
158+
func COSRegionForPowerVSRegion(region string) (string, error) {
159+
if r, ok := Regions[region]; ok {
160+
return r.COSRegion, nil
161+
}
162+
163+
return "", fmt.Errorf("COS region corresponding to a PowerVS region %s not found ", region)
164+
}
165+
166+
// ValidateCOSRegion validates that given COS region is known/tested.
167+
func ValidateCOSRegion(region string) bool {
168+
for r := range Regions {
169+
if region == Regions[r].COSRegion {
170+
return true
171+
}
172+
}
173+
return false
174+
}

0 commit comments

Comments
 (0)