Skip to content

Commit

Permalink
Only get VolumeSnapshotClass when DataUpload exists.
Browse files Browse the repository at this point in the history
Signed-off-by: Xun Jiang <[email protected]>
  • Loading branch information
blackpiglet committed Jul 11, 2024
1 parent 28d64c2 commit 6882824
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
1 change: 1 addition & 0 deletions changelogs/unreleased/7974-blackpiglet
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Only get VolumeSnapshotClass when DataUpload exists.
27 changes: 22 additions & 5 deletions internal/volume/volumes_information.go
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,22 @@ func (v *BackupVolumesInformation) generateVolumeInfoFromPVB() {
v.volumeInfos = append(v.volumeInfos, tmpVolumeInfos...)
}

func (v *BackupVolumesInformation) getVolumeSnapshotClasses(
classes *snapshotv1api.VolumeSnapshotClassList,
) (*snapshotv1api.VolumeSnapshotClassList, error) {
if classes != nil {
return classes, nil
}

vsClassList := new(snapshotv1api.VolumeSnapshotClassList)
if err := v.crClient.List(context.TODO(), vsClassList); err != nil {
v.logger.Warnf("Cannot list VolumeSnapshotClass with error %s.", err.Error())
return nil, err

Check warning on line 564 in internal/volume/volumes_information.go

View check run for this annotation

Codecov / codecov/patch

internal/volume/volumes_information.go#L563-L564

Added lines #L563 - L564 were not covered by tests
}

return vsClassList, nil
}

// generateVolumeInfoFromDataUpload generate BackupVolumeInfo for DataUpload.
func (v *BackupVolumesInformation) generateVolumeInfoFromDataUpload() {
if !features.IsEnabled(velerov1api.CSIFeatureFlag) {
Expand All @@ -559,11 +575,7 @@ func (v *BackupVolumesInformation) generateVolumeInfoFromDataUpload() {
}

tmpVolumeInfos := make([]*BackupVolumeInfo, 0)
vsClassList := new(snapshotv1api.VolumeSnapshotClassList)
if err := v.crClient.List(context.TODO(), vsClassList); err != nil {
v.logger.WithError(err).Errorf("cannot list VolumeSnapshotClass %s", err.Error())
return
}
var vsClassList *snapshotv1api.VolumeSnapshotClassList

for _, operation := range v.BackupOperations {
if operation.Spec.ResourceIdentifier.GroupResource.String() == kuberesource.PersistentVolumeClaims.String() {
Expand Down Expand Up @@ -593,6 +605,11 @@ func (v *BackupVolumesInformation) generateVolumeInfoFromDataUpload() {
continue
}

vsClassList, err = v.getVolumeSnapshotClasses(vsClassList)
if err != nil {
return

Check warning on line 610 in internal/volume/volumes_information.go

View check run for this annotation

Codecov / codecov/patch

internal/volume/volumes_information.go#L610

Added line #L610 was not covered by tests
}

driverUsedByVSClass := ""
for index := range vsClassList.Items {
if vsClassList.Items[index].Name == dataUpload.Spec.CSISnapshot.SnapshotClass {
Expand Down
9 changes: 9 additions & 0 deletions internal/volume/volumes_information_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1310,3 +1310,12 @@ func int64Ptr(val int) *int64 {
i := int64(val)
return &i
}

func TestGetVolumeSnapshotClasses(t *testing.T) {
volumesInfo := BackupVolumesInformation{}
var vsClass snapshotv1api.VolumeSnapshotClassList

result, err := volumesInfo.getVolumeSnapshotClasses(&vsClass)
require.NoError(t, err)
require.Equal(t, &vsClass, result)
}

0 comments on commit 6882824

Please sign in to comment.