Skip to content

Commit

Permalink
feat: Add error event and handle it
Browse files Browse the repository at this point in the history
Signed-off-by: Cezar Craciunoiu <[email protected]>
  • Loading branch information
craciunoiuc committed Aug 7, 2023
1 parent 4ec62b1 commit 71509c7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions api/machine/v1alpha1/machine.zip.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ const (
MachineStatePaused = MachineState("paused")
MachineStateSuspended = MachineState("suspended")
MachineStateExited = MachineState("exited")
MachineStateErrored = MachineState("errored")
)

// String implements fmt.Stringer
Expand Down
13 changes: 12 additions & 1 deletion machine/qemu/v1alpha1.go
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,13 @@ func (service *machineV1alpha1Service) Watch(ctx context.Context, machine *machi
machine.Status.State = machinev1alpha1.MachineStateExited
events <- machine

if !qcfg.NoShutdown {
break accept
}
case qmpapi.EVENT_GUEST_PANICKED:
machine.Status.State = machinev1alpha1.MachineStateErrored
events <- machine

if !qcfg.NoShutdown {
break accept
}
Expand Down Expand Up @@ -842,7 +849,11 @@ func (service *machineV1alpha1Service) Get(ctx context.Context, machine *machine

// Map the QMP status to supported machine states
switch status.Return.Status {
case qmpapi.RUN_STATE_GUEST_PANICKED, qmpapi.RUN_STATE_INTERNAL_ERROR, qmpapi.RUN_STATE_IO_ERROR:
case qmpapi.RUN_STATE_GUEST_PANICKED:
state = machinev1alpha1.MachineStateErrored
exitCode = 1

case qmpapi.RUN_STATE_INTERNAL_ERROR, qmpapi.RUN_STATE_IO_ERROR:
state = machinev1alpha1.MachineStateFailed
exitCode = 1

Expand Down

0 comments on commit 71509c7

Please sign in to comment.