diff --git a/pkg/cloudprovider/providers/aws/aws.go b/pkg/cloudprovider/providers/aws/aws.go index 41df8b153fe..27baccabc0e 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 @@ -1387,8 +1387,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 8317e9c6009..3c867638931 100644 --- a/pkg/volume/aws_ebs/aws_util.go +++ b/pkg/volume/aws_ebs/aws_util.go @@ -148,7 +148,7 @@ func (util *AWSDiskUtil) CreateVolume(c *awsElasticBlockStoreProvisioner) (strin requestGB := int(volume.RoundUpSize(requestBytes, 1024*1024*1024)) volumeOptions := &aws.VolumeOptions{ CapacityGB: requestGB, - Tags: &tags, + Tags: tags, } name, err := cloud.CreateDisk(volumeOptions)