Skip to content

Commit

Permalink
Revert "neonvm: Use container statuses, not pod phase, to trigger res…
Browse files Browse the repository at this point in the history
…tart (#749)"

This reverts commit 7f17032.

Signed-off-by: Oleg Vasilev <[email protected]>
  • Loading branch information
Omrigan committed Aug 29, 2024
1 parent 709b572 commit fcc5f64
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 52 deletions.
52 changes: 2 additions & 50 deletions neonvm/controllers/vm_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -932,20 +932,7 @@ const (

// runnerStatus returns a description of the status of the VM inside the runner pod.
//
// This is *similar* to the value of pod.Status.Phase, but takes into consideration the statuses of
// the individual containers within the pod. This is because Kubernetes sets the pod phase to Failed
// or Succeeded only if *all* pods have exited, whereas we'd like to consider the VM to be Failed or
// Succeeded if *any* pod has exited.
//
// The full set of outputs is:
//
// - runnerUnknown, if pod.Status.Phase is Unknown
// - runnerPending, if pod.Status.Phase is "" or Pending
// - runnerRunning, if pod.Status.Phase is Running, and no containers have exited
// - runnerFailed, if pod.Status.Phase is Failed, or if any container has failed, or if any
// container other than neonvm-runner has exited
// - runnerSucceeded, if pod.Status.Phase is Succeeded, or if neonvm-runner has exited
// successfully
// This is *similar* to the value of pod.Status.Phaseg .
func runnerStatus(pod *corev1.Pod) runnerStatusKind {
switch pod.Status.Phase {
case "", corev1.PodPending:
Expand All @@ -956,43 +943,8 @@ func runnerStatus(pod *corev1.Pod) runnerStatusKind {
return runnerFailed
case corev1.PodUnknown:
return runnerUnknown

// See comment above for context on this logic
case corev1.PodRunning:
nonRunnerContainerSucceeded := false
runnerContainerSucceeded := false

for _, stat := range pod.Status.ContainerStatuses {
if stat.State.Terminated != nil {
failed := stat.State.Terminated.ExitCode != 0
isRunner := stat.Name == "neonvm-runner"

if failed {
// return that the "runner" has failed if any container has.
return runnerFailed
} else /* succeeded */ {
if isRunner {
// neonvm-runner succeeded. We'll return runnerSucceeded if no other
// container has failed.
runnerContainerSucceeded = true
} else {
// Other container has succeeded. We'll return runnerSucceeded if
// neonvm-runner has succeeded, but runnerFailed if this exited while
// neonvm-runner is still going.
nonRunnerContainerSucceeded = true
}
}
}
}

if runnerContainerSucceeded {
return runnerSucceeded
} else if nonRunnerContainerSucceeded {
return runnerFailed
} else {
return runnerRunning
}

return runnerRunning
default:
panic(fmt.Errorf("unknown pod phase: %q", pod.Status.Phase))
}
Expand Down
2 changes: 0 additions & 2 deletions tests/e2e/runner-pod/01-assert.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ status:
conditions:
- type: Available
status: "True"
- type: Degraded
status: "True"
cpus: 250m
memorySize: 1Gi
restartCount: 1
Expand Down

0 comments on commit fcc5f64

Please sign in to comment.