Skip to content

Commit

Permalink
Merge pull request #8466 from hakman/fix-launch-template-tags
Browse files Browse the repository at this point in the history
Update tags support for LaunchTemplates
  • Loading branch information
k8s-ci-robot authored Feb 21, 2020
2 parents 00f4e80 + e8c107f commit 0aa97af
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 16 deletions.
4 changes: 4 additions & 0 deletions pkg/model/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,10 @@ func (m *KopsModelContext) CloudTagsForInstanceGroup(ig *kops.InstanceGroup) (ma
}
}

// Add cluster and ig names
labels[awsup.TagClusterName] = m.ClusterName()
labels["Name"] = m.AutoscalingGroupName(ig)

// The system tags take priority because the cluster likely breaks without them...

if ig.Spec.Role == kops.InstanceGroupRoleMaster {
Expand Down
1 change: 0 additions & 1 deletion pkg/model/spotinstmodel/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ go_library(
"//pkg/model/defaults:go_default_library",
"//upup/pkg/fi:go_default_library",
"//upup/pkg/fi/cloudup/awstasks:go_default_library",
"//upup/pkg/fi/cloudup/awsup:go_default_library",
"//upup/pkg/fi/cloudup/spotinsttasks:go_default_library",
"//vendor/k8s.io/klog:go_default_library",
],
Expand Down
3 changes: 0 additions & 3 deletions pkg/model/spotinstmodel/instance_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
"k8s.io/kops/pkg/model/defaults"
"k8s.io/kops/upup/pkg/fi"
"k8s.io/kops/upup/pkg/fi/cloudup/awstasks"
"k8s.io/kops/upup/pkg/fi/cloudup/awsup"
"k8s.io/kops/upup/pkg/fi/cloudup/spotinsttasks"
)

Expand Down Expand Up @@ -605,8 +604,6 @@ func (b *InstanceGroupModelBuilder) buildTags(ig *kops.InstanceGroup) (map[strin
if err != nil {
return nil, err
}
tags[awsup.TagClusterName] = b.ClusterName()
tags["Name"] = b.AutoscalingGroupName(ig)
return tags, nil
}

Expand Down
32 changes: 20 additions & 12 deletions upup/pkg/fi/cloudup/awstasks/launchtemplate_target_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,23 +109,22 @@ func (t *LaunchTemplate) RenderAWS(c *awsup.AWSAPITarget, a, ep, changes *Launch
lc.SecurityGroupIds = securityGroups
}
// @step: add the tags
{
var list []*ec2.Tag
if len(t.Tags) > 0 {
var tags []*ec2.Tag
for k, v := range t.Tags {
list = append(list, &ec2.Tag{
tags = append(tags, &ec2.Tag{
Key: aws.String(k),
Value: aws.String(v),
})
}
instanceTagSpec := ec2.LaunchTemplateTagSpecificationRequest{
ResourceType: aws.String("instance"),
Tags: list,
}
volumeTagSpec := ec2.LaunchTemplateTagSpecificationRequest{
ResourceType: aws.String("volume"),
Tags: list,
}
lc.TagSpecifications = []*ec2.LaunchTemplateTagSpecificationRequest{&instanceTagSpec, &volumeTagSpec}
lc.TagSpecifications = append(lc.TagSpecifications, &ec2.LaunchTemplateTagSpecificationRequest{
ResourceType: aws.String(ec2.ResourceTypeInstance),
Tags: tags,
})
lc.TagSpecifications = append(lc.TagSpecifications, &ec2.LaunchTemplateTagSpecificationRequest{
ResourceType: aws.String(ec2.ResourceTypeVolume),
Tags: tags,
})
}
// @step: add the userdata
if t.UserData != nil {
Expand Down Expand Up @@ -261,6 +260,15 @@ func (t *LaunchTemplate) Find(c *fi.Context) (*LaunchTemplate, error) {
actual.UserData = fi.WrapResource(fi.NewStringResource(string(ud)))
}

// @step: add tags
if len(lt.LaunchTemplateData.TagSpecifications) > 0 {
ts := lt.LaunchTemplateData.TagSpecifications[0]
if ts.Tags != nil {
tags := mapEC2TagsToMap(ts.Tags)
actual.Tags = tags
}
}

// @step: to avoid spurious changes on ImageId
if t.ImageID != nil && actual.ImageID != nil && *actual.ImageID != *t.ImageID {
image, err := cloud.ResolveImage(*t.ImageID)
Expand Down

0 comments on commit 0aa97af

Please sign in to comment.