From 7b872473df7cbd816a98454c90066d572d26749b Mon Sep 17 00:00:00 2001 From: Xun Jiang Date: Tue, 29 Jul 2025 11:44:04 +0800 Subject: [PATCH] Use const to represent snapshot.storage.kubernetes.io/managed-by. Signed-off-by: Xun Jiang --- pkg/exposer/csi_snapshot.go | 4 ++-- pkg/util/kube/utils.go | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/pkg/exposer/csi_snapshot.go b/pkg/exposer/csi_snapshot.go index 9fb4e42e0..4017ce4e8 100644 --- a/pkg/exposer/csi_snapshot.go +++ b/pkg/exposer/csi_snapshot.go @@ -471,8 +471,8 @@ func (e *csiSnapshotExposer) createBackupVSC(ctx context.Context, ownerObject co https://github.com/kubernetes-csi/external-snapshotter/tree/4cedb3f45790ac593ebfa3324c490abedf739477?tab=readme-ov-file#distributed-snapshotting https://github.com/kubernetes-csi/external-snapshotter/blob/4cedb3f45790ac593ebfa3324c490abedf739477/pkg/utils/util.go#L158 */ - if manager, ok := snapshotVSC.Labels["snapshot.storage.kubernetes.io/managed-by"]; ok { - vsc.ObjectMeta.Labels["snapshot.storage.kubernetes.io/managed-by"] = manager + if manager, ok := snapshotVSC.Labels[kube.VolumeSnapshotContentManagedByLabel]; ok { + vsc.ObjectMeta.Labels[kube.VolumeSnapshotContentManagedByLabel] = manager } return e.csiSnapshotClient.VolumeSnapshotContents().Create(ctx, vsc, metav1.CreateOptions{}) diff --git a/pkg/util/kube/utils.go b/pkg/util/kube/utils.go index eab3193fc..1720f614f 100644 --- a/pkg/util/kube/utils.go +++ b/pkg/util/kube/utils.go @@ -53,6 +53,11 @@ const ( KubeAnnSelectedNode = "volume.kubernetes.io/selected-node" ) +// VolumeSnapshotContentManagedByLabel is applied by the snapshot controller +// to the VolumeSnapshotContent object in case distributed snapshotting is enabled. +// The value contains the name of the node that handles the snapshot for the volume local to that node. +const VolumeSnapshotContentManagedByLabel = "snapshot.storage.kubernetes.io/managed-by" + var ErrorPodVolumeIsNotPVC = errors.New("pod volume is not a PVC") // NamespaceAndName returns a string in the format /