Skip to content

Commit

Permalink
Merge pull request #3697 from zxh326/cluster-autoscaler-release-1.19
Browse files Browse the repository at this point in the history
Fix pricing endpoint in AWS China Region
  • Loading branch information
k8s-ci-robot authored Nov 16, 2020
2 parents 1ba66f5 + a80bf9b commit 06c7138
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions cluster-autoscaler/cloudprovider/aws/aws_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ import (
)

var (
ec2MetaDataServiceUrl = "http://169.254.169.254/latest/dynamic/instance-identity/document"
ec2PricingServiceUrlTemplate = "https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/AmazonEC2/current/%s/index.json"
staticListLastUpdateTime = "2019-10-14"
ec2MetaDataServiceUrl = "http://169.254.169.254/latest/dynamic/instance-identity/document"
ec2PricingServiceUrlTemplate = "https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/AmazonEC2/current/%s/index.json"
ec2PricingServiceUrlTemplateCN = "https://pricing.cn-north-1.amazonaws.com.cn/offers/v1.0/cn/AmazonEC2/current/%s/index.json"
staticListLastUpdateTime = "2019-10-14"
)

type response struct {
Expand All @@ -53,6 +54,13 @@ type productAttributes struct {

// GenerateEC2InstanceTypes returns a map of ec2 resources
func GenerateEC2InstanceTypes(region string) (map[string]*InstanceType, error) {
var pricingUrlTemplate string
if strings.HasPrefix(region, "cn-") {
pricingUrlTemplate = ec2PricingServiceUrlTemplateCN
} else {
pricingUrlTemplate = ec2PricingServiceUrlTemplate
}

instanceTypes := make(map[string]*InstanceType)

resolver := endpoints.DefaultResolver()
Expand All @@ -64,7 +72,7 @@ func GenerateEC2InstanceTypes(region string) (map[string]*InstanceType, error) {
continue
}

url := fmt.Sprintf(ec2PricingServiceUrlTemplate, r.ID())
url := fmt.Sprintf(pricingUrlTemplate, r.ID())
klog.V(1).Infof("fetching %s\n", url)
res, err := http.Get(url)
if err != nil {
Expand Down

0 comments on commit 06c7138

Please sign in to comment.