Skip to content

[LIVY-1084] Prefer spark container exit status over pod phase when sidecars are enabled - #559

Open
soumyadeeplogin wants to merge 1 commit into
apache:masterfrom
soumyadeeplogin:livy-item8-sidecar-exit-status-priority
Open

soumyadeeplogin wants to merge 1 commit into
apache:masterfrom
soumyadeeplogin:livy-item8-sidecar-exit-status-priority

Conversation

@soumyadeeplogin

@soumyadeeplogin soumyadeeplogin commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

When livy.server.kubernetes.spark.sidecar.enabled is true, SparkKubernetesApp.KubernetesAppReport.getDriverState returned the raw pod phase whenever the phase wasn't "running", before ever consulting the spark container's own termination status. A sidecar container that fails or gets OOMKilled after the spark driver container has already exited successfully can flip the pod phase to "Failed", which Livy then reports as the terminal application state even though the actual Spark job succeeded.

This PR changes getDriverState so that, when sidecars are enabled, it always consults getTerminalState (the spark container's own exit code) first, and only falls back to the pod phase if the spark container cannot be found in the pod's container statuses. It also guards getTerminalState against getContainerStatuses() returning null, which happens while the pod is still in the Pending phase, to avoid an NPE.

Why are the changes needed?

To report the correct terminal application state (succeeded/failed) based on the actual Spark driver's exit code, rather than being misled by an unrelated sidecar container's failure flipping the pod phase.

Does this PR introduce any user-facing change?

Yes, but only when livy.server.kubernetes.spark.sidecar.enabled is true (the default). /sessions/:id/state and /batches/:id/state will now report succeeded for a pod whose spark container exited 0 even if a sidecar container's failure left the pod phase as Failed.

How was this patch tested?

Added a unit test to SparkKubernetesAppSpec (should prefer spark container exit status over pod phase when sidecars are enabled) covering: sidecar failure with a successfully-terminated spark container, a failed spark container, an indeterminate/not-yet-terminated spark container (falls back to phase), a pending pod with null container statuses (no NPE, falls back to phase), and sidecars disabled (phase is authoritative).

Ran mvn -pl server -am test -Dtest=SparkKubernetesAppSpec -DwildcardSuites=org.apache.livy.utils.SparkKubernetesAppSpec; all 12 tests pass.

Was this patch authored or co-authored using generative AI tooling?

Yes, this patch was co-authored using Claude Code (Anthropic).

…nabled

A sidecar failure can mark the pod as "failed" even when the spark
driver exited successfully. Remove the early return on non-running
pod phase so that getTerminalState is always consulted first when
sidecars are enabled, falling back to pod phase only when the spark
container cannot be found.

Add null safety for getContainerStatuses, which can be null while
the pod is still in pending phase.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@soumyadeeplogin

Copy link
Copy Markdown
Contributor Author

Filed LIVY-1084 for this change.

@soumyadeeplogin

Copy link
Copy Markdown
Contributor Author

Hi @gyogal / @roczei — could one of you approve the pending CI workflow run for this PR (fork-contributor approval gate)? Happy to address any review feedback as well. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant