Skip to content

Commit

Permalink
Merge pull request kubevirt#3952 from davidvossel/failed-cleanup
Browse files Browse the repository at this point in the history
Avoid local cleanup of vmi until vmi is in a finalized state
  • Loading branch information
kubevirt-bot authored Aug 14, 2020
2 parents f4b3eac + b719b3d commit 07d1ceb
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
4 changes: 3 additions & 1 deletion pkg/virt-handler/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -1234,7 +1234,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
}
}
}

Expand Down
29 changes: 29 additions & 0 deletions pkg/virt-handler/vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,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
Expand Down

0 comments on commit 07d1ceb

Please sign in to comment.