Skip to content

Detect Spark driver completion by container state when tracking via k8s API - #68048

Open
karenbraganz wants to merge 12 commits into
apache:mainfrom
karenbraganz:spark-container-status
Open

Detect Spark driver completion by container state when tracking via k8s API#68048
karenbraganz wants to merge 12 commits into
apache:mainfrom
karenbraganz:spark-container-status

Conversation

@karenbraganz

@karenbraganz karenbraganz commented Jun 5, 2026

Copy link
Copy Markdown
Collaborator

This PR tracks Spark job completion by container state instead of pod phase when track_driver_via_k8s_api=True. Sometimes the pod continues to run even after the driver container completes due to other sidecar containers. This PR makes driver completion detection more accurate by examining the container itself.

@karenbraganz

karenbraganz commented Jun 5, 2026

Copy link
Copy Markdown
Collaborator Author

I still need to test this out and write unit tests.

@karenbraganz
karenbraganz requested a review from amoghrajesh June 9, 2026 16:39
@karenbraganz

Copy link
Copy Markdown
Collaborator Author

This has passed all unit tests as well as a manual test that I ran.

Comment thread providers/apache/spark/src/airflow/providers/apache/spark/hooks/spark_submit.py Outdated
@karenbraganz
karenbraganz requested a review from uranusjr July 21, 2026 13:48
Comment on lines +1202 to +1207
for container in pod.spec.containers:
if "spark" in container.name.lower() or "driver" in container.name.lower():
driver_container = container
break
if len(pod.spec.containers) == 1:
driver_container = container

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Say with a pod whose containers are [spark-metrics-exporter, spark-kubernetes-driver], where the exporter has terminated 0 and the driver is still Running. The loop matches the exporter, sets container_completed=True, and returns Succeeded. The task is now terminal, but the Spark application is still executing. The lookup loop needs more work.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Also, we should probably make the names configurable as suggested in the original issue.

terminal_phase = phase
break
if phase == "Failed":
if phase == "Failed" and not container_completed:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The added clause means a pod in Failed whose driver exited 0 (e.g. an Istio sidecar crashed) now falls through to line 1277 and returns Succeeded. We should at least log a warning.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

For spark operator with track_driver_via_k8s_api, detect driver completion by container status rather than pod phase

2 participants