diff --git a/pkg/azureconstants/azure_constants.go b/pkg/azureconstants/azure_constants.go index 4fb162b37d..c3d5a86a2b 100644 --- a/pkg/azureconstants/azure_constants.go +++ b/pkg/azureconstants/azure_constants.go @@ -55,11 +55,13 @@ const ( PvcNamespaceKey = "csi.storage.k8s.io/pvc/namespace" PvcNamespaceTag = "kubernetes.io-created-for-pvc-namespace" PvcNameTag = "kubernetes.io-created-for-pvc-name" + PvNameTag = "kubernetes.io-created-for-pv-name" + SnapshotNamespaceTag = "kubernetes.io-created-for-snapshot-namespace" + SnapshotNameTag = "kubernetes.io-created-for-snapshot-name" PvNameKey = "csi.storage.k8s.io/pv/name" VolumeSnapshotNameKey = "csi.storage.k8s.io/volumesnapshot/name" VolumeSnapshotNamespaceKey = "csi.storage.k8s.io/volumesnapshot/namespace" VolumeSnapshotContentNameKey = "csi.storage.k8s.io/volumesnapshotcontent/name" - PvNameTag = "kubernetes.io-created-for-pv-name" RateLimited = "rate limited" RequestedSizeGib = "requestedsizegib" ResizeRequired = "resizeRequired" @@ -104,6 +106,7 @@ const ( AgentNotReadyNodeTaintKeySuffix = "/agent-not-ready" // define tag value delimiter and default is comma TagValueDelimiterField = "tagValueDelimiter" + AzureDiskDriverTag = "kubernetes-azure-dd" ) var ( diff --git a/pkg/azuredisk/azure_managedDiskController.go b/pkg/azuredisk/azure_managedDiskController.go index 9368ad42e0..9e4c6de94e 100644 --- a/pkg/azuredisk/azure_managedDiskController.go +++ b/pkg/azuredisk/azure_managedDiskController.go @@ -35,6 +35,7 @@ import ( "k8s.io/klog/v2" "k8s.io/utils/ptr" + azureconsts "sigs.k8s.io/azuredisk-csi-driver/pkg/azureconstants" "sigs.k8s.io/cloud-provider-azure/pkg/consts" "sigs.k8s.io/cloud-provider-azure/pkg/provider" ) @@ -120,8 +121,7 @@ func (c *ManagedDiskController) CreateManagedDisk(ctx context.Context, options * // insert original tags to newTags newTags := make(map[string]*string) - azureDDTag := "kubernetes-azure-dd" - newTags[consts.CreatedByTag] = &azureDDTag + newTags[consts.CreatedByTag] = ptr.To(azureconsts.AzureDiskDriverTag) if options.Tags != nil { for k, v := range options.Tags { value := v diff --git a/pkg/azuredisk/controllerserver.go b/pkg/azuredisk/controllerserver.go index 83a4274f15..c103c4aad1 100644 --- a/pkg/azuredisk/controllerserver.go +++ b/pkg/azuredisk/controllerserver.go @@ -38,6 +38,7 @@ import ( cloudprovider "k8s.io/cloud-provider" volerr "k8s.io/cloud-provider/volume/errors" "k8s.io/klog/v2" + "k8s.io/utils/ptr" consts "sigs.k8s.io/azuredisk-csi-driver/pkg/azureconstants" "sigs.k8s.io/azuredisk-csi-driver/pkg/azureutils" @@ -986,6 +987,8 @@ func (d *Driver) CreateSnapshot(ctx context.Context, req *csi.CreateSnapshotRequ localCloud := d.cloud location := d.cloud.Location + tags := make(map[string]*string) + parameters := req.GetParameters() for k, v := range parameters { switch strings.ToLower(k) { @@ -1013,9 +1016,9 @@ func (d *Driver) CreateSnapshot(ctx context.Context, req *csi.CreateSnapshotRequ case consts.TagValueDelimiterField: tagValueDelimiter = v case consts.VolumeSnapshotNameKey: - // ignore the key + tags[consts.SnapshotNameTag] = ptr.To(v) case consts.VolumeSnapshotNamespaceKey: - // ignore the key + tags[consts.SnapshotNamespaceTag] = ptr.To(v) case consts.VolumeSnapshotContentNameKey: // ignore the key default: @@ -1039,7 +1042,8 @@ func (d *Driver) CreateSnapshot(ctx context.Context, req *csi.CreateSnapshotRequ if err != nil { return nil, status.Errorf(codes.InvalidArgument, "%v", err) } - tags := make(map[string]*string) + tags[azureconsts.CreatedByTag] = ptr.To(consts.AzureDiskDriverTag) + tags["source_volume_id"] = ptr.To(sourceVolumeID) for k, v := range customTagsMap { value := v tags[k] = &value