github.com/openshift/installer@v1.4.17/pkg/quota/aws/limits.go (about) 1 package aws 2 3 import ( 4 "context" 5 "fmt" 6 7 "github.com/aws/aws-sdk-go/aws" 8 "github.com/aws/aws-sdk-go/service/servicequotas" 9 "github.com/pkg/errors" 10 "k8s.io/apimachinery/pkg/util/sets" 11 ) 12 13 // SupportedRegions is a list of AWS regions that support the servicequota APIs. 14 // see https://docs.aws.amazon.com/general/latest/gr/servicequotas.html 15 var SupportedRegions = sets.NewString( 16 "us-east-2", 17 "us-east-1", 18 "us-west-1", 19 "us-west-2", 20 "ap-south-1", 21 "ap-northeast-3", 22 "ap-northeast-2", 23 "ap-southeast-1", 24 "ap-southeast-2", 25 "ap-northeast-1", 26 "ca-central-1", 27 "ca-west-1", 28 "eu-central-1", 29 "eu-west-1", 30 "eu-west-2", 31 "eu-west-3", 32 "sa-east-1", 33 ) 34 35 // record stores the data from quota limits and usages. 36 type record struct { 37 Service string 38 Name string 39 global bool 40 41 Value int64 42 } 43 44 func loadLimits(ctx context.Context, client *servicequotas.ServiceQuotas, services ...string) ([]record, error) { 45 records := map[string]record{} 46 key := func(q *servicequotas.ServiceQuota) string { 47 return fmt.Sprintf("%s/%s", aws.StringValue(q.ServiceCode), aws.StringValue(q.QuotaCode)) 48 } 49 50 for _, service := range services { 51 if err := client.ListAWSDefaultServiceQuotasPagesWithContext(ctx, 52 &servicequotas.ListAWSDefaultServiceQuotasInput{ServiceCode: aws.String(service)}, 53 func(page *servicequotas.ListAWSDefaultServiceQuotasOutput, lastPage bool) bool { 54 for _, sq := range page.Quotas { 55 records[key(sq)] = record{ 56 Service: service, 57 Name: aws.StringValue(sq.QuotaCode), 58 global: aws.BoolValue(sq.GlobalQuota), 59 Value: int64(aws.Float64Value(sq.Value)), 60 } 61 } 62 return !lastPage 63 }); err != nil { 64 return nil, errors.Wrapf(err, "failed to list default serviceqquotas for %s", service) 65 66 } 67 68 if err := client.ListServiceQuotasPagesWithContext(ctx, 69 &servicequotas.ListServiceQuotasInput{ServiceCode: aws.String(service)}, 70 func(page *servicequotas.ListServiceQuotasOutput, lastPage bool) bool { 71 for _, sq := range page.Quotas { 72 records[key(sq)] = record{ 73 Service: service, 74 Name: aws.StringValue(sq.QuotaCode), 75 global: aws.BoolValue(sq.GlobalQuota), 76 Value: int64(aws.Float64Value(sq.Value)), 77 } 78 } 79 return !lastPage 80 }); err != nil { 81 return nil, errors.Wrapf(err, "failed to list serviceqquotas for %s", service) 82 } 83 84 } 85 var ret []record 86 for _, r := range records { 87 ret = append(ret, r) 88 } 89 return ret, nil 90 }