Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ private[spark] case class ExecutorPodsSnapshot(executorPods: Map[Long, ExecutorP

object ExecutorPodsSnapshot extends Logging {
private var shouldCheckAllContainers: Boolean = _
private var sparkContainerName: String = _
private var sparkContainerName: String = DEFAULT_EXECUTOR_CONTAINER_NAME

def apply(executorPods: Seq[Pod]): ExecutorPodsSnapshot = {
ExecutorPodsSnapshot(toStatesByExecutorId(executorPods))
Expand Down Expand Up @@ -80,24 +80,21 @@ object ExecutorPodsSnapshot extends Logging {
.anyMatch(t => t != null && t.getExitCode != 0)) {
PodFailed(pod)
} else {
// Otherwise look for the Spark container
val sparkContainerStatusOpt = pod.getStatus.getContainerStatuses.asScala
.find(_.getName() == sparkContainerName)
sparkContainerStatusOpt match {
case Some(sparkContainerStatus) =>
sparkContainerStatus.getState.getTerminated match {
case t if t.getExitCode != 0 =>
PodFailed(pod)
case t if t.getExitCode == 0 =>
// Otherwise look for the Spark container and get the exit code if present.
val sparkContainerExitCode = pod.getStatus.getContainerStatuses.asScala
.find(_.getName() == sparkContainerName).flatMap(x => Option(x.getState))
.flatMap(x => Option(x.getTerminated)).flatMap(x => Option(x.getExitCode))
.map(_.toInt)
sparkContainerExitCode match {
case Some(t) =>
t match {
case 0 =>
PodSucceeded(pod)
case _ =>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we have three case statements before this line, t is null and t is not null and exit code is non-zero and t is not null and exist code is zero` is covered. When we fall into here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't but this is to prevent the spurious "non-exhaustive match" warning.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, got it.

PodRunning(pod)
PodFailed(pod)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about the following?

sparkContainerStatus.getState.getTerminated match {
  case t if t != null and t.getExitCode != 0 =>
    PodFailed(pod)
  case t if t != null and t.getExitCode == 0 =>
    PodSucceeded(pod)
  case _ =>
    PodRunning(pod)
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure that would work to. Do you prefer this one?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I do because it's shorter. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I refactored this into using flatMaps so we can just pattern match on the result, WDYT?

// If we can't find the Spark container status, fall back to the pod status. This is
// expected to occur during pod startup and other situations.
// No exit code means we are running.
case _ =>
logDebug(s"Unable to find container ${sparkContainerName} in pod ${pod} " +
"defaulting to entire pod status (running).")
PodRunning(pod)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,16 @@ object ExecutorLifecycleTestUtils {
.editOrNewStatus()
.withPhase("running")
.addNewContainerStatus()
.withName(DEFAULT_EXECUTOR_CONTAINER_NAME)
.withNewState()
.withNewTerminated()
.withMessage("message")
.withExitCode(exitCode)
.endTerminated()
.endState()
.endContainerStatus()
.addNewContainerStatus()
.withName("SIDECARFRIEND")
.withNewState()
.withNewRunning()
.endRunning()
Expand Down