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

Fix RollingUpdate behaviour when using LaunchTemplates for both kops & terraform spec updates #8261

Merged
merged 1 commit into from
Jan 4, 2020
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
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"

"k8s.io/kops/upup/pkg/fi"
Expand All @@ -30,6 +31,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 @@ -271,6 +273,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 @@ -284,7 +287,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 @@ -345,12 +348,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 @@ -381,6 +398,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