Skip to content

Commit

Permalink
Merge pull request #2562 from k8s-infra-cherrypick-robot/cherry-pick-…
Browse files Browse the repository at this point in the history
…2561-to-release-1.31

[release-1.31] feat: add pre-defined tags in snapshot creation
  • Loading branch information
andyzhangx authored Oct 22, 2024
2 parents f1b2a7d + 1ddcf1e commit c1a1407
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
5 changes: 4 additions & 1 deletion pkg/azureconstants/azure_constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -104,6 +106,7 @@ const (
AgentNotReadyNodeTaintKeySuffix = "/agent-not-ready"
// define tag value delimiter and default is comma
TagValueDelimiterField = "tagValueDelimiter"
AzureDiskDriverTag = "kubernetes-azure-dd"
)

var (
Expand Down
4 changes: 2 additions & 2 deletions pkg/azuredisk/azure_managedDiskController.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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
Expand Down
10 changes: 7 additions & 3 deletions pkg/azuredisk/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand Down

0 comments on commit c1a1407

Please sign in to comment.