Skip to content

Commit

Permalink
Merge pull request kubevirt#6610 from davidvossel/suppress-defined-event
Browse files Browse the repository at this point in the history
Only send VirtualMachineDefined event when domain does not exist
  • Loading branch information
kubevirt-bot authored Oct 15, 2021
2 parents 8d76c6c + b569753 commit 06b91d7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
16 changes: 10 additions & 6 deletions pkg/virt-handler/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -1612,7 +1612,7 @@ func (d *VirtualMachineController) migrationTargetExecute(vmi *v1.VirtualMachine
log.Log.Object(vmi).Info("Processing vmi migration target update")

// prepare the POD for the migration
err := d.processVmUpdate(vmi)
err := d.processVmUpdate(vmi, domainExists)
if err != nil {
return err
}
Expand Down Expand Up @@ -1813,7 +1813,7 @@ func (d *VirtualMachineController) defaultExecute(key string,
syncErr = d.processVmCleanup(vmi)
case shouldUpdate:
log.Log.Object(vmi).V(3).Info("Processing vmi update")
syncErr = d.processVmUpdate(vmi)
syncErr = d.processVmUpdate(vmi, domainExists)
default:
log.Log.Object(vmi).V(3).Info("No update processing required")
}
Expand Down Expand Up @@ -2598,7 +2598,7 @@ func (d *VirtualMachineController) vmUpdateHelperMigrationTarget(origVMI *v1.Vir
}
return nil
}
func (d *VirtualMachineController) vmUpdateHelperDefault(origVMI *v1.VirtualMachineInstance) error {
func (d *VirtualMachineController) vmUpdateHelperDefault(origVMI *v1.VirtualMachineInstance, domainExists bool) error {
client, err := d.getLauncherClient(origVMI)
if err != nil {
return fmt.Errorf("unable to create virt-launcher client connection: %v", err)
Expand Down Expand Up @@ -2704,7 +2704,11 @@ func (d *VirtualMachineController) vmUpdateHelperDefault(origVMI *v1.VirtualMach
}
return err
}
d.recorder.Event(vmi, k8sv1.EventTypeNormal, v1.Created.String(), "VirtualMachineInstance defined.")

if !domainExists {
d.recorder.Event(vmi, k8sv1.EventTypeNormal, v1.Created.String(), VMIDefined)
}

if vmi.IsRunning() {
// Umount any disks no longer mounted
if err := d.hotplugVolumeMounter.Unmount(vmi); err != nil {
Expand All @@ -2714,7 +2718,7 @@ func (d *VirtualMachineController) vmUpdateHelperDefault(origVMI *v1.VirtualMach
return nil
}

func (d *VirtualMachineController) processVmUpdate(vmi *v1.VirtualMachineInstance) error {
func (d *VirtualMachineController) processVmUpdate(vmi *v1.VirtualMachineInstance, domainExists bool) error {

isUnresponsive, isInitialized, err := d.isLauncherClientUnresponsive(vmi)
if err != nil {
Expand All @@ -2734,7 +2738,7 @@ func (d *VirtualMachineController) processVmUpdate(vmi *v1.VirtualMachineInstanc
} else if d.isMigrationSource(vmi) {
return d.vmUpdateHelperMigrationSource(vmi)
} else {
return d.vmUpdateHelperDefault(vmi)
return d.vmUpdateHelperDefault(vmi, domainExists)
}
}

Expand Down
7 changes: 0 additions & 7 deletions pkg/virt-handler/vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,6 @@ var _ = Describe("VirtualMachineInstance", func() {
mockHotplugVolumeMounter.EXPECT().Mount(gomock.Any()).Return(nil)

controller.Execute()
testutils.ExpectEvent(recorder, VMIDefined)
})

It("should maintain unsupported user agent condition when it's already set", func() {
Expand Down Expand Up @@ -820,7 +819,6 @@ var _ = Describe("VirtualMachineInstance", func() {
mockHotplugVolumeMounter.EXPECT().Mount(gomock.Any()).Return(nil)

controller.Execute()
testutils.ExpectEvent(recorder, VMIDefined)
})

It("should remove guest agent condition when there is no channel connected", func() {
Expand Down Expand Up @@ -876,7 +874,6 @@ var _ = Describe("VirtualMachineInstance", func() {
mockHotplugVolumeMounter.EXPECT().Mount(gomock.Any()).Return(nil)

controller.Execute()
testutils.ExpectEvent(recorder, VMIDefined)
})

It("should add access credential synced condition when credentials report success", func() {
Expand Down Expand Up @@ -1073,8 +1070,6 @@ var _ = Describe("VirtualMachineInstance", func() {
vmiInterface.EXPECT().Update(NewVMICondMatcher(*updatedVMI))

controller.Execute()
testutils.ExpectEvent(recorder, VMIDefined)
testutils.ExpectEvent(recorder, VMIDefined)
})

It("should move VirtualMachineInstance from Scheduled to Failed if watchdog file is missing", func() {
Expand Down Expand Up @@ -1268,7 +1263,6 @@ var _ = Describe("VirtualMachineInstance", func() {
client.EXPECT().SyncVirtualMachine(vmi, gomock.Any())

controller.Execute()
testutils.ExpectEvent(recorder, VMIDefined)
})

It("should call mount, fail if mount fails", func() {
Expand Down Expand Up @@ -2982,7 +2976,6 @@ var _ = Describe("VirtualMachineInstance", func() {
}
}).Return(vmi, nil)
controller.Execute()
testutils.ExpectEvent(recorder, VMIDefined)
})
})

Expand Down

0 comments on commit 06b91d7

Please sign in to comment.