diff --git a/README.md b/README.md index bcbc2a2c1..27ab3cb87 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ The best description is "Kubernetes API on top, programmable back." + [Adding a New Provider via the Provider Interface](#adding-a-new-provider-via-the-provider-interface) * [Testing](#testing) + [Testing the Azure Provider Client](#testing-the-azure-provider-client) -* [Known quirks and workarounds](#known-quirks-and-workaroundss) +* [Known quirks and workarounds](#known-quirks-and-workarounds) * [Contributing](#contributing) ## How It Works diff --git a/providers/azure/aci.go b/providers/azure/aci.go index 31e9ef0d9..db1766984 100644 --- a/providers/azure/aci.go +++ b/providers/azure/aci.go @@ -52,6 +52,28 @@ type AuthConfig struct { RegistryToken string `json:"registrytoken,omitempty"` } +// See https://docs.microsoft.com/en-us/azure/container-instances/container-instances-quotas for valid regions. +var validAciRegions = []string{ + "westeurope", + "westus", + "eastus", + "southeastasia", +} + +// isValidACIRegion checks to make sure we're using a valid ACI region +func isValidACIRegion(region string) bool { + regionLower := strings.ToLower(region) + regionTrimmed := strings.Replace(regionLower, " ", "", -1) + + for _, validRegion := range validAciRegions { + if regionTrimmed == validRegion { + return true + } + } + + return false +} + // NewACIProvider creates a new ACIProvider. func NewACIProvider(config string, rm *manager.ResourceManager, nodeName, operatingSystem string, internalIP string, daemonEndpointPort int32) (*ACIProvider, error) { var p ACIProvider @@ -139,6 +161,12 @@ func NewACIProvider(config string, rm *manager.ResourceManager, nodeName, operat if p.region == "" { return nil, errors.New("Region can not be empty please set ACI_REGION") } + if r := p.region; !isValidACIRegion(r) { + unsupportedRegionMessage := fmt.Sprintf("Region %s is invalid. Current supported regions are: %s", + r, strings.Join(validAciRegions, ", ")) + + return nil, errors.New(unsupportedRegionMessage) + } // Set sane defaults for Capacity in case config is not supplied p.cpu = "20" @@ -508,7 +536,7 @@ func (p *ACIProvider) getVolumes(pod *v1.Pod) ([]aci.Volume, error) { } if secret == nil { - return nil, fmt.Errorf("Getting secret for AzureFile volume returned an empty secret.") + return nil, fmt.Errorf("Getting secret for AzureFile volume returned an empty secret") } volumes = append(volumes, aci.Volume{