Skip to content

Commit a066a9d

Browse files
authored
fix(vm): fix restart VM after delete pod for run policy AlwaysOnUnles… (#632)
fix(vm): fix restart VM after delete pod for run policy AlwaysOnUnlessStoppedManually Signed-off-by: dmitry.lopatin <[email protected]>
1 parent b3c5083 commit a066a9d

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

images/virtualization-artifact/pkg/controller/vm/internal/sync_power_state.go

+22-6
Original file line numberDiff line numberDiff line change
@@ -183,12 +183,28 @@ func (h *SyncPowerStateHandler) syncPowerState(ctx context.Context, s state.Virt
183183
return fmt.Errorf("restart VM on guest-reset: %w", err)
184184
}
185185
default:
186-
h.recordStopEventf(ctx, s.VirtualMachine().Current(),
187-
"Stop initiated from inside the guest VM",
188-
)
189-
err = h.client.Delete(ctx, kvvmi)
190-
if err != nil && !k8serrors.IsNotFound(err) {
191-
return fmt.Errorf("delete Succeeded KVVMI: %w", err)
186+
vmPod, err := s.Pod(ctx)
187+
if err != nil {
188+
return fmt.Errorf("get virtual machine pod: %w", err)
189+
}
190+
191+
if vmPod != nil && !vmPod.GetObjectMeta().GetDeletionTimestamp().IsZero() {
192+
h.recordRestartEventf(ctx, s.VirtualMachine().Current(),
193+
"Restart initiated by controller for %s runPolicy after the deletion of pod VM.",
194+
runPolicy,
195+
)
196+
err = powerstate.SafeRestartVM(ctx, h.client, kvvm, kvvmi)
197+
if err != nil {
198+
return fmt.Errorf("automatic restart of failed VM: %w", err)
199+
}
200+
} else {
201+
h.recordStopEventf(ctx, s.VirtualMachine().Current(),
202+
"Stop initiated from inside the guest VM",
203+
)
204+
err = h.client.Delete(ctx, kvvmi)
205+
if err != nil && !k8serrors.IsNotFound(err) {
206+
return fmt.Errorf("delete Succeeded KVVMI: %w", err)
207+
}
192208
}
193209
}
194210
}

0 commit comments

Comments
 (0)