Merge pull request #8462 from johngmyers/tag-volume

Tag EBS volumes when using launch templates with AWS API target
This commit is contained in:
Kubernetes Prow Robot 2020-02-02 20:23:20 -08:00 committed by GitHub
commit 0c7cbee2bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 0 deletions

View File

@ -97,6 +97,11 @@ func (b *AutoscalingGroupModelBuilder) buildLaunchTemplateTask(c *fi.ModelBuilde
return nil, err
}
tags, err := b.CloudTagsForInstanceGroup(ig)
if err != nil {
return nil, fmt.Errorf("error building cloud tags: %v", err)
}
// @TODO check if there any a better way of doing this .. initially I had a type LaunchTemplate which included
// LaunchConfiguration as an anonymous field, bit given up the task dependency walker works this caused issues, due
// to the creation of a implicit dependency
@ -115,6 +120,7 @@ func (b *AutoscalingGroupModelBuilder) buildLaunchTemplateTask(c *fi.ModelBuilde
RootVolumeType: lc.RootVolumeType,
SSHKey: lc.SSHKey,
SecurityGroups: lc.SecurityGroups,
Tags: tags,
Tenancy: lc.Tenancy,
UserData: lc.UserData,
}

View File

@ -62,6 +62,8 @@ type LaunchTemplate struct {
SecurityGroups []*SecurityGroup
// SpotPrice is set to the spot-price bid if this is a spot pricing request
SpotPrice string
// Tags are the keypairs to apply to the instance and volume on launch.
Tags map[string]string
// Tenancy. Can be either default or dedicated.
Tenancy *string
// UserData is the user data configuration

View File

@ -108,6 +108,25 @@ func (t *LaunchTemplate) RenderAWS(c *awsup.AWSAPITarget, a, ep, changes *Launch
} else {
lc.SecurityGroupIds = securityGroups
}
// @step: add the tags
{
var list []*ec2.Tag
for k, v := range t.Tags {
list = append(list, &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}
}
// @step: add the userdata
if t.UserData != nil {
d, err := t.UserData.AsBytes()