Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add KubernetesCluster tag to provisioned volumes when cluster-id set #932

Merged
merged 1 commit into from
Jun 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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