diff --git a/go.mod b/go.mod index 41a20845..3e197a25 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( github.com/spf13/pflag v1.0.5 github.com/stretchr/testify v1.8.2 // TODO: need to use velero v1.12.0 after releasing. - github.com/vmware-tanzu/velero v0.0.0-20230620063525-6f3adcf7282b + github.com/vmware-tanzu/velero v0.0.0-20230630063030-84eca51d22c7 k8s.io/api v0.25.6 k8s.io/apimachinery v0.25.6 k8s.io/client-go v0.25.6 diff --git a/go.sum b/go.sum index 414bb8df..7a6409fb 100644 --- a/go.sum +++ b/go.sum @@ -658,8 +658,8 @@ github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69 github.com/tg123/go-htpasswd v1.2.1 h1:i4wfsX1KvvkyoMiHZzjS0VzbAPWfxzI8INcZAKtutoU= github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/tmc/grpc-websocket-proxy v0.0.0-20201229170055-e5319fda7802/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= -github.com/vmware-tanzu/velero v0.0.0-20230620063525-6f3adcf7282b h1:mrsiuap4DAaF5ukPvJrFAiELcuHmLF2QVswJpIyVSP8= -github.com/vmware-tanzu/velero v0.0.0-20230620063525-6f3adcf7282b/go.mod h1:URz7drKyNV58T6MuVdDH/iATs3/DorJI+IEVPZwdHZE= +github.com/vmware-tanzu/velero v0.0.0-20230630063030-84eca51d22c7 h1:w/KPz4EQwQaaXes4gEgjrFrvygVSjjUaDQnm7VggtZ8= +github.com/vmware-tanzu/velero v0.0.0-20230630063030-84eca51d22c7/go.mod h1:URz7drKyNV58T6MuVdDH/iATs3/DorJI+IEVPZwdHZE= github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU= github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:GwrjFmJcFw6At/Gs6z4yjiIwzuJ1/+UwLxMQDVQXShQ= github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQluxsYJ78Id3Y= diff --git a/internal/restore/pvc_action_test.go b/internal/restore/pvc_action_test.go index ffc1050c..446e4ddb 100644 --- a/internal/restore/pvc_action_test.go +++ b/internal/restore/pvc_action_test.go @@ -553,10 +553,14 @@ func TestExecute(t *testing.T) { expectedErr: "Failed to get Volumesnapshot velero/testVS to restore PVC velero/testPVC: volumesnapshots.snapshot.storage.k8s.io \"testVS\" not found", }, { - name: "Restore from VolumeSnapshot", - backup: builder.ForBackup("velero", "testBackup").Result(), - restore: builder.ForRestore("velero", "testRestore").Backup("testBackup").Result(), - pvc: builder.ForPersistentVolumeClaim("velero", "testPVC").ObjectMeta(builder.WithAnnotations(util.VolumeSnapshotLabel, "testVS")).Result(), + name: "Restore from VolumeSnapshot", + backup: builder.ForBackup("velero", "testBackup").Result(), + restore: builder.ForRestore("velero", "testRestore").Backup("testBackup").Result(), + pvc: builder.ForPersistentVolumeClaim("velero", "testPVC").ObjectMeta(builder.WithAnnotations(util.VolumeSnapshotLabel, "testVS")). + RequestResource(map[corev1api.ResourceName]resource.Quantity{corev1api.ResourceStorage: resource.MustParse("10Gi")}). + DataSource(&corev1api.TypedLocalObjectReference{APIGroup: &snapshotv1api.SchemeGroupVersion.Group, Kind: util.VolumeSnapshotKindName, Name: "testVS"}). + DataSourceRef(&corev1api.TypedLocalObjectReference{APIGroup: &snapshotv1api.SchemeGroupVersion.Group, Kind: util.VolumeSnapshotKindName, Name: "testVS"}). + Result(), vs: builder.ForVolumeSnapshot("velero", "testVS").ObjectMeta(builder.WithAnnotations(util.VolumeSnapshotRestoreSize, "10Gi")).Result(), expectedPVC: builder.ForPersistentVolumeClaim("velero", "testPVC").ObjectMeta(builder.WithAnnotations("velero.io/volume-snapshot-name", "testVS")).Result(), }, @@ -575,6 +579,10 @@ func TestExecute(t *testing.T) { pvc: builder.ForPersistentVolumeClaim("velero", "testPVC").ObjectMeta(builder.WithAnnotations(util.VolumeSnapshotRestoreSize, "10Gi")).Result(), dataUploadResult: builder.ForConfigMap("velero", "testCM").Data("uid", "{}").ObjectMeta(builder.WithLabels(velerov1api.RestoreUIDLabel, "uid", util.PVCNamespaceNameLabel, "velero.testPVC")).Result(), expectedPVC: builder.ForPersistentVolumeClaim("velero", "testPVC").ObjectMeta(builder.WithAnnotations("velero.io/vsi-volumesnapshot-restore-size", "10Gi")).Result(), + expectedDataDownload: builder.ForDataDownload("velero", "").TargetVolume(velerov2alpha1.TargetVolumeSpec{PVC: "testPVC", Namespace: "velero"}). + ObjectMeta(builder.WithOwnerReference([]metav1.OwnerReference{{APIVersion: velerov1api.SchemeGroupVersion.String(), Kind: "Restore", Name: "testRestore", UID: "uid", Controller: boolptr.True()}}), + builder.WithLabelsMap(map[string]string{util.AsyncOperationIDLabel: "dd-uid.", velerov1api.RestoreNameLabel: "testRestore", velerov1api.RestoreUIDLabel: "uid"}), + builder.WithGenerateName("testRestore-")).Result(), }, } @@ -588,54 +596,6 @@ func TestExecute(t *testing.T) { } input := new(velero.RestoreItemActionExecuteInput) - // TODO: after needed Velero builder methods are added, need to remove this block. - if tc.name == "Restore from VolumeSnapshot" { - requestMemory, _ := resource.ParseQuantity("10Gi") - tc.expectedPVC.Spec.Resources.Requests = make(map[corev1api.ResourceName]resource.Quantity) - tc.expectedPVC.Spec.Resources.Requests[corev1api.ResourceStorage] = requestMemory - tc.expectedPVC.Spec.DataSource = &corev1api.TypedLocalObjectReference{ - APIGroup: &snapshotv1api.SchemeGroupVersion.Group, - Kind: util.VolumeSnapshotKindName, - Name: "testVS", - } - tc.expectedPVC.Spec.DataSourceRef = &corev1api.TypedLocalObjectReference{ - APIGroup: &snapshotv1api.SchemeGroupVersion.Group, - Kind: util.VolumeSnapshotKindName, - Name: "testVS", - } - } else if tc.name == "Restore from DataUploadResult" { - tc.expectedDataDownload = &velerov2alpha1.DataDownload{ - TypeMeta: metav1.TypeMeta{ - Kind: "DataDownload", - APIVersion: velerov2alpha1.SchemeGroupVersion.String(), - }, - ObjectMeta: metav1.ObjectMeta{ - GenerateName: tc.restore.Name + "-", - Namespace: "velero", - Labels: map[string]string{ - util.AsyncOperationIDLabel: "dd-uid.", - velerov1api.RestoreNameLabel: tc.restore.Name, - velerov1api.RestoreUIDLabel: string(tc.restore.UID), - }, - OwnerReferences: []metav1.OwnerReference{ - { - APIVersion: velerov1api.SchemeGroupVersion.String(), - Kind: "Restore", - Name: tc.restore.Name, - UID: tc.restore.UID, - Controller: boolptr.True(), - }, - }, - }, - Spec: velerov2alpha1.DataDownloadSpec{ - TargetVolume: velerov2alpha1.TargetVolumeSpec{ - PVC: tc.pvc.Name, - Namespace: tc.pvc.Namespace, - }, - }, - } - } - if tc.pvc != nil { pvcMap, err := runtime.DefaultUnstructuredConverter.ToUnstructured(tc.pvc) require.NoError(t, err) diff --git a/internal/util/util_test.go b/internal/util/util_test.go index 0bae9e73..625af76c 100644 --- a/internal/util/util_test.go +++ b/internal/util/util_test.go @@ -1508,23 +1508,23 @@ func TestDeleteVolumeSnapshots(t *testing.T) { { name: "VS is ReadyToUse, and VS has corresponding VSC. VS should be deleted.", vs: *builder.ForVolumeSnapshot("velero", "vs1").ObjectMeta(builder.WithLabels("testing-vs", "vs1")).Status().BoundVolumeSnapshotContentName("vsc1").Result(), - vsc: *builder.ForVolumeSnapshotContent("vsc1").DeletionPolicy(snapshotv1api.VolumeSnapshotContentDelete).Status().Result(), + vsc: *builder.ForVolumeSnapshotContent("vsc1").DeletionPolicy(snapshotv1api.VolumeSnapshotContentDelete).Status(&snapshotv1api.VolumeSnapshotContentStatus{}).Result(), expectedVS: snapshotv1api.VolumeSnapshot{}, - expectedVSC: *builder.ForVolumeSnapshotContent("vsc1").DeletionPolicy(snapshotv1api.VolumeSnapshotContentRetain).VolumeSnapshotRef("ns-", "name-").Status().Result(), + expectedVSC: *builder.ForVolumeSnapshotContent("vsc1").DeletionPolicy(snapshotv1api.VolumeSnapshotContentRetain).VolumeSnapshotRef("ns-", "name-").Result(), }, { name: "VS is ReadyToUse, and VS has corresponding VSC. Concurrent test.", vs: *builder.ForVolumeSnapshot("velero", "vs1").ObjectMeta(builder.WithLabels("testing-vs", "vs1")).Status().BoundVolumeSnapshotContentName("vsc1").Result(), - vsc: *builder.ForVolumeSnapshotContent("vsc1").DeletionPolicy(snapshotv1api.VolumeSnapshotContentDelete).Status().Result(), + vsc: *builder.ForVolumeSnapshotContent("vsc1").DeletionPolicy(snapshotv1api.VolumeSnapshotContentDelete).Status(&snapshotv1api.VolumeSnapshotContentStatus{}).Result(), expectedVS: snapshotv1api.VolumeSnapshot{}, - expectedVSC: *builder.ForVolumeSnapshotContent("vsc1").DeletionPolicy(snapshotv1api.VolumeSnapshotContentRetain).VolumeSnapshotRef("ns-", "name-").Status().Result(), + expectedVSC: *builder.ForVolumeSnapshotContent("vsc1").DeletionPolicy(snapshotv1api.VolumeSnapshotContentRetain).VolumeSnapshotRef("ns-", "name-").Result(), }, { name: "VS status is nil. VSC should not be modified.", vs: *builder.ForVolumeSnapshot("velero", "vs1").ObjectMeta(builder.WithLabels("testing-vs", "vs1")).Result(), - vsc: *builder.ForVolumeSnapshotContent("vsc1").DeletionPolicy(snapshotv1api.VolumeSnapshotContentDelete).Status().Result(), + vsc: *builder.ForVolumeSnapshotContent("vsc1").DeletionPolicy(snapshotv1api.VolumeSnapshotContentDelete).Status(&snapshotv1api.VolumeSnapshotContentStatus{}).Result(), expectedVS: snapshotv1api.VolumeSnapshot{}, - expectedVSC: *builder.ForVolumeSnapshotContent("vsc1").DeletionPolicy(snapshotv1api.VolumeSnapshotContentDelete).Status().Result(), + expectedVSC: *builder.ForVolumeSnapshotContent("vsc1").DeletionPolicy(snapshotv1api.VolumeSnapshotContentDelete).Result(), }, }