Skip to content

Commit

Permalink
allow multiple calls to graceful shutdown in case acpi did not reciev…
Browse files Browse the repository at this point in the history
…e call

Signed-off-by: Ashley Schuett <[email protected]>
  • Loading branch information
ashleyschuett committed May 26, 2021
1 parent 6a93d64 commit edaf2a2
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
16 changes: 8 additions & 8 deletions pkg/virt-launcher/virtwrap/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -1155,14 +1155,14 @@ func (l *LibvirtDomainManager) SignalShutdownVMI(vmi *v1.VirtualMachineInstance)
return err
}

if domSpec.Metadata.KubeVirt.GracePeriod.DeletionTimestamp == nil {
err = dom.ShutdownFlags(libvirt.DOMAIN_SHUTDOWN_ACPI_POWER_BTN)
if err != nil {
log.Log.Object(vmi).Reason(err).Error("Signalling graceful shutdown failed.")
return err
}
log.Log.Object(vmi).Infof("Signaled graceful shutdown for %s", vmi.GetObjectMeta().GetName())
err = dom.ShutdownFlags(libvirt.DOMAIN_SHUTDOWN_ACPI_POWER_BTN)
if err != nil {
log.Log.Object(vmi).Reason(err).Error("Signalling graceful shutdown failed.")
return err
}
log.Log.Object(vmi).Infof("Signaled graceful shutdown for %s", vmi.GetObjectMeta().GetName())

if domSpec.Metadata.KubeVirt.GracePeriod.DeletionTimestamp == nil {
now := metav1.Now()
domSpec.Metadata.KubeVirt.GracePeriod.DeletionTimestamp = &now
d, err := l.setDomainSpecWithHooks(vmi, domSpec)
Expand Down Expand Up @@ -1213,7 +1213,7 @@ func (l *LibvirtDomainManager) KillVMI(vmi *v1.VirtualMachineInstance) error {
return nil
}

log.Log.Object(vmi).Info("Domain not running or paused, nothing to do.")
log.Log.Object(vmi).Info("Domain not running, paused or shut down, nothing to do.")
return nil
}

Expand Down
24 changes: 24 additions & 0 deletions pkg/virt-launcher/virtwrap/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -880,6 +880,30 @@ var _ = Describe("Manager", func() {

manager.MarkGracefulShutdownVMI(vmi)
})

It("Should signal graceful shutdown after marked for shutdown", func() {
mockDomain.EXPECT().Free().AnyTimes()

vmi := newVMI(testNamespace, testVmName)
domainSpec := expectIsolationDetectionForVMI(vmi)

xml, err := xml.MarshalIndent(domainSpec, "", "\t")
Expect(err).To(BeNil())

Expect(err).To(BeNil())
mockDomain.EXPECT().GetState().AnyTimes().Return(libvirt.DOMAIN_RUNNING, 1, nil)
mockConn.EXPECT().LookupDomainByName(testDomainName).AnyTimes().Return(mockDomain, nil)
mockDomain.EXPECT().GetXMLDesc(gomock.Eq(libvirt.DomainXMLFlags(0))).AnyTimes().Return(string(xml), nil)
mockDomain.EXPECT().
GetMetadata(libvirt.DOMAIN_METADATA_ELEMENT, "http://kubevirt.io", libvirt.DOMAIN_AFFECT_CONFIG).
AnyTimes().
Return(`<kubevirt><graceperiod><deletionGracePeriodSeconds>3600</deletionGracePeriodSeconds><deletionTimestamp>2021-03-11T09:08:20.144606353Z</deletionTimestamp><markedForGracefulShutdown>true</markedForGracefulShutdown></graceperiod></kubevirt>`, nil)

mockDomain.EXPECT().ShutdownFlags(libvirt.DOMAIN_SHUTDOWN_ACPI_POWER_BTN).Times(1).Return(nil)
manager, _ := NewLibvirtDomainManager(mockConn, testVirtShareDir, nil, 0, nil, "/usr/share/OVMF", ephemeralDiskCreatorMock)

manager.SignalShutdownVMI(vmi)
})
})
Context("test migration monitor", func() {
It("migration should be canceled if it's not progressing", func() {
Expand Down

0 comments on commit edaf2a2

Please sign in to comment.