From 40eed65bc32215da21049fc28d56626cd62e3601 Mon Sep 17 00:00:00 2001 From: Xun Jiang Date: Wed, 13 Mar 2024 15:14:40 +0800 Subject: [PATCH] Skip populate VolumeInfo for data-moved PV when CSI is not enabled. Signed-off-by: Xun Jiang --- changelogs/unreleased/7789-blackpiglet | 2 ++ internal/volume/volumes_information.go | 6 ++++++ internal/volume/volumes_information_test.go | 3 +++ 3 files changed, 11 insertions(+) create mode 100644 changelogs/unreleased/7789-blackpiglet diff --git a/changelogs/unreleased/7789-blackpiglet b/changelogs/unreleased/7789-blackpiglet new file mode 100644 index 000000000..842fd460a --- /dev/null +++ b/changelogs/unreleased/7789-blackpiglet @@ -0,0 +1,2 @@ +Check whether the VolumeSnapshot's source PVC is nil before using it. +Skip populate VolumeInfo for data-moved PV when CSI is not enabled. \ No newline at end of file diff --git a/internal/volume/volumes_information.go b/internal/volume/volumes_information.go index 4f152ccf8..2e5059ff1 100644 --- a/internal/volume/volumes_information.go +++ b/internal/volume/volumes_information.go @@ -28,6 +28,7 @@ import ( velerov1api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1" velerov2alpha1 "github.com/vmware-tanzu/velero/pkg/apis/velero/v2alpha1" + "github.com/vmware-tanzu/velero/pkg/features" "github.com/vmware-tanzu/velero/pkg/itemoperation" "github.com/vmware-tanzu/velero/pkg/kuberesource" "github.com/vmware-tanzu/velero/pkg/plugin/velero" @@ -462,6 +463,11 @@ func (v *VolumesInformation) generateVolumeInfoFromPVB() { // generateVolumeInfoFromDataUpload generate VolumeInfo for DataUpload. func (v *VolumesInformation) generateVolumeInfoFromDataUpload() { + if !features.IsEnabled(velerov1api.CSIFeatureFlag) { + v.logger.Debug("Skip generating VolumeInfo when the CSI feature is disabled.") + return + } + tmpVolumeInfos := make([]*VolumeInfo, 0) vsClassList := new(snapshotv1api.VolumeSnapshotClassList) if err := v.crClient.List(context.TODO(), vsClassList); err != nil { diff --git a/internal/volume/volumes_information_test.go b/internal/volume/volumes_information_test.go index 5b5d841e2..acb134285 100644 --- a/internal/volume/volumes_information_test.go +++ b/internal/volume/volumes_information_test.go @@ -31,6 +31,7 @@ import ( velerov1api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1" velerov2alpha1 "github.com/vmware-tanzu/velero/pkg/apis/velero/v2alpha1" "github.com/vmware-tanzu/velero/pkg/builder" + "github.com/vmware-tanzu/velero/pkg/features" "github.com/vmware-tanzu/velero/pkg/itemoperation" "github.com/vmware-tanzu/velero/pkg/plugin/velero" velerotest "github.com/vmware-tanzu/velero/pkg/test" @@ -605,6 +606,8 @@ func TestGenerateVolumeInfoFromPVB(t *testing.T) { } func TestGenerateVolumeInfoFromDataUpload(t *testing.T) { + features.Enable(velerov1api.CSIFeatureFlag) + defer features.Disable(velerov1api.CSIFeatureFlag) now := metav1.Now() tests := []struct { name string