Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ova: fix migration with multiple disks #599

Merged
merged 1 commit into from
Sep 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 8 additions & 18 deletions pkg/controller/plan/adapter/ova/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,6 @@ const (
Unknown = "unknown"
)

// Annotations
const (
// CDI import backing file annotation on PVC
AnnImportBackingFile = "cdi.kubevirt.io/storage.import.backingFile"
)

// Error messages
const (
ErrVMLookupFailed = "VM lookup failed."
Expand Down Expand Up @@ -209,7 +203,7 @@ func (r *Builder) DataVolumes(vmRef ref.Ref, secret *core.Secret, _ *core.Config
if dv.ObjectMeta.Annotations == nil {
dv.ObjectMeta.Annotations = make(map[string]string)
}
dv.ObjectMeta.Annotations[planbase.AnnDiskSource] = getDiskSourcePath(disk.FilePath)
dv.ObjectMeta.Annotations[planbase.AnnDiskSource] = getDiskFullPath(disk)
dvs = append(dvs, *dv)
}
}
Expand Down Expand Up @@ -387,22 +381,15 @@ func (r *Builder) mapDisks(vm *model.VM, persistentVolumeClaims []core.Persisten
var kDisks []cnv.Disk

disks := vm.Disks
// TODO might need sort by the disk id (incremental name)
/*sort.Slice(disks, func(i, j int) bool {
return disks[i].Key < disks[j].Key
})*/
pvcMap := make(map[string]*core.PersistentVolumeClaim)
for i := range persistentVolumeClaims {
pvc := &persistentVolumeClaims[i]
// the PVC BackingFile value has already been trimmed.
if source, ok := pvc.Annotations[planbase.AnnDiskSource]; ok {
pvcMap[source] = pvc
} else {
pvcMap[pvc.Annotations[AnnImportBackingFile]] = pvc
}
}
for i, disk := range disks {
pvc := pvcMap[getDiskSourcePath(disk.FilePath)]
pvc := pvcMap[getDiskFullPath(disk)]
volumeName := fmt.Sprintf("vol-%v", i)
volume := cnv.Volume{
Name: volumeName,
Expand Down Expand Up @@ -446,7 +433,7 @@ func (r *Builder) Tasks(vmRef ref.Ref) (list []*plan.Task, err error) {
list = append(
list,
&plan.Task{
Name: getDiskSourcePath(disk.FilePath),
Name: getDiskFullPath(disk),
Progress: libitr.Progress{
Total: mB,
},
Expand Down Expand Up @@ -481,14 +468,13 @@ func (r *Builder) TemplateLabels(vmRef ref.Ref) (labels map[string]string, err e
return
}

// Return a stable identifier for a VDDK DataVolume.
func (r *Builder) ResolveDataVolumeIdentifier(dv *cdi.DataVolume) string {
return trimBackingFileName(dv.ObjectMeta.Annotations[planbase.AnnDiskSource])
}

// Return a stable identifier for a PersistentDataVolume.
func (r *Builder) ResolvePersistentVolumeClaimIdentifier(pvc *core.PersistentVolumeClaim) string {
return trimBackingFileName(pvc.Annotations[AnnImportBackingFile])
return ""
}

// Trims the snapshot suffix from a disk backing file name if there is one.
Expand All @@ -500,6 +486,10 @@ func trimBackingFileName(fileName string) string {
return backingFilePattern.ReplaceAllString(fileName, ".vmdk")
}

func getDiskFullPath(disk ova.Disk) string {
return disk.FilePath + "::" + disk.Name
}

func getDiskSourcePath(filePath string) string {
if strings.HasSuffix(filePath, ".ova") {
return filePath
Expand Down
Loading