Skip to content

Commit

Permalink
Merge pull request #2440 from Jeffwan/cherry-pick-1.16
Browse files Browse the repository at this point in the history
Cherry pick  #2385 #2401 #2428 to 1.16
  • Loading branch information
k8s-ci-robot authored Oct 11, 2019
2 parents dd43a0a + 415bbbd commit e151e4f
Show file tree
Hide file tree
Showing 4 changed files with 142 additions and 5 deletions.
25 changes: 24 additions & 1 deletion cluster-autoscaler/cloudprovider/aws/auto_scaling_groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -461,9 +461,32 @@ func (m *asgCache) buildAsgFromAWS(g *autoscaling.Group) (*asg, error) {
}

func (m *asgCache) buildLaunchTemplateFromSpec(ltSpec *autoscaling.LaunchTemplateSpecification) *launchTemplate {
// NOTE(jaypipes): The LaunchTemplateSpecification.Version is a pointer to
// string. When the pointer is nil, EC2 AutoScaling API considers the value
// to be "$Default", however aws.StringValue(ltSpec.Version) will return an
// empty string (which is not considered the same as "$Default" or a nil
// string pointer. So, in order to not pass an empty string as the version
// for the launch template when we communicate with the EC2 AutoScaling API
// using the information in the launchTemplate, we store the string
// "$Default" here when the ltSpec.Version is a nil pointer.
//
// See:
//
// https://github.com/kubernetes/autoscaler/issues/1728
// https://github.com/aws/aws-sdk-go/blob/81fad3b797f4a9bd1b452a5733dd465eefef1060/service/autoscaling/api.go#L10666-L10671
//
// A cleaner alternative might be to make launchTemplate.version a string
// pointer instead of a string, or even store the aws-sdk-go's
// LaunchTemplateSpecification structs directly.
var version string
if ltSpec.Version == nil {
version = "$Default"
} else {
version = aws.StringValue(ltSpec.Version)
}
return &launchTemplate{
name: aws.StringValue(ltSpec.LaunchTemplateName),
version: aws.StringValue(ltSpec.Version),
version: version,
}
}

Expand Down
64 changes: 64 additions & 0 deletions cluster-autoscaler/cloudprovider/aws/auto_scaling_groups_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ import (
"testing"

"github.com/stretchr/testify/assert"

sdkaws "github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/autoscaling"
)

func TestBuildAsg(t *testing.T) {
Expand All @@ -46,3 +49,64 @@ func validateAsg(t *testing.T, asg *asg, name string, minSize int, maxSize int)
assert.Equal(t, minSize, asg.minSize)
assert.Equal(t, maxSize, asg.maxSize)
}

func TestBuildLaunchTemplateFromSpec(t *testing.T) {
assert := assert.New(t)

units := []struct {
name string
in *autoscaling.LaunchTemplateSpecification
exp *launchTemplate
}{
{
name: "non-default, specified version",
in: &autoscaling.LaunchTemplateSpecification{
LaunchTemplateName: sdkaws.String("foo"),
Version: sdkaws.String("1"),
},
exp: &launchTemplate{
name: "foo",
version: "1",
},
},
{
name: "non-default, specified $Latest",
in: &autoscaling.LaunchTemplateSpecification{
LaunchTemplateName: sdkaws.String("foo"),
Version: sdkaws.String("$Latest"),
},
exp: &launchTemplate{
name: "foo",
version: "$Latest",
},
},
{
name: "specified $Default",
in: &autoscaling.LaunchTemplateSpecification{
LaunchTemplateName: sdkaws.String("foo"),
Version: sdkaws.String("$Default"),
},
exp: &launchTemplate{
name: "foo",
version: "$Default",
},
},
{
name: "no version specified",
in: &autoscaling.LaunchTemplateSpecification{
LaunchTemplateName: sdkaws.String("foo"),
Version: nil,
},
exp: &launchTemplate{
name: "foo",
version: "$Default",
},
},
}

cache := &asgCache{}
for _, unit := range units {
got := cache.buildLaunchTemplateFromSpec(unit.in)
assert.Equal(unit.exp, got)
}
}
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 @@ -146,9 +146,14 @@ func newAWSSDKProvider(cfg *provider_aws.CloudConfig) *awsSDKProvider {
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 Down Expand Up @@ -182,8 +187,11 @@ func createAWSManagerInternal(

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

if autoScalingService == nil {
autoScalingService = &autoScalingWrapper{autoscaling.New(sess), map[string]string{}}
Expand Down
42 changes: 42 additions & 0 deletions cluster-autoscaler/cloudprovider/aws/ec2_instance_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -1485,4 +1485,46 @@ var InstanceTypes = map[string]*instanceType{
MemoryMb: 32768,
GPU: 0,
},
"g4dn.xlarge": {
InstanceType: "g4dn.xlarge",
VCPU: 4,
MemoryMb: 16384,
GPU: 1,
},
"g4dn.2xlarge": {
InstanceType: "g4dn.2xlarge",
VCPU: 8,
MemoryMb: 32768,
GPU: 1,
},
"g4dn.4xlarge": {
InstanceType: "g4dn.4xlarge",
VCPU: 16,
MemoryMb: 65536,
GPU: 1,
},
"g4dn.8xlarge": {
InstanceType: "g4dn.8xlarge",
VCPU: 32,
MemoryMb: 131072,
GPU: 1,
},
"g4dn.16xlarge": {
InstanceType: "g4dn.16xlarge",
VCPU: 64,
MemoryMb: 262144,
GPU: 1,
},
"g4dn.12xlarge": {
InstanceType: "g4dn.12xlarge",
VCPU: 48,
MemoryMb: 196608,
GPU: 4,
},
"g4dn.metal": { //coming soon
InstanceType: "g4dn.metal",
VCPU: 96,
MemoryMb: 393216,
GPU: 8,
},
}

0 comments on commit e151e4f

Please sign in to comment.