Skip to content
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

Cherry pick #2428 to 1.13 #2464

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions cluster-autoscaler/cloudprovider/aws/aws_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,14 @@ type asgTemplate struct {
func getRegion(cfg ...*aws.Config) string {
region, present := os.LookupEnv("AWS_REGION")
if !present {
svc := ec2metadata.New(session.New(), cfg...)
if r, err := svc.Region(); err == nil {
region = r
sess, err := session.NewSession()
if err != nil {
klog.Errorf("Error getting AWS session while retrieving region: %v", err)
} else {
svc := ec2metadata.New(sess, cfg...)
if r, err := svc.Region(); err == nil {
region = r
}
}
}
return region
Expand All @@ -95,7 +100,10 @@ func createAWSManagerInternal(
}

if autoScalingService == nil || ec2Service == nil {
sess := session.New(aws.NewConfig().WithRegion(getRegion()))
sess, err := session.NewSession(aws.NewConfig().WithRegion(getRegion()))
if err != nil {
return nil, err
}

if autoScalingService == nil {
autoScalingService = &autoScalingWrapper{autoscaling.New(sess), map[string]string{}}
Expand Down