@@ -29,6 +29,7 @@ import (
2929 corev1api "k8s.io/api/core/v1"
3030 "k8s.io/apimachinery/pkg/api/resource"
3131 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
32+ "k8s.io/apimachinery/pkg/runtime"
3233 "k8s.io/apimachinery/pkg/runtime/schema"
3334
3435 velerov1api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
@@ -415,7 +416,6 @@ func TestGenerateVolumeInfoForCSIVolumeSnapshot(t *testing.T) {
415416 BoundVolumeSnapshotContentName : stringPtr ("testContent" ),
416417 },
417418 },
418- volumeSnapshotClass : * builder .ForVolumeSnapshotClass ("testClass" ).Driver ("pd.csi.storage.gke.io" ).Result (),
419419 volumeSnapshotContent : * builder .ForVolumeSnapshotContent ("testContent" ).Status (& snapshotv1api.VolumeSnapshotContentStatus {SnapshotHandle : stringPtr ("testSnapshotHandle" )}).Result (),
420420 expectedVolumeInfos : []* BackupVolumeInfo {},
421421 },
@@ -440,8 +440,7 @@ func TestGenerateVolumeInfoForCSIVolumeSnapshot(t *testing.T) {
440440 ReadyToUse : & readyToUse ,
441441 },
442442 },
443- volumeSnapshotClass : * builder .ForVolumeSnapshotClass ("testClass" ).Driver ("pd.csi.storage.gke.io" ).Result (),
444- volumeSnapshotContent : * builder .ForVolumeSnapshotContent ("testContent" ).Status (& snapshotv1api.VolumeSnapshotContentStatus {SnapshotHandle : stringPtr ("testSnapshotHandle" )}).Result (),
443+ volumeSnapshotContent : * builder .ForVolumeSnapshotContent ("testContent" ).Driver ("pd.csi.storage.gke.io" ).Status (& snapshotv1api.VolumeSnapshotContentStatus {SnapshotHandle : stringPtr ("testSnapshotHandle" )}).Result (),
445444 pvMap : map [string ]pvcPvInfo {
446445 "testPV" : {
447446 PVCName : "testPVC" ,
@@ -758,7 +757,8 @@ func TestGenerateVolumeInfoFromDataUpload(t *testing.T) {
758757 defer features .Disable (velerov1api .CSIFeatureFlag )
759758 tests := []struct {
760759 name string
761- volumeSnapshotClass * snapshotv1api.VolumeSnapshotClass
760+ vs * snapshotv1api.VolumeSnapshot
761+ vsc * snapshotv1api.VolumeSnapshotContent
762762 dataUpload * velerov2alpha1.DataUpload
763763 operation * itemoperation.BackupOperation
764764 pvMap map [string ]pvcPvInfo
@@ -829,87 +829,20 @@ func TestGenerateVolumeInfoFromDataUpload(t *testing.T) {
829829 },
830830 expectedVolumeInfos : []* BackupVolumeInfo {},
831831 },
832- {
833- name : "VolumeSnapshotClass cannot be found for operation" ,
834- dataUpload : builder .ForDataUpload ("velero" , "testDU" ).DataMover ("velero" ).CSISnapshot (& velerov2alpha1.CSISnapshotSpec {
835- VolumeSnapshot : "testVS" ,
836- }).SnapshotID ("testSnapshotHandle" ).StartTimestamp (& now ).Result (),
837- operation : & itemoperation.BackupOperation {
838- Spec : itemoperation.BackupOperationSpec {
839- OperationID : "testOperation" ,
840- ResourceIdentifier : velero.ResourceIdentifier {
841- GroupResource : schema.GroupResource {
842- Group : "" ,
843- Resource : "persistentvolumeclaims" ,
844- },
845- Namespace : "velero" ,
846- Name : "testPVC" ,
847- },
848- PostOperationItems : []velero.ResourceIdentifier {
849- {
850- GroupResource : schema.GroupResource {
851- Group : "velero.io" ,
852- Resource : "datauploads" ,
853- },
854- Namespace : "velero" ,
855- Name : "testDU" ,
856- },
857- },
858- },
859- },
860- pvMap : map [string ]pvcPvInfo {
861- "testPV" : {
862- PVCName : "testPVC" ,
863- PVCNamespace : "velero" ,
864- PV : corev1api.PersistentVolume {
865- ObjectMeta : metav1.ObjectMeta {
866- Name : "testPV" ,
867- Labels : map [string ]string {"a" : "b" },
868- },
869- Spec : corev1api.PersistentVolumeSpec {
870- PersistentVolumeReclaimPolicy : corev1api .PersistentVolumeReclaimDelete ,
871- },
872- },
873- },
874- },
875- expectedVolumeInfos : []* BackupVolumeInfo {
876- {
877- PVCName : "testPVC" ,
878- PVCNamespace : "velero" ,
879- PVName : "testPV" ,
880- BackupMethod : CSISnapshot ,
881- SnapshotDataMoved : true ,
882- StartTimestamp : & now ,
883- CSISnapshotInfo : & CSISnapshotInfo {
884- SnapshotHandle : FieldValueIsUnknown ,
885- VSCName : FieldValueIsUnknown ,
886- OperationID : FieldValueIsUnknown ,
887- Size : 0 ,
888- },
889- SnapshotDataMovementInfo : & SnapshotDataMovementInfo {
890- DataMover : "velero" ,
891- UploaderType : "kopia" ,
892- OperationID : "testOperation" ,
893- },
894- PVInfo : & PVInfo {
895- ReclaimPolicy : string (corev1api .PersistentVolumeReclaimDelete ),
896- Labels : map [string ]string {"a" : "b" },
897- },
898- },
899- },
900- },
901832 {
902833 name : "Normal DataUpload case" ,
903834 dataUpload : builder .ForDataUpload ("velero" , "testDU" ).
904835 DataMover ("velero" ).
905836 CSISnapshot (& velerov2alpha1.CSISnapshotSpec {
906- VolumeSnapshot : "testVS " ,
837+ VolumeSnapshot : "vs-01 " ,
907838 SnapshotClass : "testClass" ,
839+ Driver : "pd.csi.storage.gke.io" ,
908840 }).SnapshotID ("testSnapshotHandle" ).
909841 StartTimestamp (& now ).
910842 Phase (velerov2alpha1 .DataUploadPhaseCompleted ).
911843 Result (),
912- volumeSnapshotClass : builder .ForVolumeSnapshotClass ("testClass" ).Driver ("pd.csi.storage.gke.io" ).Result (),
844+ vs : builder .ForVolumeSnapshot (velerov1api .DefaultNamespace , "vs-01" ).Status ().BoundVolumeSnapshotContentName ("vsc-01" ).Result (),
845+ vsc : builder .ForVolumeSnapshotContent ("vsc-01" ).Driver ("pd.csi.storage.gke.io" ).Result (),
913846 operation : & itemoperation.BackupOperation {
914847 Spec : itemoperation.BackupOperationSpec {
915848 OperationID : "testOperation" ,
@@ -995,14 +928,17 @@ func TestGenerateVolumeInfoFromDataUpload(t *testing.T) {
995928 }
996929 }
997930
998- volumesInfo . crClient = velerotest . NewFakeControllerRuntimeClient ( t )
931+ objects := make ([]runtime. Object , 0 )
999932 if tc .dataUpload != nil {
1000- volumesInfo . crClient . Create ( context . TODO () , tc .dataUpload )
933+ objects = append ( objects , tc .dataUpload )
1001934 }
1002-
1003- if tc .volumeSnapshotClass != nil {
1004- volumesInfo .crClient .Create (context .TODO (), tc .volumeSnapshotClass )
935+ if tc .vs != nil {
936+ objects = append (objects , tc .vs )
937+ }
938+ if tc .vsc != nil {
939+ objects = append (objects , tc .vsc )
1005940 }
941+ volumesInfo .crClient = velerotest .NewFakeControllerRuntimeClient (t , objects ... )
1006942
1007943 volumesInfo .logger = logging .DefaultLogger (logrus .DebugLevel , logging .FormatJSON )
1008944
0 commit comments