From 342612176337e48ebef594a59561c7c795f9e042 Mon Sep 17 00:00:00 2001 From: Alexander Wels Date: Tue, 17 Sep 2024 15:11:27 -0500 Subject: [PATCH] Make sure the size of the destination datavolume is specified when creating the adopting datavolume of the pvc. Signed-off-by: Alexander Wels --- pkg/controller/directvolumemigration/vm.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/pkg/controller/directvolumemigration/vm.go b/pkg/controller/directvolumemigration/vm.go index 92ec7b59b..351fd063f 100644 --- a/pkg/controller/directvolumemigration/vm.go +++ b/pkg/controller/directvolumemigration/vm.go @@ -359,6 +359,19 @@ func CreateNewDataVolume(client k8sclient.Client, sourceDvName, targetDvName, ns adoptingDV.Spec.Source = &cdiv1.DataVolumeSource{ Blank: &cdiv1.DataVolumeBlankImage{}, } + if adoptingDV.Spec.Storage != nil { + if _, ok := adoptingDV.Spec.Storage.Resources.Requests[corev1.ResourceStorage]; !ok { + // DV doesn't have a size specified, look it up from the matching PVC. + pvc := &corev1.PersistentVolumeClaim{} + if err := client.Get(context.TODO(), k8sclient.ObjectKey{Namespace: ns, Name: sourceDvName}, pvc); err != nil { + return err + } + adoptingDV.Spec.Storage.Resources = corev1.ResourceRequirements{ + Requests: corev1.ResourceList{}, + } + adoptingDV.Spec.Storage.Resources.Requests[corev1.ResourceStorage] = pvc.Spec.Resources.Requests[corev1.ResourceStorage] + } + } err := client.Create(context.TODO(), adoptingDV) if err != nil && !k8serrors.IsAlreadyExists(err) { log.Error(err, "Failed to create adopting datavolume", "namespace", ns, "name", targetDvName)