Skip to content

Commit

Permalink
inherit k8s default volumeSnapshotClass
Browse files Browse the repository at this point in the history
Signed-off-by: hu-keyu <[email protected]>
  • Loading branch information
hu-keyu committed Feb 26, 2025
1 parent 0f81772 commit ab96efb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions changelogs/unreleased/8719-hu-keyu
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Inherit k8s default volumeSnapshotClass.
3 changes: 3 additions & 0 deletions pkg/apis/velero/v1/labels_annotations.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ const (
VolumeSnapshotClassDriverBackupAnnotationPrefix = "velero.io/csi-volumesnapshot-class"
VolumeSnapshotClassDriverPVCAnnotation = "velero.io/csi-volumesnapshot-class"

// https://kubernetes.io/zh-cn/docs/concepts/storage/volume-snapshot-classes/
VolumeSnapshotClassKubernetesAnnotation = "snapshot.storage.kubernetes.io/is-default-class"

// There is no release w/ these constants exported. Using the strings for now.
// CSI Annotation volumesnapshotclass
// https://github.com/kubernetes-csi/external-snapshotter/blob/master/pkg/utils/util.go#L59-L60
Expand Down
14 changes: 12 additions & 2 deletions pkg/util/csi/volume_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,13 +432,23 @@ func GetVolumeSnapshotClassForStorageClass(
}
}
}
// not found by label, pick by annotation
for _, sc := range snapshotClasses.Items {
_, hasDefaultAnnotation := sc.Annotations[velerov1api.VolumeSnapshotClassKubernetesAnnotation]
if sc.Driver == provisioner {
vsClass = sc
if hasDefaultAnnotation {
return &sc, nil
}
}
}
// If there's only one volumesnapshotclass for the driver, return it.
if n == 1 {
return &vsClass, nil
}
return nil, fmt.Errorf(
"failed to get VolumeSnapshotClass for provisioner %s, ensure that the desired VolumeSnapshot class has the %s label",
provisioner, velerov1api.VolumeSnapshotClassSelectorLabel)
"failed to get VolumeSnapshotClass for provisioner %s, ensure that the desired VolumeSnapshot class has the %s label or %s annotation",
provisioner, velerov1api.VolumeSnapshotClassSelectorLabel, velerov1api.VolumeSnapshotClassKubernetesAnnotation)
}

// IsVolumeSnapshotClassHasListerSecret returns whether a volumesnapshotclass has a snapshotlister secret
Expand Down

0 comments on commit ab96efb

Please sign in to comment.