Skip to content

Commit

Permalink
Allow zone wise sysTypes
Browse files Browse the repository at this point in the history
  • Loading branch information
AshwinHIBM committed Dec 31, 2024
1 parent 9598d63 commit 008825f
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 52 deletions.
2 changes: 1 addition & 1 deletion pkg/asset/cluster/tfvars/tfvars.go
Original file line number Diff line number Diff line change
Expand Up @@ -937,7 +937,7 @@ func (t *TerraformVariables) Generate(parents asset.Parents) error {

cpStanza := installConfig.Config.ControlPlane
if cpStanza == nil || cpStanza.Platform.PowerVS == nil || cpStanza.Platform.PowerVS.SysType == "" {
sysTypes, err := powervs.AvailableSysTypes(installConfig.Config.PowerVS.Region)
sysTypes, err := powervs.AvailableSysTypes(installConfig.Config.PowerVS.Region, installConfig.Config.PowerVS.Zone)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/asset/installconfig/platformprovisioncheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func (a *PlatformProvisionCheck) Generate(dependencies asset.Parents) error {
return err
}

err = powervsconfig.ValidateSystemTypeForRegion(client, ic.Config)
err = powervsconfig.ValidateSystemTypeForZone(client, ic.Config)
if err != nil {
return err
}
Expand Down
6 changes: 5 additions & 1 deletion pkg/asset/installconfig/powervs/regions.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,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
8 changes: 4 additions & 4 deletions pkg/asset/installconfig/powervs/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,12 +255,12 @@ func ValidateResourceGroup(client API, ic *types.InstallConfig) error {
return nil
}

// ValidateSystemTypeForRegion checks if the specified sysType is available in the target region.
func ValidateSystemTypeForRegion(client API, ic *types.InstallConfig) error {
// ValidateSystemTypeForZone checks if the specified sysType is available in the target zone.
func ValidateSystemTypeForZone(client API, ic *types.InstallConfig) error {
if ic.ControlPlane == nil || ic.ControlPlane.Platform.PowerVS == nil || ic.ControlPlane.Platform.PowerVS.SysType == "" {
return nil
}
availableOnes, err := powervstypes.AvailableSysTypes(ic.PowerVS.Region)
availableOnes, err := powervstypes.AvailableSysTypes(ic.PowerVS.Region, ic.PowerVS.Zone)
if err != nil {
return fmt.Errorf("failed to obtain available SysTypes for: %s", ic.PowerVS.Region)
}
Expand All @@ -275,7 +275,7 @@ func ValidateSystemTypeForRegion(client API, ic *types.InstallConfig) error {
if found {
return nil
}
return fmt.Errorf("%s is not available in: %s", requested, ic.PowerVS.Region)
return fmt.Errorf("%s is not available in: %s", requested, ic.PowerVS.Zone)
}

// ValidateServiceInstance validates the optional service instance GUID in our install config.
Expand Down
22 changes: 12 additions & 10 deletions pkg/asset/installconfig/powervs/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ var (
validPrivateSubnetUSSouth2ID,
}
validUserID = "valid-user@example.com"
validZone = "dal10"
validZone = "dal12"

existingDNSRecordsResponse = []powervs.DNSRecordResponse{
{
Expand Down Expand Up @@ -132,7 +132,7 @@ var (
}
defaultSysType = "s922"
newSysType = "s1022"
invalidRegion = "foo"
invalidZone = "dall11"
validServiceInstanceGUID = ""
)

Expand Down Expand Up @@ -561,22 +561,22 @@ func TestValidatePERAvailability(t *testing.T) {
}
}

func TestValidateSystemTypeForRegion(t *testing.T) {
func TestValidateSystemTypeForZone(t *testing.T) {
cases := []struct {
name string
edits editFunctions
errorMsg string
}{
{
name: "Unknown Region specified",
name: "Unknown Zone specified",
edits: editFunctions{
func(ic *types.InstallConfig) {
ic.Platform.PowerVS.Region = invalidRegion
ic.Platform.PowerVS.Region = invalidZone
ic.ControlPlane.Platform.PowerVS = validMachinePool()
ic.ControlPlane.Platform.PowerVS.SysType = defaultSysType
},
},
errorMsg: fmt.Sprintf("failed to obtain available SysTypes for: %s", invalidRegion),
errorMsg: fmt.Sprintf("failed to obtain available SysTypes for: %s", invalidZone),
},
{
name: "No Platform block",
Expand All @@ -597,21 +597,23 @@ func TestValidateSystemTypeForRegion(t *testing.T) {
errorMsg: "",
},
{
name: "Unavailable SysType specified for Dallas Region",
name: "Unavailable SysType specified for dal12 Zone",
edits: editFunctions{
func(ic *types.InstallConfig) {
ic.Platform.PowerVS.Region = validRegion
ic.Platform.PowerVS.Zone = validZone
ic.ControlPlane.Platform.PowerVS = validMachinePool()
ic.ControlPlane.Platform.PowerVS.SysType = newSysType
},
},
errorMsg: fmt.Sprintf("%s is not available in: %s", newSysType, validRegion),
errorMsg: fmt.Sprintf("%s is not available in: %s", newSysType, validZone),
},
{
name: "Good Region/SysType combo specified",
name: "Good Zone/SysType combo specified",
edits: editFunctions{
func(ic *types.InstallConfig) {
ic.Platform.PowerVS.Region = validRegion
ic.Platform.PowerVS.Zone = validZone
ic.ControlPlane.Platform.PowerVS = validMachinePool()
ic.ControlPlane.Platform.PowerVS.SysType = defaultSysType
},
Expand All @@ -634,7 +636,7 @@ func TestValidateSystemTypeForRegion(t *testing.T) {
edit(editedInstallConfig)
}

aggregatedErrors := powervs.ValidateSystemTypeForRegion(powervsClient, editedInstallConfig)
aggregatedErrors := powervs.ValidateSystemTypeForZone(powervsClient, editedInstallConfig)
if tc.errorMsg != "" {
assert.Regexp(t, tc.errorMsg, aggregatedErrors)
} else {
Expand Down
4 changes: 2 additions & 2 deletions pkg/asset/machines/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,11 @@ func defaultPowerVSMachinePoolPlatform(ic *types.InstallConfig) powervstypes.Mac
SysType: "s922",
}

sysTypes, err = powervstypes.AvailableSysTypes(ic.PowerVS.Region)
sysTypes, err = powervstypes.AvailableSysTypes(ic.PowerVS.Region, ic.PowerVS.Zone)
if err == nil {
defaultMp.SysType = sysTypes[0]
} else {
logrus.Warnf("For given region %v, AvailableSysTypes returns %v", ic.PowerVS.Region, err)
logrus.Warnf("For given zone %v, AvailableSysTypes returns %v", ic.PowerVS.Zone, err)
}

return defaultMp
Expand Down
116 changes: 83 additions & 33 deletions pkg/types/powervs/powervs_regions.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,76 +15,119 @@ type Region struct {
Description string
VPCRegion string
COSRegion string
Zones []string
SysTypes []string
Zones map[string]Zone
VPCZones []string
}

// 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",
COSRegion: "us-south",
Zones: []string{"dal10", "dal12"},
SysTypes: []string{"s922", "e980"},
VPCZones: []string{"us-south-1", "us-south-2", "us-south-3"},
Zones: map[string]Zone{
"dal10": {
SysTypes: []string{"s922", "s1022", "e980", "e1080"},
},
"dal12": {
SysTypes: []string{"s922", "e980"},
},
},
VPCZones: []string{"us-south-1", "us-south-2", "us-south-3"},
},
"eu-de": {
Description: "Frankfurt, Germany",
VPCRegion: "eu-de",
COSRegion: "eu-de",
Zones: []string{"eu-de-1", "eu-de-2"},
SysTypes: []string{"s922", "e980"},
VPCZones: []string{"eu-de-2", "eu-de-3"},
Zones: map[string]Zone{
"eu-de-1": {
SysTypes: []string{"s922", "s1022", "e980"},
},
"eu-de-2": {
SysTypes: []string{"s922", "e980"},
},
},
VPCZones: []string{"eu-de-1", "eu-de-2", "eu-de-3"},
},
"lon": {
Description: "London, UK",
VPCRegion: "eu-gb",
COSRegion: "eu-gb",
Zones: []string{"lon06"},
SysTypes: []string{"s922", "e980"},
VPCZones: []string{"eu-gb-1", "eu-gb-2", "eu-gb-3"},
Zones: map[string]Zone{
"lon06": {
SysTypes: []string{"s922", "e980"},
},
},
VPCZones: []string{"eu-gb-1", "eu-gb-2", "eu-gb-3"},
},
"mad": {
Description: "Madrid, Spain",
VPCRegion: "eu-es",
COSRegion: "eu-de", // @HACK - PowerVS says COS not supported in this region
Zones: []string{"mad02", "mad04"},
SysTypes: []string{"e980", "s1022"},
VPCZones: []string{"eu-es-1", "eu-es-2"},
Zones: map[string]Zone{
"mad02": {
SysTypes: []string{"s922", "s1022", "e980"},
},
"mad04": {
SysTypes: []string{"s1022", "e980", "e1080"},
},
},
VPCZones: []string{"eu-es-1", "eu-es-2"},
},
"osa": {
Description: "Osaka, Japan",
VPCRegion: "jp-osa",
COSRegion: "jp-osa",
Zones: []string{"osa21"},
SysTypes: []string{"s922", "e980"},
VPCZones: []string{"jp-osa-1", "jp-osa-2", "jp-osa-3"},
Zones: map[string]Zone{
"osa21": {
SysTypes: []string{"s922", "s1022", "e980"},
},
},
VPCZones: []string{"jp-osa-1", "jp-osa-2", "jp-osa-3"},
},
"sao": {
Description: "São Paulo, Brazil",
VPCRegion: "br-sao",
COSRegion: "br-sao",
Zones: []string{"sao01", "sao04"},
SysTypes: []string{"s922", "e980"},
VPCZones: []string{"br-sao-1", "br-sao-2", "br-sao-3"},
Zones: map[string]Zone{
"sao01": {
SysTypes: []string{"s922", "e980"},
},
"sao04": {
SysTypes: []string{"s922", "e980"},
},
},
VPCZones: []string{"br-sao-1", "br-sao-2", "br-sao-3"},
},
"syd": {
Description: "Sydney, Australia",
VPCRegion: "au-syd",
COSRegion: "au-syd",
Zones: []string{"syd04"},
SysTypes: []string{"s922", "e980"},
VPCZones: []string{"au-syd-1", "au-syd-2", "au-syd-3"},
Zones: map[string]Zone{
"syd04": {
SysTypes: []string{"s922", "e980"},
},
},
VPCZones: []string{"au-syd-1", "au-syd-2", "au-syd-3"},
},
"wdc": {
Description: "Washington DC, USA",
VPCRegion: "us-east",
COSRegion: "us-east",
Zones: []string{"wdc06", "wdc07"},
SysTypes: []string{"s922", "e980"},
VPCZones: []string{"us-east-1", "us-east-2", "us-east-3"},
Zones: map[string]Zone{
"wdc06": {
SysTypes: []string{"s922", "e980"},
},
"wdc07": {
SysTypes: []string{"s922", "s1022", "e980", "e1080"},
},
},
VPCZones: []string{"us-east-1", "us-east-2", "us-east-3"},
},
}

Expand Down Expand Up @@ -124,7 +167,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 @@ -137,7 +180,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 @@ -147,7 +190,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 All @@ -156,19 +199,26 @@ func RegionFromZone(zone string) string {
}

// AvailableSysTypes returns the default system type for the zone.
func AvailableSysTypes(region string) ([]string, error) {
func AvailableSysTypes(region string, zone string) ([]string, error) {
knownRegion, ok := Regions[region]
if !ok {
return nil, fmt.Errorf("unknown region name provided")
}
return knownRegion.SysTypes, nil
var knownZone Zone
knownZone, ok = knownRegion.Zones[zone]
if !ok {
return nil, fmt.Errorf("unknown zone name provided")
}
return knownZone.SysTypes, nil
}

// AllKnownSysTypes returns aggregated known system types from all regions.
func AllKnownSysTypes() sets.Set[string] {
sysTypes := sets.New[string]()
for _, region := range Regions {
sysTypes.Insert(region.SysTypes...)
for region := range Regions {
for _, zones := range Regions[region].Zones {
sysTypes.Insert(zones.SysTypes...)
}
}
return sysTypes
}
Expand Down

0 comments on commit 008825f

Please sign in to comment.