Skip to content

Commit

Permalink
Merge pull request kubevirt#12851 from alicefr/fix-mig-block-to-fs
Browse files Browse the repository at this point in the history
volume-migration: append disk image for block replacement
  • Loading branch information
kubevirt-bot authored Oct 7, 2024
2 parents 35aefb7 + 5875155 commit 3ea0cc9
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pkg/virt-launcher/virtwrap/live-migration-source.go
Original file line number Diff line number Diff line change
Expand Up @@ -908,7 +908,7 @@ func configureLocalDiskToMigrate(dom *libvirtxml.Domain, vmi *v1.VirtualMachineI
if _, ok := blockSrcFsDstVols[name]; ok {
log.Log.V(2).Infof("Replace block source with destination for volume %s", name)
dom.Devices.Disks[i].Source.File = &libvirtxml.DomainDiskSourceFile{
File: hostdisk.GetMountedHostDiskDir(name),
File: filepath.Join(hostdisk.GetMountedHostDiskDir(name), "disk.img"),
}
dom.Devices.Disks[i].Source.Block = nil
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/virt-launcher/virtwrap/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2930,7 +2930,7 @@ var _ = Describe("Manager helper functions", func() {
}

getFsImagePath := func(name string) string {
return hostdisk.GetMountedHostDiskDir(name)
return filepath.Join(hostdisk.GetMountedHostDiskDir(name), "disk.img")
}

getBlockPath := func(name string) string {
Expand Down
40 changes: 40 additions & 0 deletions tests/storage/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,46 @@ var _ = SIGDescribe("[Serial]Volumes update with migration", Serial, func() {
waitForMigrationToSucceed(vm.Name, ns)
})

It("should migrate the source volume from a block source and filesystem destination DVs", func() {
volName := "disk0"
sc, exist := libstorage.GetRWOBlockStorageClass()
Expect(exist).To(BeTrue())
srcDV := libdv.NewDataVolume(
libdv.WithBlankImageSource(),
libdv.WithPVC(libdv.PVCWithStorageClass(sc),
libdv.PVCWithVolumeSize(size),
libdv.PVCWithVolumeMode(k8sv1.PersistentVolumeBlock),
),
)
_, err := virtClient.CdiClient().CdiV1beta1().DataVolumes(ns).Create(context.Background(),
srcDV, metav1.CreateOptions{})
Expect(err).ToNot(HaveOccurred())

sc, exist = libstorage.GetRWOFileSystemStorageClass()
Expect(exist).To(BeTrue())
destDV := libdv.NewDataVolume(
libdv.WithBlankImageSource(),
libdv.WithPVC(libdv.PVCWithStorageClass(sc),
libdv.PVCWithVolumeSize(size),
libdv.PVCWithVolumeMode(k8sv1.PersistentVolumeFilesystem),
),
)
_, err = virtClient.CdiClient().CdiV1beta1().DataVolumes(ns).Create(context.Background(),
destDV, metav1.CreateOptions{})
Expect(err).ToNot(HaveOccurred())
vm := createVMWithDV(srcDV, volName)
By("Update volumes")
updateVMWithDV(vm, volName, destDV.Name)
Eventually(func() bool {
vmi, err := virtClient.VirtualMachineInstance(ns).Get(context.Background(), vm.Name,
metav1.GetOptions{})
Expect(err).ToNot(HaveOccurred())
claim := storagetypes.PVCNameFromVirtVolume(&vmi.Spec.Volumes[0])
return claim == destDV.Name
}, 120*time.Second, time.Second).Should(BeTrue())
waitForMigrationToSucceed(vm.Name, ns)
})

It("should migrate a PVC with a VM using a containerdisk", func() {
volName := "volume"
srcPVC := "src-" + rand.String(5)
Expand Down

0 comments on commit 3ea0cc9

Please sign in to comment.