diff --git a/pkg/driver/constants.go b/pkg/driver/constants.go index 503ec2bee4..43028b57eb 100644 --- a/pkg/driver/constants.go +++ b/pkg/driver/constants.go @@ -86,6 +86,11 @@ const ( // in-tree volume plugin. Used only when --cluster-id is set. NameTag = "Name" + // KubernetesClusterTag is tag applied to provisioned EBS volume for backward compatibility with + // in-tree volume plugin. Used only when --cluster-id is set. + // See https://github.com/kubernetes/cloud-provider-aws/blob/release-1.20/pkg/providers/v1/tags.go#L38-L41. + KubernetesClusterTag = "KubernetesCluster" + // PVCNameTag is tag applied to provisioned EBS volume for backward compatibility // with in-tree volume plugin. Value of the tag is PVC name. It is applied only when // the external provisioner sidecar is started with --extra-create-metadata=true and diff --git a/pkg/driver/controller.go b/pkg/driver/controller.go index 367612b7e4..8c4d892866 100644 --- a/pkg/driver/controller.go +++ b/pkg/driver/controller.go @@ -220,6 +220,7 @@ func (d *controllerService) CreateVolume(ctx context.Context, req *csi.CreateVol resourceLifecycleTag := ResourceLifecycleTagPrefix + d.driverOptions.kubernetesClusterID volumeTags[resourceLifecycleTag] = ResourceLifecycleOwned volumeTags[NameTag] = d.driverOptions.kubernetesClusterID + "-dynamic-" + volName + volumeTags[KubernetesClusterTag] = d.driverOptions.kubernetesClusterID } for k, v := range d.driverOptions.extraTags { volumeTags[k] = v diff --git a/pkg/driver/controller_test.go b/pkg/driver/controller_test.go index 1af505b325..83e1021e72 100644 --- a/pkg/driver/controller_test.go +++ b/pkg/driver/controller_test.go @@ -1356,12 +1356,14 @@ func TestCreateVolume(t *testing.T) { name: "success with cluster-id", testFunc: func(t *testing.T) { const ( - volumeName = "random-vol-name" - clusterID = "test-cluster-id" - expectedOwnerTag = "kubernetes.io/cluster/test-cluster-id" - expectedOwnerTagValue = "owned" - expectedNameTag = "Name" - expectedNameTagValue = "test-cluster-id-dynamic-random-vol-name" + volumeName = "random-vol-name" + clusterID = "test-cluster-id" + expectedOwnerTag = "kubernetes.io/cluster/test-cluster-id" + expectedOwnerTagValue = "owned" + expectedNameTag = "Name" + expectedNameTagValue = "test-cluster-id-dynamic-random-vol-name" + expectedKubernetesClusterTag = "KubernetesCluster" + expectedKubernetesClusterTagValue = "test-cluster-id" ) req := &csi.CreateVolumeRequest{ Name: volumeName, @@ -1381,10 +1383,11 @@ func TestCreateVolume(t *testing.T) { diskOptions := &cloud.DiskOptions{ CapacityBytes: stdVolSize, Tags: map[string]string{ - cloud.VolumeNameTagKey: volumeName, - cloud.AwsEbsDriverTagKey: "true", - expectedOwnerTag: expectedOwnerTagValue, - expectedNameTag: expectedNameTagValue, + cloud.VolumeNameTagKey: volumeName, + cloud.AwsEbsDriverTagKey: "true", + expectedOwnerTag: expectedOwnerTagValue, + expectedNameTag: expectedNameTagValue, + expectedKubernetesClusterTag: expectedKubernetesClusterTagValue, }, } @@ -1418,7 +1421,6 @@ func TestCreateVolume(t *testing.T) { testFunc: func(t *testing.T) { const ( volumeName = "random-vol-name" - clusterID = "test-cluster-id" expectedPVCNameTag = "kubernetes.io/created-for/pvc/name" expectedPVCNamespaceTag = "kubernetes.io/created-for/pvc/namespace" expectedPVNameTag = "kubernetes.io/created-for/pv/name"