From daf8661c20c148f18f60a28cf9e076965baddf13 Mon Sep 17 00:00:00 2001 From: Martin Necas Date: Tue, 8 Oct 2024 16:18:53 +0200 Subject: [PATCH] MTV-1477 | Add DataVolume deletion when archiving Issue: When running the migration archive we do not delete the DataVolumes. Fix: Add deletion of the DataVolumes when running the archive and the VM migration failed. At some cases the migration in the context is missing the migration ID so we can use the plan instead to find the DataVolume. Fixes: https://issues.redhat.com/browse/MTV-1477 Signed-off-by: Martin Necas --- pkg/controller/plan/kubevirt.go | 2 +- pkg/controller/plan/migration.go | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/pkg/controller/plan/kubevirt.go b/pkg/controller/plan/kubevirt.go index 4afa58a5d..af44af2a1 100644 --- a/pkg/controller/plan/kubevirt.go +++ b/pkg/controller/plan/kubevirt.go @@ -661,7 +661,7 @@ func (r *KubeVirt) getDVs(vm *plan.VMStatus) (edvs []ExtendedDataVolume, err err context.TODO(), dvsList, &client.ListOptions{ - LabelSelector: k8slabels.SelectorFromSet(r.vmLabels(vm.Ref)), + LabelSelector: k8slabels.SelectorFromSet(r.vmAllButMigrationLabels(vm.Ref)), Namespace: r.Plan.Spec.TargetNamespace, }) diff --git a/pkg/controller/plan/migration.go b/pkg/controller/plan/migration.go index 122ebffb2..f3c9e0530 100644 --- a/pkg/controller/plan/migration.go +++ b/pkg/controller/plan/migration.go @@ -458,6 +458,9 @@ func (r *Migration) cleanup(vm *plan.VMStatus, failOnErr func(error) bool) error if err := r.deletePopulatorPVCs(vm); failOnErr(err) { return err } + if err := r.kubevirt.DeleteDataVolumes(vm); failOnErr(err) { + return err + } } if err := r.deleteImporterPods(vm); failOnErr(err) { return err