From 16730aba964a19d3c81eb127ab4877393965d2de Mon Sep 17 00:00:00 2001 From: Justin Santa Barbara Date: Thu, 10 Mar 2016 08:12:17 -0500 Subject: [PATCH] AWS: Tag created EBS volumes with our cluster tag Fix #22792 --- pkg/cloudprovider/providers/aws/aws.go | 15 ++++++++++++--- pkg/volume/aws_ebs/aws_util.go | 2 +- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/pkg/cloudprovider/providers/aws/aws.go b/pkg/cloudprovider/providers/aws/aws.go index 5ba3091486a..d23c9afcb69 100644 --- a/pkg/cloudprovider/providers/aws/aws.go +++ b/pkg/cloudprovider/providers/aws/aws.go @@ -161,7 +161,7 @@ type EC2Metadata interface { type VolumeOptions struct { CapacityGB int - Tags *map[string]string + Tags map[string]string } // Volumes is an interface for managing cloud-provisioned volumes @@ -1400,8 +1400,17 @@ func (s *AWSCloud) CreateDisk(volumeOptions *VolumeOptions) (string, error) { volumeName := "aws://" + az + "/" + awsID // apply tags - if volumeOptions.Tags != nil { - if err := s.createTags(awsID, *volumeOptions.Tags); err != nil { + tags := make(map[string]string) + for k, v := range volumeOptions.Tags { + tags[k] = v + } + + if s.getClusterName() != "" { + tags[TagNameKubernetesCluster] = s.getClusterName() + } + + if len(tags) != 0 { + if err := s.createTags(awsID, tags); err != nil { // delete the volume and hope it succeeds _, delerr := s.DeleteDisk(volumeName) if delerr != nil { diff --git a/pkg/volume/aws_ebs/aws_util.go b/pkg/volume/aws_ebs/aws_util.go index cfacc8b8e33..fcb219f72a0 100644 --- a/pkg/volume/aws_ebs/aws_util.go +++ b/pkg/volume/aws_ebs/aws_util.go @@ -146,7 +146,7 @@ func (util *AWSDiskUtil) CreateVolume(c *awsElasticBlockStoreProvisioner) (volum requestGB := int(volume.RoundUpSize(requestBytes, 1024*1024*1024)) volumeOptions := &aws.VolumeOptions{ CapacityGB: requestGB, - Tags: &tags, + Tags: tags, } name, err := cloud.CreateDisk(volumeOptions)