@@ -364,7 +364,10 @@ func (worker *Worker) syncVMs(ctx context.Context, updateVM func(context.Context
364364 case ActionMonitorRunning :
365365 if vmResource .Generation != vm .Resource .Generation {
366366 // VM specification changed, reboot the VM for the changes to take effect
367- if v1 .ConditionIsTrue (vm .Conditions (), v1 .ConditionTypeRunning ) {
367+ stoppingOrSuspending := v1 .ConditionIsTrue (vm .Conditions (), v1 .ConditionTypeStopping ) ||
368+ v1 .ConditionIsTrue (vm .Conditions (), v1 .ConditionTypeSuspending )
369+
370+ if v1 .ConditionIsTrue (vm .Conditions (), v1 .ConditionTypeRunning ) && ! stoppingOrSuspending {
368371 // VM is running, suspend or stop it first
369372 shouldStop := vmResource .PowerState == v1 .PowerStateStopped || ! vm .Resource .Suspendable
370373
@@ -373,21 +376,17 @@ func (worker *Worker) syncVMs(ctx context.Context, updateVM func(context.Context
373376 } else {
374377 vm .Suspend ()
375378 }
379+ }
376380
377- if vm .Resource .Suspendable && vmResource .PowerState != v1 .PowerStateStopped {
378- vm .Suspend ()
379- } else {
380- vm .Stop ()
381- }
382- } else if vmResource .PowerState == v1 .PowerStateRunning {
383- // VM stopped, start it with the new specification
381+ if v1 .ConditionIsFalse (vm .Conditions (), v1 .ConditionTypeRunning ) && ! stoppingOrSuspending {
382+ // VM stopped, update its specification
384383 vm .UpdateSpec (* vmResource )
385384
386- eventStreamer := worker . client . VMs (). StreamEvents ( vmResource . Name )
387- vm . Start ( eventStreamer )
388- } else if vmResource . PowerState == v1 . PowerStateSuspended || vmResource . PowerState == v1 . PowerStateStopped {
389- // VM stopped, just update its specification
390- vm . UpdateSpec ( * vmResource )
385+ if vmResource . PowerState == v1 . PowerStateRunning {
386+ // Start the VM
387+ eventStreamer := worker . client . VMs (). StreamEvents ( vmResource . Name )
388+ vm . Start ( eventStreamer )
389+ }
391390 }
392391 }
393392
0 commit comments