Skip to content
This repository was archived by the owner on Apr 25, 2025. It is now read-only.

Commit c1d61ca

Browse files
committed
feature annotation for snapshotclass provisioner
Signed-off-by: Ning Ding <834652870@qq.com>
1 parent bec108a commit c1d61ca

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

internal/util/labels_annotations.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ const (
2626
CSIVSCDeletionPolicy = "velero.io/csi-vsc-deletion-policy"
2727
VolumeSnapshotClassSelectorLabel = "velero.io/csi-volumesnapshot-class"
2828

29+
// For some csi providers, the provisioner name of storageclass is no the same as driver name in snapshotclass
30+
// We provide this annotation in snapshotclass to let velero detect the different name
31+
VolumeSnapshotClassProvisionerAnnotation = "velero.io/csi-volumesnapshot-class-provisioner"
32+
2933
// There is no release w/ these constants exported. Using the strings for now.
3034
// CSI Labels volumesnapshotclass
3135
// https://github.com/kubernetes-csi/external-snapshotter/blob/master/pkg/utils/util.go#L59-L60

internal/util/util.go

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,18 @@ func GetVolumeSnapshotClassForStorageClass(provisioner string, snapshotClient sn
132132
// https://github.com/kubernetes-csi/external-snapshotter/blob/release-4.2/client/config/crd/snapshot.storage.k8s.io_volumesnapshotclasses.yaml
133133
for _, sc := range snapshotClasses.Items {
134134
_, hasLabelSelector := sc.Labels[VolumeSnapshotClassSelectorLabel]
135-
if sc.Driver == provisioner && hasLabelSelector {
136-
return &sc, nil
135+
if hasLabelSelector {
136+
if sc.Driver == provisioner {
137+
return &sc, nil
138+
} else { // check snapshotclass provisioner annotation exists
139+
annotationValue, hasAnnotationsSelector := GetAnnotation(&sc.ObjectMeta, VolumeSnapshotClassProvisionerAnnotation)
140+
if hasAnnotationsSelector && annotationValue == provisioner {
141+
return &sc, nil
142+
}
143+
}
137144
}
138145
}
146+
139147
return nil, errors.Errorf("failed to get volumesnapshotclass for provisioner %s, ensure that the desired volumesnapshot class has the %s label", provisioner, VolumeSnapshotClassSelectorLabel)
140148
}
141149

@@ -244,6 +252,15 @@ func IsVolumeSnapshotHasVSCDeleteSecret(vs *snapshotv1api.VolumeSnapshot) bool {
244252
return nameExists && nsExists
245253
}
246254

255+
// GetAnnotation get the annotations on the object
256+
func GetAnnotation(o *metav1.ObjectMeta, key string) (string, bool) {
257+
if o.Annotations == nil {
258+
return "", false
259+
}
260+
v, exist := o.Annotations[key]
261+
return v, exist
262+
}
263+
247264
// AddAnnotations adds the supplied key-values to the annotations on the object
248265
func AddAnnotations(o *metav1.ObjectMeta, vals map[string]string) {
249266
if o.Annotations == nil {

0 commit comments

Comments
 (0)