Skip to content

Commit

Permalink
Better handle force delete scenario with unified controllers
Browse files Browse the repository at this point in the history
Signed-off-by: Roman Mohr <[email protected]>
  • Loading branch information
rmohr committed Oct 27, 2017
1 parent 6bb2ee5 commit d6852d0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pkg/virt-handler/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ func (d *VirtualMachineController) execute(key string) error {

// Process the VM only if the current phases are in sync
var syncErr error
if vm.Status.Phase == d.calculateVmPhaseForStatusReason(domain, vm) {
if vm.Status.Phase == d.calculateVmPhaseForStatusReason(domain, vm) || !exists {
syncErr = d.processVmUpdate(vm.DeepCopy(), shouldDeleteVm)
if syncErr != nil {
d.recorder.Event(vm, k8sv1.EventTypeWarning, v1.SyncFailed.String(), syncErr.Error())
Expand Down
14 changes: 13 additions & 1 deletion pkg/virt-handler/vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ var _ = Describe("VM", func() {

Context("VM controller gets informed about a Domain change through the Domain controller", func() {

It("should kill the Domain if no cluster wide equivalent exists", func() {
It("should delete non-running Domains if no cluster wide equivalent exists", func() {
domain := api.NewMinimalDomain("testvm")
domainFeeder.Add(domain)
vmInterface.EXPECT().Get("testvm", gomock.Any()).Return(nil, errors.NewNotFound(schema.GroupResource{}, ""))
Expand All @@ -122,6 +122,18 @@ var _ = Describe("VM", func() {
controller.Execute()
})

It("should delete running Domains if no cluster wide equivalent exists", func() {
domain := api.NewMinimalDomain("testvm")
domain.Status.Status = api.Running
domainFeeder.Add(domain)
vmInterface.EXPECT().Get("testvm", gomock.Any()).Return(nil, errors.NewNotFound(schema.GroupResource{}, ""))

domainManager.EXPECT().RemoveVMSecrets(v1.NewVMReferenceFromName("testvm")).Return(nil)
domainManager.EXPECT().KillVM(v1.NewVMReferenceFromName("testvm"))

controller.Execute()
})

It("should leave the Domain alone if the VM is migrating to its host", func() {
vm := v1.NewMinimalVM("testvm")
vm.Status.MigrationNodeName = "master"
Expand Down

0 comments on commit d6852d0

Please sign in to comment.