Skip to content

Commit 10ecd0a

Browse files
committed
kvm with containerd needs more time to stop
1 parent 838ea0c commit 10ecd0a

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

pkg/drivers/kvm/kvm.go

+17-17
Original file line numberDiff line numberDiff line change
@@ -175,27 +175,26 @@ func (d *Driver) GetState() (st state.State, err error) {
175175

176176
// machineState converts libvirt state to libmachine state
177177
func machineState(lvs libvirt.DomainState) state.State {
178-
// Possible States:
179-
//
180-
// VIR_DOMAIN_NOSTATE no state
181-
// VIR_DOMAIN_RUNNING the domain is running
182-
// VIR_DOMAIN_BLOCKED the domain is blocked on resource
183-
// VIR_DOMAIN_PAUSED the domain is paused by user
184-
// VIR_DOMAIN_SHUTDOWN the domain is being shut down
185-
// VIR_DOMAIN_SHUTOFF the domain is shut off
186-
// VIR_DOMAIN_CRASHED the domain is crashed
187-
// VIR_DOMAIN_PMSUSPENDED the domain is suspended by guest power management
188-
// 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.
178+
// Possible States (ref: https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainState):
179+
// - VIR_DOMAIN_NOSTATE no state
180+
// - VIR_DOMAIN_RUNNING the domain is running
181+
// - VIR_DOMAIN_BLOCKED the domain is blocked on resource
182+
// - VIR_DOMAIN_PAUSED the domain is paused by user
183+
// - VIR_DOMAIN_SHUTDOWN the domain is being shut down
184+
// - VIR_DOMAIN_SHUTOFF the domain is shut off
185+
// - VIR_DOMAIN_CRASHED the domain is crashed
186+
// - VIR_DOMAIN_PMSUSPENDED the domain is suspended by guest power management
187+
// - 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.
189188

190189
switch lvs {
191-
// DOMAIN_SHUTDOWN technically means the VM is still running, but in the
192-
// process of being shutdown, so we return state.Running
193-
case libvirt.DOMAIN_RUNNING, libvirt.DOMAIN_SHUTDOWN:
190+
case libvirt.DOMAIN_RUNNING:
194191
return state.Running
195192
case libvirt.DOMAIN_BLOCKED, libvirt.DOMAIN_CRASHED:
196193
return state.Error
197194
case libvirt.DOMAIN_PAUSED:
198195
return state.Paused
196+
case libvirt.DOMAIN_SHUTDOWN:
197+
return state.Stopping
199198
case libvirt.DOMAIN_SHUTOFF:
200199
return state.Stopped
201200
case libvirt.DOMAIN_PMSUSPENDED:
@@ -451,16 +450,17 @@ func (d *Driver) Stop() (err error) {
451450
return errors.Wrap(err, "stopping vm")
452451
}
453452

454-
for i := 0; i < 60; i++ {
453+
maxsec := 120
454+
for i := 0; i < maxsec; i++ {
455455
s, err := d.GetState()
456456
if err != nil {
457457
return errors.Wrap(err, "error getting state of VM")
458458
}
459459
if s == state.Stopped {
460460
return nil
461461
}
462-
log.Infof("Waiting for machine to stop %d/%d", i, 60)
463-
time.Sleep(1 * time.Second)
462+
log.Infof("Waiting for machine to stop %d/%d", i, maxsec)
463+
time.Sleep(time.Second)
464464
}
465465

466466
}

0 commit comments

Comments
 (0)