Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kvm with containerd needs more time to stop #17967

Merged
merged 1 commit into from
Jan 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions pkg/drivers/kvm/kvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,27 +175,26 @@ func (d *Driver) GetState() (st state.State, err error) {

// machineState converts libvirt state to libmachine state
func machineState(lvs libvirt.DomainState) state.State {
// Possible States:
//
// VIR_DOMAIN_NOSTATE no state
// VIR_DOMAIN_RUNNING the domain is running
// VIR_DOMAIN_BLOCKED the domain is blocked on resource
// VIR_DOMAIN_PAUSED the domain is paused by user
// VIR_DOMAIN_SHUTDOWN the domain is being shut down
// VIR_DOMAIN_SHUTOFF the domain is shut off
// VIR_DOMAIN_CRASHED the domain is crashed
// VIR_DOMAIN_PMSUSPENDED the domain is suspended by guest power management
// VIR_DOMAIN_LAST this enum value will increase over time as new events are added to the libvirt API. It reflects the last state supported by this version of the libvirt API.
// Possible States (ref: https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainState):
// - VIR_DOMAIN_NOSTATE no state
// - VIR_DOMAIN_RUNNING the domain is running
// - VIR_DOMAIN_BLOCKED the domain is blocked on resource
// - VIR_DOMAIN_PAUSED the domain is paused by user
// - VIR_DOMAIN_SHUTDOWN the domain is being shut down
// - VIR_DOMAIN_SHUTOFF the domain is shut off
// - VIR_DOMAIN_CRASHED the domain is crashed
// - VIR_DOMAIN_PMSUSPENDED the domain is suspended by guest power management
// - VIR_DOMAIN_LAST this enum value will increase over time as new events are added to the libvirt API. It reflects the last state supported by this version of the libvirt API.

switch lvs {
// DOMAIN_SHUTDOWN technically means the VM is still running, but in the
// process of being shutdown, so we return state.Running
case libvirt.DOMAIN_RUNNING, libvirt.DOMAIN_SHUTDOWN:
case libvirt.DOMAIN_RUNNING:
return state.Running
case libvirt.DOMAIN_BLOCKED, libvirt.DOMAIN_CRASHED:
return state.Error
case libvirt.DOMAIN_PAUSED:
return state.Paused
case libvirt.DOMAIN_SHUTDOWN:
return state.Stopping
case libvirt.DOMAIN_SHUTOFF:
return state.Stopped
case libvirt.DOMAIN_PMSUSPENDED:
Expand Down Expand Up @@ -451,16 +450,17 @@ func (d *Driver) Stop() (err error) {
return errors.Wrap(err, "stopping vm")
}

for i := 0; i < 60; i++ {
maxsec := 120
for i := 0; i < maxsec; i++ {
s, err := d.GetState()
if err != nil {
return errors.Wrap(err, "error getting state of VM")
}
if s == state.Stopped {
return nil
}
log.Infof("Waiting for machine to stop %d/%d", i, 60)
time.Sleep(1 * time.Second)
log.Infof("Waiting for machine to stop %d/%d", i, maxsec)
time.Sleep(time.Second)
}

}
Expand Down
Loading