Skip to content
This repository was archived by the owner on Apr 25, 2025. It is now read-only.
Open
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
4 changes: 4 additions & 0 deletions internal/util/labels_annotations.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ const (
CSIVSCDeletionPolicy = "velero.io/csi-vsc-deletion-policy"
VolumeSnapshotClassSelectorLabel = "velero.io/csi-volumesnapshot-class"

// For some csi providers, the provisioner name of storageclass is no the same as driver name in snapshotclass
// We provide this annotation in snapshotclass to let velero detect the different name
VolumeSnapshotClassProvisionerAnnotation = "velero.io/csi-volumesnapshot-class-provisioner"

// There is no release w/ these constants exported. Using the strings for now.
// CSI Labels volumesnapshotclass
// https://github.com/kubernetes-csi/external-snapshotter/blob/master/pkg/utils/util.go#L59-L60
Expand Down
21 changes: 19 additions & 2 deletions internal/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,18 @@ func GetVolumeSnapshotClassForStorageClass(provisioner string, snapshotClient sn
// https://github.com/kubernetes-csi/external-snapshotter/blob/release-4.2/client/config/crd/snapshot.storage.k8s.io_volumesnapshotclasses.yaml
for _, sc := range snapshotClasses.Items {
_, hasLabelSelector := sc.Labels[VolumeSnapshotClassSelectorLabel]
if sc.Driver == provisioner && hasLabelSelector {
return &sc, nil
if hasLabelSelector {
if sc.Driver == provisioner {
return &sc, nil
} else { // check snapshotclass provisioner annotation exists
annotationValue, hasAnnotationsSelector := GetAnnotation(&sc.ObjectMeta, VolumeSnapshotClassProvisionerAnnotation)
if hasAnnotationsSelector && annotationValue == provisioner {
return &sc, nil
}
}
}
}

return nil, errors.Errorf("failed to get volumesnapshotclass for provisioner %s, ensure that the desired volumesnapshot class has the %s label", provisioner, VolumeSnapshotClassSelectorLabel)
}

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

// GetAnnotation get the annotations on the object
func GetAnnotation(o *metav1.ObjectMeta, key string) (string, bool) {
if o.Annotations == nil {
return "", false
}
v, exist := o.Annotations[key]
return v, exist
}

// AddAnnotations adds the supplied key-values to the annotations on the object
func AddAnnotations(o *metav1.ObjectMeta, vals map[string]string) {
if o.Annotations == nil {
Expand Down