mirror of https://github.com/kubernetes/kops.git
Use LaunchTemplate id instead of name for ASGs
This commit is contained in:
parent
7b04b97999
commit
ed37c34a92
|
|
@ -18,7 +18,6 @@ package mockautoscaling
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"hash/crc64"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/aws/aws-sdk-go/aws"
|
"github.com/aws/aws-sdk-go/aws"
|
||||||
|
|
@ -78,8 +77,10 @@ func (m *MockAutoscaling) CreateAutoScalingGroup(input *autoscaling.CreateAutoSc
|
||||||
}
|
}
|
||||||
|
|
||||||
if input.LaunchTemplate != nil {
|
if input.LaunchTemplate != nil {
|
||||||
launchTemplateCrc := crc64.Checksum([]byte(aws.StringValue(input.LaunchTemplate.LaunchTemplateName)), crc64.MakeTable(crc64.ECMA))
|
g.LaunchTemplate.LaunchTemplateName = input.AutoScalingGroupName
|
||||||
g.LaunchTemplate.LaunchTemplateId = aws.String(fmt.Sprintf("lt-%x", launchTemplateCrc))
|
if g.LaunchTemplate.LaunchTemplateId == nil {
|
||||||
|
return nil, fmt.Errorf("AutoScalingGroup has LaunchTemplate without ID")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tag := range input.Tags {
|
for _, tag := range input.Tags {
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,8 @@ type MockEC2 struct {
|
||||||
|
|
||||||
InternetGateways map[string]*ec2.InternetGateway
|
InternetGateways map[string]*ec2.InternetGateway
|
||||||
|
|
||||||
LaunchTemplates map[string]*launchTemplateInfo
|
launchTemplateNumber int
|
||||||
|
LaunchTemplates map[string]*launchTemplateInfo
|
||||||
|
|
||||||
NatGateways map[string]*ec2.NatGateway
|
NatGateways map[string]*ec2.NatGateway
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -87,8 +87,9 @@ func (m *MockEC2) CreateLaunchTemplate(request *ec2.CreateLaunchTemplateInput) (
|
||||||
|
|
||||||
klog.V(2).Infof("Mock CreateLaunchTemplate: %v", request)
|
klog.V(2).Infof("Mock CreateLaunchTemplate: %v", request)
|
||||||
|
|
||||||
crc := crc64.Checksum([]byte(aws.StringValue(request.LaunchTemplateName)), crc64.MakeTable(crc64.ECMA))
|
m.launchTemplateNumber++
|
||||||
id := fmt.Sprintf("lt-%x", crc)
|
n := m.launchTemplateNumber
|
||||||
|
id := fmt.Sprintf("lt-%d", n)
|
||||||
|
|
||||||
if m.LaunchTemplates == nil {
|
if m.LaunchTemplates == nil {
|
||||||
m.LaunchTemplates = make(map[string]*launchTemplateInfo)
|
m.LaunchTemplates = make(map[string]*launchTemplateInfo)
|
||||||
|
|
|
||||||
|
|
@ -366,8 +366,8 @@ func (v *AutoscalingGroup) RenderAWS(t *awsup.AWSAPITarget, a, e, changes *Autos
|
||||||
},
|
},
|
||||||
LaunchTemplate: &autoscaling.LaunchTemplate{
|
LaunchTemplate: &autoscaling.LaunchTemplate{
|
||||||
LaunchTemplateSpecification: &autoscaling.LaunchTemplateSpecification{
|
LaunchTemplateSpecification: &autoscaling.LaunchTemplateSpecification{
|
||||||
LaunchTemplateName: e.LaunchTemplate.Name,
|
LaunchTemplateId: e.LaunchTemplate.ID,
|
||||||
Version: aws.String("$Latest"),
|
Version: aws.String("$Latest"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
@ -379,8 +379,8 @@ func (v *AutoscalingGroup) RenderAWS(t *awsup.AWSAPITarget, a, e, changes *Autos
|
||||||
}
|
}
|
||||||
} else if e.LaunchTemplate != nil {
|
} else if e.LaunchTemplate != nil {
|
||||||
request.LaunchTemplate = &autoscaling.LaunchTemplateSpecification{
|
request.LaunchTemplate = &autoscaling.LaunchTemplateSpecification{
|
||||||
LaunchTemplateName: e.LaunchTemplate.Name,
|
LaunchTemplateId: e.LaunchTemplate.ID,
|
||||||
Version: aws.String("$Latest"),
|
Version: aws.String("$Latest"),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return fmt.Errorf("could not find one of launch template, mixed instances policy, or launch configuration")
|
return fmt.Errorf("could not find one of launch template, mixed instances policy, or launch configuration")
|
||||||
|
|
@ -446,8 +446,8 @@ func (v *AutoscalingGroup) RenderAWS(t *awsup.AWSAPITarget, a, e, changes *Autos
|
||||||
|
|
||||||
if changes.LaunchTemplate != nil {
|
if changes.LaunchTemplate != nil {
|
||||||
spec := &autoscaling.LaunchTemplateSpecification{
|
spec := &autoscaling.LaunchTemplateSpecification{
|
||||||
LaunchTemplateName: changes.LaunchTemplate.Name,
|
LaunchTemplateId: changes.LaunchTemplate.ID,
|
||||||
Version: aws.String("$Latest"),
|
Version: aws.String("$Latest"),
|
||||||
}
|
}
|
||||||
if e.UseMixedInstancesPolicy() {
|
if e.UseMixedInstancesPolicy() {
|
||||||
setup(request).LaunchTemplate = &autoscaling.LaunchTemplate{LaunchTemplateSpecification: spec}
|
setup(request).LaunchTemplate = &autoscaling.LaunchTemplate{LaunchTemplateSpecification: spec}
|
||||||
|
|
@ -481,8 +481,8 @@ func (v *AutoscalingGroup) RenderAWS(t *awsup.AWSAPITarget, a, e, changes *Autos
|
||||||
if setup(request).LaunchTemplate == nil {
|
if setup(request).LaunchTemplate == nil {
|
||||||
setup(request).LaunchTemplate = &autoscaling.LaunchTemplate{
|
setup(request).LaunchTemplate = &autoscaling.LaunchTemplate{
|
||||||
LaunchTemplateSpecification: &autoscaling.LaunchTemplateSpecification{
|
LaunchTemplateSpecification: &autoscaling.LaunchTemplateSpecification{
|
||||||
LaunchTemplateName: changes.LaunchTemplate.Name,
|
LaunchTemplateId: changes.LaunchTemplate.ID,
|
||||||
Version: aws.String("$Latest"),
|
Version: aws.String("$Latest"),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue