Merge pull request #8466 from hakman/fix-launch-template-tags

Update tags support for LaunchTemplates
This commit is contained in:
Kubernetes Prow Robot 2020-02-21 10:42:31 -08:00 committed by GitHub
commit 0aa97af94e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 16 deletions

View File

@ -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 {

View File

@ -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",
],

View File

@ -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"
)
@ -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
}

View File

@ -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 {
@ -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)