Skip to content

Commit

Permalink
Merge pull request #3320 from openshift-cherrypick-robot/cherry-pick-…
Browse files Browse the repository at this point in the history
…3269-to-release-4.3

[release-4.3] Bug 1786364: filter out unsupported regions in Azure
  • Loading branch information
openshift-merge-robot authored Mar 25, 2020
2 parents 49a0416 + 96ad80b commit 9d52b2d
Show file tree
Hide file tree
Showing 13 changed files with 7,470 additions and 3 deletions.
5 changes: 4 additions & 1 deletion Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 40 additions & 2 deletions pkg/asset/installconfig/azure/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/pkg/errors"
survey "gopkg.in/AlecAivazis/survey.v1"

azres "github.com/Azure/azure-sdk-for-go/profiles/latest/resources/mgmt/resources"
azsub "github.com/Azure/azure-sdk-for-go/profiles/latest/resources/mgmt/subscriptions"
)

Expand All @@ -27,12 +28,24 @@ func Platform() (*azure.Platform, error) {
if err != nil {
return nil, errors.Wrap(err, "failed to get list of regions")
}

resourceCapableRegions, err := getResourceCapableRegions()
if err != nil {
return nil, errors.Wrap(err, "failed to get list of resources to check available regions")
}

longRegions := make([]string, 0, len(regions))
shortRegions := make([]string, 0, len(regions))
for id, location := range regions {
longRegions = append(longRegions, fmt.Sprintf("%s (%s)", id, location))
shortRegions = append(shortRegions, id)
for _, resourceCapableRegion := range resourceCapableRegions {
// filter our regions not capable of having resources created (we check for resource groups)
if resourceCapableRegion == location {
longRegions = append(longRegions, fmt.Sprintf("%s (%s)", id, location))
shortRegions = append(shortRegions, id)
}
}
}

regionTransform := survey.TransformString(func(s string) string {
return strings.SplitN(s, " ", 2)[0]
})
Expand Down Expand Up @@ -95,3 +108,28 @@ func getRegions() (map[string]string, error) {
}
return allLocations, nil
}

func getResourceCapableRegions() ([]string, error) {
session, err := GetSession()
if err != nil {
return nil, err
}

client := azres.NewProvidersClient(session.Credentials.SubscriptionID)
client.Authorizer = session.Authorizer
ctx, cancel := context.WithTimeout(context.TODO(), 30*time.Second)
defer cancel()

provider, err := client.Get(ctx, "Microsoft.Resources", "")
if err != nil {
return nil, err
}

for _, resType := range *provider.ResourceTypes {
if *resType.ResourceType == "resourceGroups" {
return *resType.Locations, nil
}
}

return []string{}, nil
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 9d52b2d

Please sign in to comment.