Skip to content

Commit 7cc6e3c

Browse files
authored
Merge pull request kubernetes#3528 from qqshfox/patch-2
Fix pricing endpoint in AWS China Region
2 parents 33bd5fc + b5f95e0 commit 7cc6e3c

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

cluster-autoscaler/cloudprovider/aws/aws_util.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@ import (
3131
)
3232

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

3940
type response struct {
@@ -53,6 +54,13 @@ type productAttributes struct {
5354

5455
// GenerateEC2InstanceTypes returns a map of ec2 resources
5556
func GenerateEC2InstanceTypes(region string) (map[string]*InstanceType, error) {
57+
var pricingUrlTemplate string
58+
if strings.HasPrefix(region, "cn-") {
59+
pricingUrlTemplate = ec2PricingServiceUrlTemplateCN
60+
} else {
61+
pricingUrlTemplate = ec2PricingServiceUrlTemplate
62+
}
63+
5664
instanceTypes := make(map[string]*InstanceType)
5765

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

67-
url := fmt.Sprintf(ec2PricingServiceUrlTemplate, r.ID())
75+
url := fmt.Sprintf(pricingUrlTemplate, r.ID())
6876
klog.V(1).Infof("fetching %s\n", url)
6977
res, err := http.Get(url)
7078
if err != nil {

0 commit comments

Comments
 (0)