From c9ceead52cec1caeb00f0dae1696ed33b3d47b04 Mon Sep 17 00:00:00 2001 From: David Vossel Date: Fri, 7 Aug 2020 16:45:17 -0400 Subject: [PATCH 1/2] Do not perform local cleanup of vmi until vmi is in a finalized state Signed-off-by: David Vossel --- pkg/virt-handler/vm.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pkg/virt-handler/vm.go b/pkg/virt-handler/vm.go index 6c3ff4020765..68c007416590 100644 --- a/pkg/virt-handler/vm.go +++ b/pkg/virt-handler/vm.go @@ -1232,7 +1232,9 @@ func (d *VirtualMachineController) defaultExecute(key string, log.Log.Object(vmi).V(3).Info("Deleting domain for VirtualMachineInstance with deletion timestamp.") shouldDelete = true default: - shouldCleanUp = true + if vmi.IsFinal() { + shouldCleanUp = true + } } } From b719b3ddeef8dbba7a400578bde20082e5bb9234 Mon Sep 17 00:00:00 2001 From: David Vossel Date: Fri, 7 Aug 2020 16:45:45 -0400 Subject: [PATCH 2/2] Unit test for ensuring local cleanup of vmi does not occur on non finalized vmi Signed-off-by: David Vossel --- pkg/virt-handler/vm_test.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/pkg/virt-handler/vm_test.go b/pkg/virt-handler/vm_test.go index 2e27d18f8f4a..b22bdcd0593c 100644 --- a/pkg/virt-handler/vm_test.go +++ b/pkg/virt-handler/vm_test.go @@ -442,6 +442,35 @@ var _ = Describe("VirtualMachineInstance", func() { Expect(len(controller.phase1NetworkSetupCache)).To(Equal(0)) }, 3) + It("should do final cleanup if vmi is being deleted and not finalized", func() { + vmi := v1.NewMinimalVMI("testvmi") + vmi.UID = vmiTestUUID + vmi.Status.Phase = v1.Scheduled + now := metav1.Time{Time: time.Now()} + vmi.DeletionTimestamp = &now + vmi.Status.MigrationMethod = v1.LiveMigration + vmi.Status.Conditions = []v1.VirtualMachineInstanceCondition{ + { + Type: v1.VirtualMachineInstanceIsMigratable, + Status: k8sv1.ConditionTrue, + }, + } + + mockWatchdog.CreateFile(vmi) + + controller.phase1NetworkSetupCache[vmi.UID] = 1 + vmiFeeder.Add(vmi) + + client.EXPECT().SyncVirtualMachine(vmi, gomock.Any()) + + controller.Execute() + Expect(mockQueue.Len()).To(Equal(0)) + Expect(mockQueue.GetRateLimitedEnqueueCount()).To(Equal(0)) + _, err := os.Stat(mockWatchdog.File(vmi)) + Expect(os.IsNotExist(err)).To(BeFalse()) + Expect(len(controller.phase1NetworkSetupCache)).To(Equal(1)) + }, 3) + It("should attempt force terminate Domain if grace period expires", func() { vmi := v1.NewMinimalVMI("testvmi") vmi.UID = vmiTestUUID