From efb94ae6105f88020d3de2be3b7ac2158c3d525e Mon Sep 17 00:00:00 2001 From: Xun Jiang Date: Wed, 20 Mar 2024 15:26:47 +0800 Subject: [PATCH] Refactor the native snapshot definition code. Signed-off-by: Xun Jiang --- changelogs/unreleased/7544-blackpiglet | 1 + .../volume/native_snapshot.go | 0 internal/volume/volumes_information.go | 3 +- internal/volume/volumes_information_test.go | 23 ++++++------ pkg/backup/backup_test.go | 2 +- pkg/backup/item_backupper.go | 2 +- pkg/backup/request.go | 5 ++- pkg/cmd/util/output/backup_describer.go | 3 +- pkg/controller/backup_controller.go | 5 ++- pkg/controller/backup_deletion_controller.go | 4 +-- .../backup_deletion_controller_test.go | 7 ++-- pkg/controller/restore_controller.go | 4 +-- pkg/controller/restore_controller_test.go | 5 ++- .../restore_finalizer_controller.go | 10 +++--- pkg/persistence/mocks/backup_store.go | 11 +++--- pkg/persistence/object_store.go | 9 +++-- pkg/persistence/object_store_test.go | 13 ++++--- pkg/restore/pv_restorer.go | 5 ++- pkg/restore/pv_restorer_test.go | 2 +- pkg/restore/request.go | 5 ++- pkg/restore/restore.go | 11 +++--- pkg/restore/restore_test.go | 35 +++++++++---------- 22 files changed, 76 insertions(+), 89 deletions(-) create mode 100644 changelogs/unreleased/7544-blackpiglet rename pkg/volume/snapshot.go => internal/volume/native_snapshot.go (100%) diff --git a/changelogs/unreleased/7544-blackpiglet b/changelogs/unreleased/7544-blackpiglet new file mode 100644 index 0000000000..398ac16219 --- /dev/null +++ b/changelogs/unreleased/7544-blackpiglet @@ -0,0 +1 @@ +Move the native snapshot definition code into internal directory \ No newline at end of file diff --git a/pkg/volume/snapshot.go b/internal/volume/native_snapshot.go similarity index 100% rename from pkg/volume/snapshot.go rename to internal/volume/native_snapshot.go diff --git a/internal/volume/volumes_information.go b/internal/volume/volumes_information.go index 2e5059ff1b..7e3acd555d 100644 --- a/internal/volume/volumes_information.go +++ b/internal/volume/volumes_information.go @@ -32,7 +32,6 @@ import ( "github.com/vmware-tanzu/velero/pkg/itemoperation" "github.com/vmware-tanzu/velero/pkg/kuberesource" "github.com/vmware-tanzu/velero/pkg/plugin/velero" - "github.com/vmware-tanzu/velero/pkg/volume" ) type VolumeBackupMethod string @@ -188,7 +187,7 @@ type VolumesInformation struct { volumeSnapshotContents []snapshotv1api.VolumeSnapshotContent volumeSnapshotClasses []snapshotv1api.VolumeSnapshotClass SkippedPVs map[string]string - NativeSnapshots []*volume.Snapshot + NativeSnapshots []*Snapshot PodVolumeBackups []*velerov1api.PodVolumeBackup BackupOperations []*itemoperation.BackupOperation BackupName string diff --git a/internal/volume/volumes_information_test.go b/internal/volume/volumes_information_test.go index acb1342854..d91f3004a6 100644 --- a/internal/volume/volumes_information_test.go +++ b/internal/volume/volumes_information_test.go @@ -36,7 +36,6 @@ import ( "github.com/vmware-tanzu/velero/pkg/plugin/velero" velerotest "github.com/vmware-tanzu/velero/pkg/test" "github.com/vmware-tanzu/velero/pkg/util/logging" - "github.com/vmware-tanzu/velero/pkg/volume" ) func TestGenerateVolumeInfoForSkippedPV(t *testing.T) { @@ -142,14 +141,14 @@ func TestGenerateVolumeInfoForSkippedPV(t *testing.T) { func TestGenerateVolumeInfoForVeleroNativeSnapshot(t *testing.T) { tests := []struct { name string - nativeSnapshot volume.Snapshot + nativeSnapshot Snapshot pvMap map[string]pvcPvInfo expectedVolumeInfos []*VolumeInfo }{ { name: "Native snapshot's IPOS pointer is nil", - nativeSnapshot: volume.Snapshot{ - Spec: volume.SnapshotSpec{ + nativeSnapshot: Snapshot{ + Spec: SnapshotSpec{ PersistentVolumeName: "testPV", VolumeIOPS: nil, }, @@ -158,8 +157,8 @@ func TestGenerateVolumeInfoForVeleroNativeSnapshot(t *testing.T) { }, { name: "Cannot find info for the PV", - nativeSnapshot: volume.Snapshot{ - Spec: volume.SnapshotSpec{ + nativeSnapshot: Snapshot{ + Spec: SnapshotSpec{ PersistentVolumeName: "testPV", VolumeIOPS: int64Ptr(100), }, @@ -183,14 +182,14 @@ func TestGenerateVolumeInfoForVeleroNativeSnapshot(t *testing.T) { }, }, }, - nativeSnapshot: volume.Snapshot{ - Spec: volume.SnapshotSpec{ + nativeSnapshot: Snapshot{ + Spec: SnapshotSpec{ PersistentVolumeName: "testPV", VolumeIOPS: int64Ptr(100), VolumeType: "ssd", VolumeAZ: "us-central1-a", }, - Status: volume.SnapshotStatus{ + Status: SnapshotStatus{ ProviderSnapshotID: "pvc-b31e3386-4bbb-4937-95d-7934cd62-b0a1-494b-95d7-0687440e8d0c", }, }, @@ -213,14 +212,14 @@ func TestGenerateVolumeInfoForVeleroNativeSnapshot(t *testing.T) { }, }, }, - nativeSnapshot: volume.Snapshot{ - Spec: volume.SnapshotSpec{ + nativeSnapshot: Snapshot{ + Spec: SnapshotSpec{ PersistentVolumeName: "testPV", VolumeIOPS: int64Ptr(100), VolumeType: "ssd", VolumeAZ: "us-central1-a", }, - Status: volume.SnapshotStatus{ + Status: SnapshotStatus{ ProviderSnapshotID: "pvc-b31e3386-4bbb-4937-95d-7934cd62-b0a1-494b-95d7-0687440e8d0c", }, }, diff --git a/pkg/backup/backup_test.go b/pkg/backup/backup_test.go index bb60760e71..32270c8cf9 100644 --- a/pkg/backup/backup_test.go +++ b/pkg/backup/backup_test.go @@ -42,6 +42,7 @@ import ( "k8s.io/apimachinery/pkg/runtime" "github.com/vmware-tanzu/velero/internal/resourcepolicies" + "github.com/vmware-tanzu/velero/internal/volume" velerov1 "github.com/vmware-tanzu/velero/pkg/apis/velero/v1" "github.com/vmware-tanzu/velero/pkg/builder" "github.com/vmware-tanzu/velero/pkg/client" @@ -55,7 +56,6 @@ import ( "github.com/vmware-tanzu/velero/pkg/podvolume" "github.com/vmware-tanzu/velero/pkg/test" kubeutil "github.com/vmware-tanzu/velero/pkg/util/kube" - "github.com/vmware-tanzu/velero/pkg/volume" ) func TestBackedUpItemsMatchesTarballContents(t *testing.T) { diff --git a/pkg/backup/item_backupper.go b/pkg/backup/item_backupper.go index 927b770dbf..7f1d826857 100644 --- a/pkg/backup/item_backupper.go +++ b/pkg/backup/item_backupper.go @@ -41,6 +41,7 @@ import ( "github.com/vmware-tanzu/velero/internal/hook" "github.com/vmware-tanzu/velero/internal/resourcepolicies" + "github.com/vmware-tanzu/velero/internal/volume" velerov1api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1" "github.com/vmware-tanzu/velero/pkg/archive" "github.com/vmware-tanzu/velero/pkg/client" @@ -54,7 +55,6 @@ import ( "github.com/vmware-tanzu/velero/pkg/util/boolptr" csiutil "github.com/vmware-tanzu/velero/pkg/util/csi" pdvolumeutil "github.com/vmware-tanzu/velero/pkg/util/podvolume" - "github.com/vmware-tanzu/velero/pkg/volume" ) const ( diff --git a/pkg/backup/request.go b/pkg/backup/request.go index 63013ca0d2..b78200af6c 100644 --- a/pkg/backup/request.go +++ b/pkg/backup/request.go @@ -22,12 +22,11 @@ import ( "github.com/vmware-tanzu/velero/internal/hook" "github.com/vmware-tanzu/velero/internal/resourcepolicies" - internalVolume "github.com/vmware-tanzu/velero/internal/volume" + "github.com/vmware-tanzu/velero/internal/volume" velerov1api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1" "github.com/vmware-tanzu/velero/pkg/itemoperation" "github.com/vmware-tanzu/velero/pkg/plugin/framework" "github.com/vmware-tanzu/velero/pkg/util/collections" - "github.com/vmware-tanzu/velero/pkg/volume" ) type itemKey struct { @@ -53,7 +52,7 @@ type Request struct { itemOperationsList *[]*itemoperation.BackupOperation ResPolicies *resourcepolicies.Policies SkippedPVTracker *skipPVTracker - VolumesInformation internalVolume.VolumesInformation + VolumesInformation volume.VolumesInformation } // VolumesInformation contains the information needs by generating diff --git a/pkg/cmd/util/output/backup_describer.go b/pkg/cmd/util/output/backup_describer.go index e76d89fe50..d198c80cbe 100644 --- a/pkg/cmd/util/output/backup_describer.go +++ b/pkg/cmd/util/output/backup_describer.go @@ -43,7 +43,6 @@ import ( "github.com/vmware-tanzu/velero/pkg/util/boolptr" "github.com/vmware-tanzu/velero/pkg/util/collections" "github.com/vmware-tanzu/velero/pkg/util/results" - nativesnap "github.com/vmware-tanzu/velero/pkg/volume" ) // DescribeBackup describes a backup in human-readable format. @@ -502,7 +501,7 @@ func retrieveNativeSnapshotLegacy(ctx context.Context, kbClient kbclient.Client, return nativeSnapshots, errors.Wrapf(err, "error to download native snapshot info") } - var snapshots []*nativesnap.Snapshot + var snapshots []*volume.Snapshot if err := json.NewDecoder(buf).Decode(&snapshots); err != nil { return nativeSnapshots, errors.Wrapf(err, "error to decode native snapshot info") } diff --git a/pkg/controller/backup_controller.go b/pkg/controller/backup_controller.go index bb60abb589..da915ed7e5 100644 --- a/pkg/controller/backup_controller.go +++ b/pkg/controller/backup_controller.go @@ -40,7 +40,7 @@ import ( "github.com/vmware-tanzu/velero/internal/credentials" "github.com/vmware-tanzu/velero/internal/resourcepolicies" "github.com/vmware-tanzu/velero/internal/storage" - internalVolume "github.com/vmware-tanzu/velero/internal/volume" + "github.com/vmware-tanzu/velero/internal/volume" velerov1api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1" pkgbackup "github.com/vmware-tanzu/velero/pkg/backup" "github.com/vmware-tanzu/velero/pkg/discovery" @@ -56,7 +56,6 @@ import ( kubeutil "github.com/vmware-tanzu/velero/pkg/util/kube" "github.com/vmware-tanzu/velero/pkg/util/logging" "github.com/vmware-tanzu/velero/pkg/util/results" - "github.com/vmware-tanzu/velero/pkg/volume" ) const ( @@ -588,7 +587,7 @@ func (b *backupReconciler) validateAndGetSnapshotLocations(backup *velerov1api.B // add credential to config for each location for _, location := range providerLocations { - err = internalVolume.UpdateVolumeSnapshotLocationWithCredentialConfig(location, b.credentialFileStore) + err = volume.UpdateVolumeSnapshotLocationWithCredentialConfig(location, b.credentialFileStore) if err != nil { errors = append(errors, fmt.Sprintf("error adding credentials to volume snapshot location named %s: %v", location.Name, err)) continue diff --git a/pkg/controller/backup_deletion_controller.go b/pkg/controller/backup_deletion_controller.go index 6533b8d176..9ab7e318c8 100644 --- a/pkg/controller/backup_deletion_controller.go +++ b/pkg/controller/backup_deletion_controller.go @@ -37,7 +37,7 @@ import ( "github.com/vmware-tanzu/velero/internal/credentials" "github.com/vmware-tanzu/velero/internal/delete" - internalVolume "github.com/vmware-tanzu/velero/internal/volume" + "github.com/vmware-tanzu/velero/internal/volume" 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/discovery" @@ -456,7 +456,7 @@ func (r *backupDeletionReconciler) volumeSnapshottersForVSL( } // add credential to config - err := internalVolume.UpdateVolumeSnapshotLocationWithCredentialConfig(vsl, r.credentialStore) + err := volume.UpdateVolumeSnapshotLocationWithCredentialConfig(vsl, r.credentialStore) if err != nil { return nil, errors.WithStack(err) } diff --git a/pkg/controller/backup_deletion_controller_test.go b/pkg/controller/backup_deletion_controller_test.go index c808f249d4..0dbb0a3e97 100644 --- a/pkg/controller/backup_deletion_controller_test.go +++ b/pkg/controller/backup_deletion_controller_test.go @@ -42,10 +42,7 @@ import ( ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" - "github.com/vmware-tanzu/velero/pkg/plugin/velero" - "github.com/vmware-tanzu/velero/pkg/plugin/velero/mocks" - "github.com/vmware-tanzu/velero/pkg/volume" - + "github.com/vmware-tanzu/velero/internal/volume" velerov1api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1" pkgbackup "github.com/vmware-tanzu/velero/pkg/backup" "github.com/vmware-tanzu/velero/pkg/builder" @@ -53,6 +50,8 @@ import ( persistencemocks "github.com/vmware-tanzu/velero/pkg/persistence/mocks" "github.com/vmware-tanzu/velero/pkg/plugin/clientmgmt" pluginmocks "github.com/vmware-tanzu/velero/pkg/plugin/mocks" + "github.com/vmware-tanzu/velero/pkg/plugin/velero" + "github.com/vmware-tanzu/velero/pkg/plugin/velero/mocks" "github.com/vmware-tanzu/velero/pkg/repository" velerotest "github.com/vmware-tanzu/velero/pkg/test" ) diff --git a/pkg/controller/restore_controller.go b/pkg/controller/restore_controller.go index a15db454b9..4b282d21e5 100644 --- a/pkg/controller/restore_controller.go +++ b/pkg/controller/restore_controller.go @@ -44,7 +44,7 @@ import ( "github.com/vmware-tanzu/velero/internal/hook" "github.com/vmware-tanzu/velero/internal/resourcemodifiers" - internalVolume "github.com/vmware-tanzu/velero/internal/volume" + "github.com/vmware-tanzu/velero/internal/volume" api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1" "github.com/vmware-tanzu/velero/pkg/itemoperation" "github.com/vmware-tanzu/velero/pkg/label" @@ -521,7 +521,7 @@ func (r *restoreReconciler) runValidatedRestore(restore *api.Restore, info backu return errors.Wrap(err, "fail to fetch CSI VolumeSnapshots metadata") } - backupVolumeInfoMap := make(map[string]internalVolume.VolumeInfo) + backupVolumeInfoMap := make(map[string]volume.VolumeInfo) volumeInfos, err := backupStore.GetBackupVolumeInfos(restore.Spec.BackupName) if err != nil { restoreLog.WithError(err).Errorf("fail to get VolumeInfos metadata file for backup %s", restore.Spec.BackupName) diff --git a/pkg/controller/restore_controller_test.go b/pkg/controller/restore_controller_test.go index bc505ce408..65df4af57d 100644 --- a/pkg/controller/restore_controller_test.go +++ b/pkg/controller/restore_controller_test.go @@ -37,7 +37,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "github.com/vmware-tanzu/velero/internal/resourcemodifiers" - internalVolume "github.com/vmware-tanzu/velero/internal/volume" + "github.com/vmware-tanzu/velero/internal/volume" velerov1api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1" "github.com/vmware-tanzu/velero/pkg/builder" "github.com/vmware-tanzu/velero/pkg/metrics" @@ -50,7 +50,6 @@ import ( velerotest "github.com/vmware-tanzu/velero/pkg/test" "github.com/vmware-tanzu/velero/pkg/util/logging" "github.com/vmware-tanzu/velero/pkg/util/results" - "github.com/vmware-tanzu/velero/pkg/volume" ) func TestFetchBackupInfo(t *testing.T) { @@ -506,7 +505,7 @@ func TestRestoreReconcile(t *testing.T) { if test.emptyVolumeInfo == true { backupStore.On("GetBackupVolumeInfos", test.backup.Name).Return(nil, nil) } else { - backupStore.On("GetBackupVolumeInfos", test.backup.Name).Return([]*internalVolume.VolumeInfo{}, nil) + backupStore.On("GetBackupVolumeInfos", test.backup.Name).Return([]*volume.VolumeInfo{}, nil) } volumeSnapshots := []*volume.Snapshot{ diff --git a/pkg/controller/restore_finalizer_controller.go b/pkg/controller/restore_finalizer_controller.go index 1c3f37f21c..45b03159b8 100644 --- a/pkg/controller/restore_finalizer_controller.go +++ b/pkg/controller/restore_finalizer_controller.go @@ -34,7 +34,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/utils/clock" - internalVolume "github.com/vmware-tanzu/velero/internal/volume" + "github.com/vmware-tanzu/velero/internal/volume" velerov1api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1" "github.com/vmware-tanzu/velero/pkg/metrics" "github.com/vmware-tanzu/velero/pkg/persistence" @@ -238,7 +238,7 @@ type finalizerContext struct { logger logrus.FieldLogger restore *velerov1api.Restore crClient client.Client - volumeInfo []*internalVolume.VolumeInfo + volumeInfo []*volume.VolumeInfo restoredPVCList map[string]struct{} } @@ -263,7 +263,7 @@ func (ctx *finalizerContext) patchDynamicPVWithVolumeInfo() (errs results.Result semaphore := make(chan struct{}, maxConcurrency) for _, volumeItem := range ctx.volumeInfo { - if (volumeItem.BackupMethod == internalVolume.PodVolumeBackup || volumeItem.BackupMethod == internalVolume.CSISnapshot) && volumeItem.PVInfo != nil { + if (volumeItem.BackupMethod == volume.PodVolumeBackup || volumeItem.BackupMethod == volume.CSISnapshot) && volumeItem.PVInfo != nil { // Determine restored PVC namespace restoredNamespace := volumeItem.PVCNamespace if remapped, ok := ctx.restore.Spec.NamespaceMapping[restoredNamespace]; ok { @@ -277,7 +277,7 @@ func (ctx *finalizerContext) patchDynamicPVWithVolumeInfo() (errs results.Result } pvWaitGroup.Add(1) - go func(volInfo internalVolume.VolumeInfo, restoredNamespace string) { + go func(volInfo volume.VolumeInfo, restoredNamespace string) { defer pvWaitGroup.Done() semaphore <- struct{}{} @@ -375,7 +375,7 @@ func getRestoredPVCFromRestoredResourceList(restoredResourceList map[string][]st return pvcList } -func needPatch(newPV *v1.PersistentVolume, pvInfo *internalVolume.PVInfo) bool { +func needPatch(newPV *v1.PersistentVolume, pvInfo *volume.PVInfo) bool { if newPV.Spec.PersistentVolumeReclaimPolicy != v1.PersistentVolumeReclaimPolicy(pvInfo.ReclaimPolicy) { return true } diff --git a/pkg/persistence/mocks/backup_store.go b/pkg/persistence/mocks/backup_store.go index 50650afad0..b45928e775 100644 --- a/pkg/persistence/mocks/backup_store.go +++ b/pkg/persistence/mocks/backup_store.go @@ -23,11 +23,10 @@ import ( mock "github.com/stretchr/testify/mock" volumesnapshotv1 "github.com/kubernetes-csi/external-snapshotter/client/v7/apis/volumesnapshot/v1" - internalVolume "github.com/vmware-tanzu/velero/internal/volume" itemoperation "github.com/vmware-tanzu/velero/pkg/itemoperation" "github.com/vmware-tanzu/velero/pkg/persistence" v1 "github.com/vmware-tanzu/velero/pkg/apis/velero/v1" - volume "github.com/vmware-tanzu/velero/pkg/volume" + "github.com/vmware-tanzu/velero/internal/volume" "github.com/vmware-tanzu/velero/pkg/util/results" @@ -316,15 +315,15 @@ func (_m *BackupStore) GetRestoreItemOperations(name string) ([]*itemoperation.R } // GetRestoreItemOperations provides a mock function with given fields: name -func (_m *BackupStore) GetBackupVolumeInfos(name string) ([]*internalVolume.VolumeInfo, error) { +func (_m *BackupStore) GetBackupVolumeInfos(name string) ([]*volume.VolumeInfo, error) { ret := _m.Called(name) - var r0 []*internalVolume.VolumeInfo - if rf, ok := ret.Get(0).(func(string) []*internalVolume.VolumeInfo); ok { + var r0 []*volume.VolumeInfo + if rf, ok := ret.Get(0).(func(string) []*volume.VolumeInfo); ok { r0 = rf(name) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).([]*internalVolume.VolumeInfo) + r0 = ret.Get(0).([]*volume.VolumeInfo) } } diff --git a/pkg/persistence/object_store.go b/pkg/persistence/object_store.go index 68a178cd17..962c36de74 100644 --- a/pkg/persistence/object_store.go +++ b/pkg/persistence/object_store.go @@ -31,13 +31,12 @@ import ( kerrors "k8s.io/apimachinery/pkg/util/errors" "github.com/vmware-tanzu/velero/internal/credentials" - internalVolume "github.com/vmware-tanzu/velero/internal/volume" + "github.com/vmware-tanzu/velero/internal/volume" velerov1api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1" "github.com/vmware-tanzu/velero/pkg/itemoperation" "github.com/vmware-tanzu/velero/pkg/plugin/velero" "github.com/vmware-tanzu/velero/pkg/util" "github.com/vmware-tanzu/velero/pkg/util/results" - "github.com/vmware-tanzu/velero/pkg/volume" ) type BackupInfo struct { @@ -75,7 +74,7 @@ type BackupStore interface { GetCSIVolumeSnapshots(name string) ([]*snapshotv1api.VolumeSnapshot, error) GetCSIVolumeSnapshotContents(name string) ([]*snapshotv1api.VolumeSnapshotContent, error) GetCSIVolumeSnapshotClasses(name string) ([]*snapshotv1api.VolumeSnapshotClass, error) - GetBackupVolumeInfos(name string) ([]*internalVolume.VolumeInfo, error) + GetBackupVolumeInfos(name string) ([]*volume.VolumeInfo, error) GetRestoreResults(name string) (map[string]results.Result, error) // BackupExists checks if the backup metadata file exists in object storage. @@ -498,8 +497,8 @@ func (s *objectBackupStore) GetPodVolumeBackups(name string) ([]*velerov1api.Pod return podVolumeBackups, nil } -func (s *objectBackupStore) GetBackupVolumeInfos(name string) ([]*internalVolume.VolumeInfo, error) { - volumeInfos := make([]*internalVolume.VolumeInfo, 0) +func (s *objectBackupStore) GetBackupVolumeInfos(name string) ([]*volume.VolumeInfo, error) { + volumeInfos := make([]*volume.VolumeInfo, 0) res, err := tryGet(s.objectStore, s.bucket, s.layout.getBackupVolumeInfoKey(name)) if err != nil { diff --git a/pkg/persistence/object_store_test.go b/pkg/persistence/object_store_test.go index 72f2fb2fb3..de3da29f1a 100644 --- a/pkg/persistence/object_store_test.go +++ b/pkg/persistence/object_store_test.go @@ -34,7 +34,7 @@ import ( "k8s.io/apimachinery/pkg/runtime" "github.com/vmware-tanzu/velero/internal/credentials" - internalVolume "github.com/vmware-tanzu/velero/internal/volume" + "github.com/vmware-tanzu/velero/internal/volume" velerov1api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1" "github.com/vmware-tanzu/velero/pkg/builder" "github.com/vmware-tanzu/velero/pkg/itemoperation" @@ -44,7 +44,6 @@ import ( velerotest "github.com/vmware-tanzu/velero/pkg/test" "github.com/vmware-tanzu/velero/pkg/util/encode" "github.com/vmware-tanzu/velero/pkg/util/results" - "github.com/vmware-tanzu/velero/pkg/volume" ) type objectBackupStoreTestHarness struct { @@ -1069,17 +1068,17 @@ func TestNewObjectBackupStoreGetterConfig(t *testing.T) { func TestGetBackupVolumeInfos(t *testing.T) { tests := []struct { name string - volumeInfo []*internalVolume.VolumeInfo + volumeInfo []*volume.VolumeInfo volumeInfoStr string expectedErr string - expectedResult []*internalVolume.VolumeInfo + expectedResult []*volume.VolumeInfo }{ { name: "No VolumeInfos, expect no error.", }, { name: "Valid VolumeInfo, should pass.", - volumeInfo: []*internalVolume.VolumeInfo{ + volumeInfo: []*volume.VolumeInfo{ { PVCName: "pvcName", PVName: "pvName", @@ -1087,7 +1086,7 @@ func TestGetBackupVolumeInfos(t *testing.T) { SnapshotDataMoved: false, }, }, - expectedResult: []*internalVolume.VolumeInfo{ + expectedResult: []*volume.VolumeInfo{ { PVCName: "pvcName", PVName: "pvName", @@ -1099,7 +1098,7 @@ func TestGetBackupVolumeInfos(t *testing.T) { { name: "Invalid VolumeInfo string, should also pass.", volumeInfoStr: `[{"abc": "123", "def": "456", "pvcName": "pvcName"}]`, - expectedResult: []*internalVolume.VolumeInfo{ + expectedResult: []*volume.VolumeInfo{ { PVCName: "pvcName", }, diff --git a/pkg/restore/pv_restorer.go b/pkg/restore/pv_restorer.go index a2565e58fa..aa13627501 100644 --- a/pkg/restore/pv_restorer.go +++ b/pkg/restore/pv_restorer.go @@ -26,10 +26,9 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "github.com/vmware-tanzu/velero/internal/credentials" - internalVolume "github.com/vmware-tanzu/velero/internal/volume" + "github.com/vmware-tanzu/velero/internal/volume" api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1" "github.com/vmware-tanzu/velero/pkg/util/boolptr" - "github.com/vmware-tanzu/velero/pkg/volume" ) type PVRestorer interface { @@ -133,7 +132,7 @@ func getSnapshotInfo(pvName string, backup *api.Backup, volumeSnapshots []*volum } // add credential to config - err = internalVolume.UpdateVolumeSnapshotLocationWithCredentialConfig(snapshotLocation, credentialStore) + err = volume.UpdateVolumeSnapshotLocationWithCredentialConfig(snapshotLocation, credentialStore) if err != nil { return nil, errors.WithStack(err) } diff --git a/pkg/restore/pv_restorer_test.go b/pkg/restore/pv_restorer_test.go index 0d49ba4b84..5609c7e924 100644 --- a/pkg/restore/pv_restorer_test.go +++ b/pkg/restore/pv_restorer_test.go @@ -26,12 +26,12 @@ import ( "github.com/stretchr/testify/require" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" + "github.com/vmware-tanzu/velero/internal/volume" api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1" "github.com/vmware-tanzu/velero/pkg/builder" providermocks "github.com/vmware-tanzu/velero/pkg/plugin/velero/mocks/volumesnapshotter/v1" vsv1 "github.com/vmware-tanzu/velero/pkg/plugin/velero/volumesnapshotter/v1" velerotest "github.com/vmware-tanzu/velero/pkg/test" - "github.com/vmware-tanzu/velero/pkg/volume" ) func defaultBackup() *builder.BackupBuilder { diff --git a/pkg/restore/request.go b/pkg/restore/request.go index 503e1b69ea..ff27c6ba78 100644 --- a/pkg/restore/request.go +++ b/pkg/restore/request.go @@ -26,10 +26,9 @@ import ( "k8s.io/apimachinery/pkg/runtime" "github.com/vmware-tanzu/velero/internal/resourcemodifiers" - internalVolume "github.com/vmware-tanzu/velero/internal/volume" + "github.com/vmware-tanzu/velero/internal/volume" velerov1api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1" "github.com/vmware-tanzu/velero/pkg/itemoperation" - "github.com/vmware-tanzu/velero/pkg/volume" ) const ( @@ -63,7 +62,7 @@ type Request struct { ResourceModifiers *resourcemodifiers.ResourceModifiers DisableInformerCache bool CSIVolumeSnapshots []*snapshotv1api.VolumeSnapshot - VolumeInfoMap map[string]internalVolume.VolumeInfo + VolumeInfoMap map[string]volume.VolumeInfo } type restoredItemStatus struct { diff --git a/pkg/restore/restore.go b/pkg/restore/restore.go index 1a323b9be6..929b14c9ec 100644 --- a/pkg/restore/restore.go +++ b/pkg/restore/restore.go @@ -52,7 +52,7 @@ import ( "github.com/vmware-tanzu/velero/internal/credentials" "github.com/vmware-tanzu/velero/internal/hook" "github.com/vmware-tanzu/velero/internal/resourcemodifiers" - internalVolume "github.com/vmware-tanzu/velero/internal/volume" + "github.com/vmware-tanzu/velero/internal/volume" velerov1api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1" "github.com/vmware-tanzu/velero/pkg/archive" "github.com/vmware-tanzu/velero/pkg/client" @@ -73,7 +73,6 @@ import ( "github.com/vmware-tanzu/velero/pkg/util/filesystem" "github.com/vmware-tanzu/velero/pkg/util/kube" "github.com/vmware-tanzu/velero/pkg/util/results" - "github.com/vmware-tanzu/velero/pkg/volume" ) var resourceMustHave = []string{ @@ -377,7 +376,7 @@ type restoreContext struct { disableInformerCache bool featureVerifier features.Verifier hookTracker *hook.HookTracker - volumeInfoMap map[string]internalVolume.VolumeInfo + volumeInfoMap map[string]volume.VolumeInfo } type resourceClientKey struct { @@ -1228,7 +1227,7 @@ func (ctx *restoreContext) restoreItem(obj *unstructured.Unstructured, groupReso ctx.log.Infof("Find VolumeInfo for PV %s.", obj.GetName()) switch volumeInfo.BackupMethod { - case internalVolume.NativeSnapshot: + case volume.NativeSnapshot: obj, err = ctx.handlePVHasNativeSnapshot(obj, resourceClient) if err != nil { errs.Add(namespace, err) @@ -1237,7 +1236,7 @@ func (ctx *restoreContext) restoreItem(obj *unstructured.Unstructured, groupReso name = obj.GetName() - case internalVolume.PodVolumeBackup: + case volume.PodVolumeBackup: restoreLogger.Infof("Dynamically re-provisioning persistent volume because it has a pod volume backup to be restored.") ctx.pvsToProvision.Insert(name) @@ -1245,7 +1244,7 @@ func (ctx *restoreContext) restoreItem(obj *unstructured.Unstructured, groupReso // want to dynamically re-provision it. return warnings, errs, itemExists - case internalVolume.CSISnapshot: + case volume.CSISnapshot: restoreLogger.Infof("Dynamically re-provisioning persistent volume because it has a CSI VolumeSnapshot or a related snapshot DataUpload.") ctx.pvsToProvision.Insert(name) diff --git a/pkg/restore/restore_test.go b/pkg/restore/restore_test.go index efca338703..ee735386db 100644 --- a/pkg/restore/restore_test.go +++ b/pkg/restore/restore_test.go @@ -42,7 +42,7 @@ import ( "k8s.io/client-go/dynamic" kubetesting "k8s.io/client-go/testing" - internalVolume "github.com/vmware-tanzu/velero/internal/volume" + "github.com/vmware-tanzu/velero/internal/volume" velerov1api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1" "github.com/vmware-tanzu/velero/pkg/archive" "github.com/vmware-tanzu/velero/pkg/builder" @@ -60,7 +60,6 @@ import ( "github.com/vmware-tanzu/velero/pkg/test" kubeutil "github.com/vmware-tanzu/velero/pkg/util/kube" . "github.com/vmware-tanzu/velero/pkg/util/results" - "github.com/vmware-tanzu/velero/pkg/volume" ) func TestRestorePVWithVolumeInfo(t *testing.T) { @@ -71,7 +70,7 @@ func TestRestorePVWithVolumeInfo(t *testing.T) { apiResources []*test.APIResource tarball io.Reader want map[*test.APIResource][]string - volumeInfoMap map[string]internalVolume.VolumeInfo + volumeInfoMap map[string]volume.VolumeInfo }{ { name: "Restore PV with native snapshot", @@ -84,11 +83,11 @@ func TestRestorePVWithVolumeInfo(t *testing.T) { apiResources: []*test.APIResource{ test.PVs(), }, - volumeInfoMap: map[string]internalVolume.VolumeInfo{ + volumeInfoMap: map[string]volume.VolumeInfo{ "pv-1": { - BackupMethod: internalVolume.NativeSnapshot, + BackupMethod: volume.NativeSnapshot, PVName: "pv-1", - NativeSnapshotInfo: &internalVolume.NativeSnapshotInfo{ + NativeSnapshotInfo: &volume.NativeSnapshotInfo{ SnapshotHandle: "testSnapshotHandle", }, }, @@ -108,11 +107,11 @@ func TestRestorePVWithVolumeInfo(t *testing.T) { apiResources: []*test.APIResource{ test.PVs(), }, - volumeInfoMap: map[string]internalVolume.VolumeInfo{ + volumeInfoMap: map[string]volume.VolumeInfo{ "pv-1": { - BackupMethod: internalVolume.PodVolumeBackup, + BackupMethod: volume.PodVolumeBackup, PVName: "pv-1", - PVBInfo: &internalVolume.PodVolumeBackupInfo{ + PVBInfo: &volume.PodVolumeBackupInfo{ SnapshotHandle: "testSnapshotHandle", Size: 100, NodeName: "testNode", @@ -134,12 +133,12 @@ func TestRestorePVWithVolumeInfo(t *testing.T) { apiResources: []*test.APIResource{ test.PVs(), }, - volumeInfoMap: map[string]internalVolume.VolumeInfo{ + volumeInfoMap: map[string]volume.VolumeInfo{ "pv-1": { - BackupMethod: internalVolume.CSISnapshot, + BackupMethod: volume.CSISnapshot, SnapshotDataMoved: false, PVName: "pv-1", - CSISnapshotInfo: &internalVolume.CSISnapshotInfo{ + CSISnapshotInfo: &volume.CSISnapshotInfo{ Driver: "pd.csi.storage.gke.io", }, }, @@ -159,15 +158,15 @@ func TestRestorePVWithVolumeInfo(t *testing.T) { apiResources: []*test.APIResource{ test.PVs(), }, - volumeInfoMap: map[string]internalVolume.VolumeInfo{ + volumeInfoMap: map[string]volume.VolumeInfo{ "pv-1": { - BackupMethod: internalVolume.CSISnapshot, + BackupMethod: volume.CSISnapshot, SnapshotDataMoved: true, PVName: "pv-1", - CSISnapshotInfo: &internalVolume.CSISnapshotInfo{ + CSISnapshotInfo: &volume.CSISnapshotInfo{ Driver: "pd.csi.storage.gke.io", }, - SnapshotDataMovementInfo: &internalVolume.SnapshotDataMovementInfo{ + SnapshotDataMovementInfo: &volume.SnapshotDataMovementInfo{ DataMover: "velero", }, }, @@ -187,7 +186,7 @@ func TestRestorePVWithVolumeInfo(t *testing.T) { apiResources: []*test.APIResource{ test.PVs(), }, - volumeInfoMap: map[string]internalVolume.VolumeInfo{ + volumeInfoMap: map[string]volume.VolumeInfo{ "pv-1": { PVName: "pv-1", Skipped: true, @@ -208,7 +207,7 @@ func TestRestorePVWithVolumeInfo(t *testing.T) { apiResources: []*test.APIResource{ test.PVs(), }, - volumeInfoMap: map[string]internalVolume.VolumeInfo{ + volumeInfoMap: map[string]volume.VolumeInfo{ "pv-1": { PVName: "pv-1", Skipped: true,