Skip to content

Commit

Permalink
Automated cherry pick of kubernetes#8261: Fix RollingUpdate behaviour…
Browse files Browse the repository at this point in the history
… when using LaunchTemplates for kubernetes#8567: Treat nil of LaunchTemplateSpecification.Version as  from kubernetes#8808
  • Loading branch information
kaldorn committed Jul 29, 2020
1 parent 5a1c701 commit 0d52fba
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
20 changes: 19 additions & 1 deletion upup/pkg/fi/cloudup/awstasks/autoscalinggroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"fmt"
"reflect"
"sort"
"strconv"
"strings"
"sync"

Expand All @@ -31,6 +32,7 @@ import (

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/autoscaling"
"github.com/aws/aws-sdk-go/service/ec2"
"k8s.io/klog"
)

Expand Down Expand Up @@ -303,6 +305,7 @@ func (v *AutoscalingGroup) RenderAWS(t *awsup.AWSAPITarget, a, e, changes *Autos
LaunchTemplateName: e.LaunchTemplate.ID,
}
}

// @check if we are using mixed instance policies
if e.UseMixedInstancesPolicy() {
// we can zero this out for now and use the mixed instance policy for definition
Expand All @@ -316,7 +319,7 @@ func (v *AutoscalingGroup) RenderAWS(t *awsup.AWSAPITarget, a, e, changes *Autos
SpotMaxPrice: e.MixedSpotMaxPrice,
},
LaunchTemplate: &autoscaling.LaunchTemplate{
LaunchTemplateSpecification: &autoscaling.LaunchTemplateSpecification{LaunchTemplateName: e.LaunchTemplate.ID},
LaunchTemplateSpecification: &autoscaling.LaunchTemplateSpecification{LaunchTemplateName: e.LaunchTemplate.ID, Version: aws.String("1")},
},
}
p := request.MixedInstancesPolicy.LaunchTemplate
Expand Down Expand Up @@ -378,12 +381,26 @@ func (v *AutoscalingGroup) RenderAWS(t *awsup.AWSAPITarget, a, e, changes *Autos
return req.MixedInstancesPolicy
}

launchTemplateVersion := "1"
if e.LaunchTemplate != nil {
dltRequest := &ec2.DescribeLaunchTemplatesInput{
LaunchTemplateNames: []*string{e.LaunchTemplate.ID},
}
dltResponse, err := t.Cloud.EC2().DescribeLaunchTemplates(dltRequest)
if err != nil {
klog.Warningf("could not find existing LaunchTemplate: %v", err)
} else {
launchTemplateVersion = strconv.FormatInt(*dltResponse.LaunchTemplates[0].LatestVersionNumber, 10)
}
}

if changes.LaunchTemplate != nil {
// @note: at the moment we are only using launch templates when using mixed instance policies,
// but this might change
setup(request).LaunchTemplate = &autoscaling.LaunchTemplate{
LaunchTemplateSpecification: &autoscaling.LaunchTemplateSpecification{
LaunchTemplateName: changes.LaunchTemplate.ID,
Version: &launchTemplateVersion,
},
}
changes.LaunchTemplate = nil
Expand Down Expand Up @@ -414,6 +431,7 @@ func (v *AutoscalingGroup) RenderAWS(t *awsup.AWSAPITarget, a, e, changes *Autos
setup(request).LaunchTemplate = &autoscaling.LaunchTemplate{
LaunchTemplateSpecification: &autoscaling.LaunchTemplateSpecification{
LaunchTemplateName: e.LaunchTemplate.ID,
Version: &launchTemplateVersion,
},
}
}
Expand Down
4 changes: 2 additions & 2 deletions upup/pkg/fi/cloudup/awsup/aws_cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ func findAutoscalingGroupLaunchConfiguration(c AWSCloud, g *autoscaling.Group) (
//See what version the ASG is set to use
mixedVersion := aws.StringValue(g.MixedInstancesPolicy.LaunchTemplate.LaunchTemplateSpecification.Version)
//Correctly Handle Default and Latest Versions
if mixedVersion == "$Default" || mixedVersion == "$Latest" {
if mixedVersion == "" || mixedVersion == "$Default" || mixedVersion == "$Latest" {
request := &ec2.DescribeLaunchTemplatesInput{
LaunchTemplateNames: []*string{&name},
}
Expand All @@ -608,7 +608,7 @@ func findAutoscalingGroupLaunchConfiguration(c AWSCloud, g *autoscaling.Group) (
return "", fmt.Errorf("error describing launch templates: %v", err)
}
launchTemplate := dltResponse.LaunchTemplates[0]
if mixedVersion == "$Default" {
if mixedVersion == "" || mixedVersion == "$Default" {
version = strconv.FormatInt(*launchTemplate.DefaultVersionNumber, 10)
} else {
version = strconv.FormatInt(*launchTemplate.LatestVersionNumber, 10)
Expand Down

0 comments on commit 0d52fba

Please sign in to comment.