Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release-4.14] OCPBUGS-46606: Power VS: Create region-zone-sysType hierarchy #9331

Open
wants to merge 1 commit into
base: release-4.14
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion pkg/asset/installconfig/powervs/regions.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ func IsKnownRegion(region string) bool {
}

func knownZones(region string) []string {
return powervs.Regions[region].Zones
zones := make([]string, 0, len(powervs.Regions[region].Zones))
for z := range powervs.Regions[region].Zones {
zones = append(zones, z)
}
return zones
}

// IsKnownZone return true is a specified zone is Known to the installer.
Expand Down
98 changes: 67 additions & 31 deletions pkg/types/powervs/powervs_regions.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,72 +12,108 @@ import (
type Region struct {
Description string
VPCRegion string
Zones []string
Zones map[string]Zone
}

// Zone holds the sysTypes for a zone in a IBM Power VS region.
type Zone struct {
SysTypes []string
}

// Regions holds the regions for IBM Power VS, and descriptions used during the survey.
var Regions = map[string]Region{
"dal": {
Description: "Dallas, USA",
VPCRegion: "us-south",
Zones: []string{
"dal10",
"dal12",
Zones: map[string]Zone{
"dal10": {
SysTypes: []string{"s922", "s1022", "e980", "e1080"},
},
"dal12": {
SysTypes: []string{"s922", "e980"},
},
},
},
"eu-de": {
Description: "Frankfurt, Germany",
VPCRegion: "eu-de",
Zones: []string{
"eu-de-1",
"eu-de-2",
Zones: map[string]Zone{
"eu-de-1": {
SysTypes: []string{"s922", "s1022", "e980"},
},
"eu-de-2": {
SysTypes: []string{"s922", "e980"},
},
},
},
"lon": {
Description: "London, UK.",
Description: "London, UK",
VPCRegion: "eu-gb",
Zones: []string{
"lon04",
"lon06",
Zones: map[string]Zone{
"lon04": {
SysTypes: []string{"s922", "e980"},
},
"lon06": {
SysTypes: []string{"s922", "e980"},
},
},
},
"mon": {
Description: "Montreal, Canada",
VPCRegion: "ca-tor",
Zones: []string{"mon01"},
Zones: map[string]Zone{
"mon01": {
SysTypes: []string{"s922", "e980"},
},
},
},
"osa": {
Description: "Osaka, Japan",
VPCRegion: "jp-osa",
Zones: []string{"osa21"},
},
"syd": {
Description: "Sydney, Australia",
VPCRegion: "au-syd",
Zones: []string{
"syd04",
"syd05",
Zones: map[string]Zone{
"osa21": {
SysTypes: []string{"s922", "s1022", "e980"},
},
},
},
"sao": {
Description: "São Paulo, Brazil",
VPCRegion: "br-sao",
Zones: []string{"sao01"},
Zones: map[string]Zone{
"sao01": {
SysTypes: []string{"s922", "e980"},
},
},
},
"syd": {
Description: "Sydney, Australia",
VPCRegion: "au-syd",
Zones: map[string]Zone{
"syd04": {
SysTypes: []string{"s922", "e980"},
},
"syd05": {
SysTypes: []string{"s922", "e980"},
},
},
},
"tor": {
Description: "Toronto, Canada",
VPCRegion: "ca-tor",
Zones: []string{"tor01"},
},
"tok": {
Description: "Tokyo, Japan",
VPCRegion: "jp-tok",
Zones: []string{"tok04"},
Zones: map[string]Zone{
"tor01": {
SysTypes: []string{"s922", "e980"},
},
},
},
"us-east": {
Description: "Washington DC, USA",
VPCRegion: "us-east",
Zones: []string{"us-east"},
Zones: map[string]Zone{
"us-east": {
SysTypes: []string{"s922", "e980"},
},
},
},
}

Expand Down Expand Up @@ -117,7 +153,7 @@ func ValidateVPCRegion(region string) bool {
func ValidateZone(zone string) bool {
for r := range Regions {
for z := range Regions[r].Zones {
if zone == Regions[r].Zones[z] {
if zone == z {
return true
}
}
Expand All @@ -130,7 +166,7 @@ func ZoneNames() []string {
zones := []string{}
for r := range Regions {
for z := range Regions[r].Zones {
zones = append(zones, Regions[r].Zones[z])
zones = append(zones, z)
}
}
return zones
Expand All @@ -140,7 +176,7 @@ func ZoneNames() []string {
func RegionFromZone(zone string) string {
for r := range Regions {
for z := range Regions[r].Zones {
if zone == Regions[r].Zones[z] {
if zone == z {
return r
}
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/types/powervs/validation/machinepool.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ func ValidateMachinePool(p *powervs.MachinePool, fldPath *field.Path) field.Erro

// Validate SysType
if p.SysType != "" {
const sysTypeRegex = `^(?:e980|s922(-.*|))$`
const sysTypeRegex = `^(?:e980|e1080|s1022|s922(-.*|))$`
// Allowing for a staging-only pattern of s922-* but not exposing here
if !regexp.MustCompile(sysTypeRegex).MatchString(p.SysType) {
allErrs = append(allErrs, field.Invalid(fldPath.Child("sysType"), p.SysType, "system type must be one of {e980,s922}"))
allErrs = append(allErrs, field.Invalid(fldPath.Child("sysType"), p.SysType, "system type must be one of {e980,e1080,s922,s1022}"))
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/types/powervs/validation/machinepool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func TestValidateMachinePool(t *testing.T) {
pool: &powervs.MachinePool{
SysType: "p922",
},
expected: `^test-path\.sysType: Invalid value: "p922": system type must be one of {e980,s922}$`,
expected: `^test-path\.sysType: Invalid value: "p922": system type must be one of {e980,e1080,s922,s1022}$`,
},
}
for _, tc := range cases {
Expand Down