-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Make AWS Pricing API Region Configurable via Env Var or Parameter #8172
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…on override Adds support for configuring the AWS pricing API region using the PRICING_REGION_OVERRIDE environment variable or a function parameter. Defaults remain backward compatible with region-based fallbacks and us-east-1.
✅ Deploy Preview for karpenter-docs-prod canceled.
|
func NewAPI(cfg aws.Config, pricingRegionOverride ...string) *pricing.Client { | ||
pricingRegion := "us-east-1" | ||
|
||
if val := os.Getenv("PRICING_REGION_OVERRIDE"); val != "" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than use the os.Getenv
here, can we match the pattern established with other operator options?
karpenter-provider-aws/pkg/operator/options/options.go
Lines 47 to 56 in 352a94b
func (o *Options) AddFlags(fs *coreoptions.FlagSet) { | |
fs.StringVar(&o.ClusterCABundle, "cluster-ca-bundle", env.WithDefaultString("CLUSTER_CA_BUNDLE", ""), "Cluster CA bundle for nodes to use for TLS connections with the API server. If not set, this is taken from the controller's TLS configuration.") | |
fs.StringVar(&o.ClusterName, "cluster-name", env.WithDefaultString("CLUSTER_NAME", ""), "[REQUIRED] The kubernetes cluster name for resource discovery.") | |
fs.StringVar(&o.ClusterEndpoint, "cluster-endpoint", env.WithDefaultString("CLUSTER_ENDPOINT", ""), "The external kubernetes cluster endpoint for new nodes to connect with. If not specified, will discover the cluster endpoint using DescribeCluster API.") | |
fs.BoolVarWithEnv(&o.IsolatedVPC, "isolated-vpc", "ISOLATED_VPC", false, "If true, then assume we can't reach AWS services which don't have a VPC endpoint. This also has the effect of disabling look-ups to the AWS on-demand pricing endpoint.") | |
fs.BoolVarWithEnv(&o.EKSControlPlane, "eks-control-plane", "EKS_CONTROL_PLANE", false, "Marking this true means that your cluster is running with an EKS control plane and Karpenter should attempt to discover cluster details from the DescribeCluster API ") | |
fs.Float64Var(&o.VMMemoryOverheadPercent, "vm-memory-overhead-percent", utils.WithDefaultFloat64("VM_MEMORY_OVERHEAD_PERCENT", 0.075), "The VM memory overhead as a percent that will be subtracted from the total memory for all instance types when cached information is unavailable.") | |
fs.StringVar(&o.InterruptionQueue, "interruption-queue", env.WithDefaultString("INTERRUPTION_QUEUE", ""), "Interruption queue is the name of the SQS queue used for processing interruption events from EC2. Interruption handling is disabled if not specified. Enabling interruption handling may require additional permissions on the controller service account. Additional permissions are outlined in the docs.") | |
fs.IntVar(&o.ReservedENIs, "reserved-enis", env.WithDefaultInt("RESERVED_ENIS", 0), "Reserved ENIs are not included in the calculations for max-pods or kube-reserved. This is most often used in the VPC CNI custom networking setup https://docs.aws.amazon.com/eks/latest/userguide/cni-custom-network.html.") | |
} |
return pricing.NewFromConfig(pricingCfg) | ||
// NewAPI returns a pricing API configured based on a specific region, | ||
// with an optional override for the pricing endpoint region. | ||
func NewAPI(cfg aws.Config, pricingRegionOverride ...string) *pricing.Client { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
func NewAPI(cfg aws.Config, pricingRegionOverride ...string) *pricing.Client { | |
func NewAPI(cfg aws.Config, regionOverride string) *pricing.Client { |
} else if len(pricingRegionOverride) > 0 && pricingRegionOverride[0] != "" { | ||
// If caller explicitly provided a region, honor it | ||
pricingRegion = pricingRegionOverride[0] | ||
} else { | ||
// Otherwise use existing fallback logic | ||
if strings.HasPrefix(cfg.Region, "ap-") { | ||
pricingRegion = "ap-south-1" | ||
} else if strings.HasPrefix(cfg.Region, "cn-") { | ||
pricingRegion = "cn-northwest-1" | ||
} else if strings.HasPrefix(cfg.Region, "eu-") { | ||
pricingRegion = "eu-central-1" | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than adding these conditionals, can we just override it if the override is not == ""
Adds support for configuring the AWS pricing API region using the PRICING_REGION_OVERRIDE environment variable or a function parameter. Defaults remain backward compatible with region-based fallbacks and us-east-1.
Fixes #8166
Description
feat(pricing): Make AWS Pricing API region configurable
This change allows consumers to override the default pricing region fallback behavior by either:
PRICING_REGION_OVERRIDE
environment variableregionOverride
string to theNewAPI
constructorThe default region logic (
us-east-1
,ap-south-1
,cn-northwest-1
,eu-central-1
) remains as fallback if no override is provided, maintaining backward compatibility. This change supports customers with restricted region access and avoids hardcoding assumptions.How was this change tested?
Does this change impact docs?
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.