Skip to content

Commit

Permalink
Add KubernetesCluster tag to provisioned volumes when cluster-id set
Browse files Browse the repository at this point in the history
  • Loading branch information
wongma7 committed Jun 11, 2021
1 parent 54f1649 commit 8a7ff58
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
5 changes: 5 additions & 0 deletions pkg/driver/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions pkg/driver/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 13 additions & 11 deletions pkg/driver/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
},
}

Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 8a7ff58

Please sign in to comment.