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

[release-1.30] feat: add pre-defined tags in snapshot creation #2563

Closed
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: 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 @@
"k8s.io/klog/v2"
"k8s.io/utils/pointer"

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 @@

// 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)

Check failure on line 124 in pkg/azuredisk/azure_managedDiskController.go

View workflow job for this annotation

GitHub Actions / Analyze (go)

undefined: ptr

Check failure on line 124 in pkg/azuredisk/azure_managedDiskController.go

View workflow job for this annotation

GitHub Actions / Build

undefined: ptr

Check failure on line 124 in pkg/azuredisk/azure_managedDiskController.go

View workflow job for this annotation

GitHub Actions / Build

undefined: ptr

Check failure on line 124 in pkg/azuredisk/azure_managedDiskController.go

View workflow job for this annotation

GitHub Actions / Go Lint

undefined: ptr) (typecheck)

Check failure on line 124 in pkg/azuredisk/azure_managedDiskController.go

View workflow job for this annotation

GitHub Actions / Go Lint

undefined: ptr) (typecheck)

Check failure on line 124 in pkg/azuredisk/azure_managedDiskController.go

View workflow job for this annotation

GitHub Actions / Go Lint

undefined: ptr (typecheck)

Check failure on line 124 in pkg/azuredisk/azure_managedDiskController.go

View workflow job for this annotation

GitHub Actions / Go Lint

undefined: ptr) (typecheck)

Check failure on line 124 in pkg/azuredisk/azure_managedDiskController.go

View workflow job for this annotation

GitHub Actions / build (1.16.x, windows-latest)

undefined: ptr

Check failure on line 124 in pkg/azuredisk/azure_managedDiskController.go

View workflow job for this annotation

GitHub Actions / Build

undefined: ptr
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
Loading