Skip to content

feat(providers/spark): add post_submit_commands to SparkSubmitHook for sidecar lifecycle management#64391

Merged
potiuk merged 1 commit into
apache:mainfrom
kalluripradeep:fix/spark-submit-post-submit-commands
Apr 6, 2026
Merged

feat(providers/spark): add post_submit_commands to SparkSubmitHook for sidecar lifecycle management#64391
potiuk merged 1 commit into
apache:mainfrom
kalluripradeep:fix/spark-submit-post-submit-commands

Conversation

@kalluripradeep

Copy link
Copy Markdown
Contributor

Summary

Closes #50958

When running Spark jobs on Kubernetes with a service mesh like Istio,
the sidecar proxy container does not automatically exit when the Spark
driver finishes. This leaves the pod in a running state indefinitely,
blocking job completion in Airflow.

This PR adds a post_submit_commands parameter to SparkSubmitHook
that runs a list of shell commands after the Spark job finishes —
whether it completes successfully or is killed via on_kill().

Example usage:

SparkSubmitHook(
    application="my_job.py",
    post_submit_commands=[
        "curl -sf -X POST http://localhost:15020/quitquitquit"
    ],
)

Changes

  • Added post_submit_commands: list[str] | None = None parameter to
    SparkSubmitHook.__init__()
  • Added _run_post_submit_commands() method that runs each command via
    subprocess.run(shell=True) with a 30s timeout, logging output and
    non-zero exit codes as warnings (never raises)
  • Called from both submit() (after job completion) and on_kill()
    (after process termination)
  • Added tests covering success, failure resilience, timeout, and
    backward compatibility

@Nataneljpwd Nataneljpwd left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I do not think it fixes the issue, we have fixed a similar issue differently, by adjusting the driver pod template and using k8s native sidecar containers

https://kubernetes.io/docs/concepts/workloads/pods/sidecar-containers/

Which is supported in the k8s version airflow requires ( > 1.30)

@kalluripradeep

Copy link
Copy Markdown
Contributor Author

The Integration: providers celery test failure appears to be an unrelated flaky test with the Celery/RabbitMQ Docker infrastructure. This PR only touches the Spark provider codebase (spark_submit.py) and has no overlap with Celery integration.

Could a maintainer please re-trigger the CI? Thanks!

I do not think it fixes the issue, we have fixed a similar issue differently, by adjusting the driver pod template and using k8s native sidecar containers

https://kubernetes.io/docs/concepts/workloads/pods/sidecar-containers/

Which is supported in the k8s version airflow requires ( > 1.30)

I agree that using native Kubernetes sidecars (K8s 1.28+) is the much better architectural solution here.

Unless you think this post_submit_commands parameter still has value for general worker-side teardown tasks (like local metric emission or temp file cleanup), I am happy to close this PR.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds a post_submit_commands capability to the Apache Spark provider’s SparkSubmitHook to support running cleanup commands (e.g., service-mesh sidecar shutdown) after a Spark submission completes or is terminated, plus unit tests for the new behavior.

Changes:

  • Add post_submit_commands parameter to SparkSubmitHook and persist it on the hook instance.
  • Implement _run_post_submit_commands() to execute configured commands after submit() and on_kill().
  • Add new unit tests covering command execution, resilience to failures/timeouts, and basic integration points.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 7 comments.

File Description
providers/apache/spark/src/airflow/providers/apache/spark/hooks/spark_submit.py Introduces post_submit_commands plumbing and executes post-submit shell commands from submit() and on_kill().
providers/apache/spark/tests/unit/apache/spark/hooks/test_spark_submit_post_commands.py Adds unit tests for post-submit command behavior and integration with submit() / on_kill().

Comment thread providers/apache/spark/src/airflow/providers/apache/spark/hooks/spark_submit.py Outdated
Comment thread providers/apache/spark/src/airflow/providers/apache/spark/hooks/spark_submit.py Outdated
@potiuk

potiuk commented Apr 4, 2026

Copy link
Copy Markdown
Member

Again - static checks fail .

@kalluripradeep kalluripradeep force-pushed the fix/spark-submit-post-submit-commands branch from 7ce0c62 to 49d54d6 Compare April 4, 2026 14:33
@kalluripradeep kalluripradeep force-pushed the fix/spark-submit-post-submit-commands branch from 49d54d6 to 03847ba Compare April 4, 2026 15:19
@kalluripradeep

Copy link
Copy Markdown
Contributor Author

Again - static checks fail .

fixed, all checks are passed now.

@potiuk potiuk merged commit b5dae4e into apache:main Apr 6, 2026
91 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cant add additional kill command to airflow.providers.apache.spark.hooks.spark_submit

4 participants