Repository navigation
Problem with pushing Xcom when using SparkKubernetesOperator #39184
Description
Apache Airflow version
Other Airflow 2 version (please specify below)
If "Other Airflow 2 version" selected, which one?
2.8.3
What happened?
I'm having an issue when using SparkKubernetesOperator to execute Spark job. Whenever i set do_xcom_push to True, the driver pod is created and run perfectly, but the xcom sidecar pod is nowhere to be found. Airflow log is thus stuck with this message:
[2024-04-23, 02:47:38 UTC] {custom_object_launcher.py:301} WARNING - Spark job submitted but not yet started. job_id: spark-custome-task-5r3pt2vk
[2024-04-23, 02:47:48 UTC] {pod_manager.py:529} ERROR - container base whose logs were requested not found in the pod spark-custome-task-5r3pt2vk-driver
[2024-04-23, 02:47:48 UTC] {pod_manager.py:718} INFO - Checking if xcom sidecar container is started.
[2024-04-23, 02:47:48 UTC] {pod_manager.py:724} WARNING - The xcom sidecar container is not yet started.
[2024-04-23, 02:51:24 UTC] {local_task_job_runner.py:296} WARNING - DagRun timed out after 0:05:03.242442.
[2024-04-23, 02:51:29 UTC] {local_task_job_runner.py:296} WARNING - DagRun timed out after 0:05:08.319418.
[2024-04-23, 02:51:29 UTC] {local_task_job_runner.py:302} WARNING - State of this instance has been externally set to skipped. Terminating instance.
[2024-04-23, 02:51:29 UTC] {process_utils.py:131} INFO - Sending 15 to group 30. PIDs of all processes in the group: [30]
[2024-04-23, 02:51:29 UTC] {process_utils.py:86} INFO - Sending the signal 15 to group 30
[2024-04-23, 02:51:29 UTC] {taskinstance.py:2483} ERROR - Received SIGTERM. Terminating subprocesses.
[2024-04-23, 02:51:29 UTC] {process_utils.py:79} INFO - Process psutil.Process(pid=30, status='terminated', exitcode=0, started='02:46:43') (30) terminated with exit code 0
In my opinion, there should be something wrong with xcom push for this operator. Any help would be much appreciated. Thanks in advance.
What you think should happen instead?
xcom pushed perfectly with any case of spark, maybe there will be placeholder for spark job with no return value or whatsoever
How to reproduce
submit a basic spark application by using SparkKubernetesOperator to K8s cluster and set do_xcom_push to True
Operating System
Ubuntu 22.04.4 LTS
Versions of Apache Airflow Providers
apache-airflow-providers-cncf-kubernetes==8.0.1
Deployment
Official Apache Airflow Helm Chart
Deployment details
No response
Anything else?
No response
Are you willing to submit PR?
- Yes I am willing to submit a PR!
Code of Conduct
- I agree to follow this project's Code of Conduct
Activity
boring-cyborg commentedon Apr 23, 2024
Thanks for opening your first issue here! Be sure to follow the issue template! If you are willing to raise PR to address this issue please do so, no need to wait for approval.
truonglac2603 commentedon Apr 24, 2024
Here's logs when i run a DBT project with KubernetesPodOperator.
Seems like it handle empty Xcom like a charm. Should SparkKubernetesOperator work the same as this one?
jojovem commentedon May 28, 2024
Im having the same issue as @truonglac2603
The task in airflow runs forever and i also get:
Airflow: 2.9.1
Python: 3.11
apache-airflow-providers-cncf-kubernetes: 8.2.0
The job is also running ok, but airflow doesnt recognize its end and it keeps executing even after SparkApplication is in the COMPLETED state.
This is my template:
bangnh1 commentedon Jun 6, 2024
I'm having the same issue. Is there any way to solve the issue?
gustavo-maxmilhas commentedon Jun 6, 2024
@bangnh1 Im my case, i downgraded the apache-airflow-providers-cncf-kubernetes to 7.13.0 to make it work
I didnt test with 8.3.0 yet
bangnh1 commentedon Jun 7, 2024
Thanks @gustavo-maxmilhas. I also need KubernetesJobOperator, so it seems more difficult to me.
realvz commentedon Jun 22, 2024
I have the same problem on 2.9.2. The driver pod completes but the worker pod keeps running. Disabling xcom push gets rid of this problem.
creyer commentedon Jun 27, 2024
If you need to use xcom push, just make the init container yourself in the spark operator template (based on https://github.com/apache/airflow/blob/main/airflow/providers/cncf/kubernetes/utils/xcom_sidecar.py)
bangnh1 commentedon Jul 1, 2024
It works like a charm. Thank you.
danielvvoros commentedon Oct 27, 2024
This worked perfectly for me too, thanks!
qRoC commentedon Nov 13, 2024
@creyer thanks!
JoelTheRed commentedon Jan 2, 2025
Is there any update on this issue? Ideally Airflow can inject the sidecar as it did in previous versions.
potiuk commentedon Jan 2, 2025
Generally - like any other issue - this one waits for someone to pick it up and fix it. If you would like to take on that task - feel free to attempt it, other than that it has to wait for someone to pick it up. That's how it works in open-source.
aichemzee commentedon Jan 14, 2025
@creyer I tried this however it still stays stuck for xcom push, do we have to enable something else in the spark operator for this to work? Did you add this in initContainers section or sidecars like you have it above?
feat(app): add optional xcom mount to fix communication issue
feat: inject XCom sidecar in SparkKubernetesOperator when do_xcom_pus…
Harmonic2004 commentedon Oct 6, 2025
Let me ask — has anyone fixed this bug yet? Please give me some suggestions!!!
[2025-10-07, 04:52:23] WARNING - Still waiting for the xcom sidecar container to start. Elapsed time: 213 seconds.: source="airflow.providers.cncf.kubernetes.utils.pod_manager.PodManager"
[2025-10-07, 04:52:53] WARNING - Still waiting for the xcom sidecar container to start. Elapsed time: 243 seconds.: source="airflow.providers.cncf.kubernetes.utils.pod_manager.PodManager"
[2025-10-07, 04:53:24] WARNING - Still waiting for the xcom sidecar container to start. Elapsed time: 273 seconds.: source="airflow.providers.cncf.kubernetes.utils.pod_manager.PodManager"
[2025-10-07, 04:53:54] WARNING - Still waiting for the xcom sidecar container to start. Elapsed time: 304 seconds.: source="airflow.providers.cncf.kubernetes.utils.pod_manager.PodManager"
[2025-10-07, 04:54:25] WARNING - Still waiting for the xcom sidecar container to start. Elapsed time: 334 seconds.: source="airflow.providers.cncf.kubernetes.utils.pod_manager.PodManager"
[2025-10-07, 04:54:55] WARNING - Still waiting for the xcom sidecar container to start. Elapsed time: 365 seconds.: source="airflow.providers.cncf.kubernetes.utils.pod_manager.PodManager"
[2025-10-07, 04:55:25] WARNING - Still waiting for the xcom sidecar container to start. Elapsed time: 395 seconds.: source="airflow.providers.cncf.kubernetes.utils.pod_manager.PodManager"
[2025-10-07, 04:55:56] WARNING - Still waiting for the xcom sidecar container to start. Elapsed time: 425 seconds.: source="airflow.providers.cncf.kubernetes.utils.pod_manager.PodManager"
[2025-10-07, 04:56:26] WARNING - Still waiting for the xcom sidecar container to start. Elapsed time: 456 seconds.: source="airflow.providers.cncf.kubernetes.utils.pod_manager.PodManager"
[2025-10-07, 04:56:57] WARNING - Still waiting for the xcom sidecar container to start. Elapsed time: 486 seconds.: source="airflow.providers.cncf.kubernetes.utils.pod_manager.PodManager"
[2025-10-07, 04:57:27] WARNING - Still waiting for the xcom sidecar container to start. Elapsed time: 517 seconds.: source="airflow.providers.cncf.kubernetes.utils.pod_manager.PodManager"
[2025-10-07, 04:57:57] WARNING - Still waiting for the xcom sidecar container to start. Elapsed time: 547 seconds.: source="airflow.providers.cncf.kubernetes.utils.pod_manager.PodManager"
[2025-10-07, 04:58:28] WARNING - Still waiting for the xcom sidecar container to start. Elapsed time: 577 seconds.: source="airflow.providers.cncf.kubernetes.utils.pod_manager.PodManager"
[2025-10-07, 04:58:52] ERROR - Task failed with exception: source="task"
ApiException: (404)
Reason: Not Found
HTTP response headers: HTTPHeaderDict({'Audit-Id': '08877d94-8165-4c56-9aff-a072da4a2181', 'Cache-Control': 'no-cache, private', 'Content-Type': 'application/json', 'X-Kubernetes-Pf-Flowschema-Uid': '73dfb296-b639-4503-9515-eee152b82f27', 'X-Kubernetes-Pf-Prioritylevel-Uid': '809f8fcd-faea-4c8e-ac7f-8df7a3db4f3a', 'Date': 'Mon, 06 Oct 2025 21:58:52 GMT', 'Content-Length': '268'})
HTTP response body: {"kind":"Status","apiVersion":"v1","metadata":{},"status":"Failure","message":"pods "ingest-sonar-medium-20251006214600-scycwdvc-driver" not found","reason":"NotFound","details":{"name":"ingest-sonar-medium-20251006214600-scycwdvc-driver","kind":"pods"},"code":404}
File "/home/airflow/.local/lib/python3.12/site-packages/airflow/sdk/execution_time/task_runner.py", line 867 in run
File "/home/airflow/.local/lib/python3.12/site-packages/airflow/sdk/execution_time/task_runner.py", line 1159 in _execute_task
File "/home/airflow/.local/lib/python3.12/site-packages/airflow/sdk/bases/operator.py", line 397 in wrapper
File "/home/airflow/.local/lib/python3.12/site-packages/airflow/providers/cncf/kubernetes/operators/spark_kubernetes.py", line 310 in execute
File "/home/airflow/.local/lib/python3.12/site-packages/airflow/sdk/bases/operator.py", line 397 in wrapper
File "/home/airflow/.local/lib/python3.12/site-packages/airflow/providers/cncf/kubernetes/operators/pod.py", line 607 in execute
File "/home/airflow/.local/lib/python3.12/site-packages/airflow/providers/cncf/kubernetes/operators/pod.py", line 680 in execute_sync
File "/home/airflow/.local/lib/python3.12/site-packages/airflow/providers/cncf/kubernetes/utils/pod_manager.py", line 822 in await_xcom_sidecar_container_start
File "/home/airflow/.local/lib/python3.12/site-packages/airflow/providers/cncf/kubernetes/utils/pod_manager.py", line 720 in container_is_running
File "/home/airflow/.local/lib/python3.12/site-packages/tenacity/init.py", line 338 in wrapped_f
File "/home/airflow/.local/lib/python3.12/site-packages/tenacity/init.py", line 477 in call
File "/home/airflow/.local/lib/python3.12/site-packages/tenacity/init.py", line 378 in iter
File "/home/airflow/.local/lib/python3.12/site-packages/tenacity/init.py", line 420 in exc_check
File "/home/airflow/.local/lib/python3.12/site-packages/tenacity/init.py", line 187 in reraise
File "/usr/local/lib/python3.12/concurrent/futures/_base.py", line 449 in result
File "/usr/local/lib/python3.12/concurrent/futures/_base.py", line 401 in __get_result
File "/home/airflow/.local/lib/python3.12/site-packages/tenacity/init.py", line 480 in call
File "/home/airflow/.local/lib/python3.12/site-packages/airflow/providers/cncf/kubernetes/utils/pod_manager.py", line 808 in read_pod
File "/home/airflow/.local/lib/python3.12/site-packages/kubernetes/client/api/core_v1_api.py", line 23693 in read_namespaced_pod
File "/home/airflow/.local/lib/python3.12/site-packages/kubernetes/client/api/core_v1_api.py", line 23780 in read_namespaced_pod_with_http_info
File "/home/airflow/.local/lib/python3.12/site-packages/kubernetes/client/api_client.py", line 348 in call_api
File "/home/airflow/.local/lib/python3.12/site-packages/kubernetes/client/api_client.py", line 180 in __call_api
File "/home/airflow/.local/lib/python3.12/site-packages/kubernetes/client/api_client.py", line 373 in request
File "/home/airflow/.local/lib/python3.12/site-packages/kubernetes/client/rest.py", line 244 in GET
File "/home/airflow/.local/lib/python3.12/site-packages/kubernetes/client/rest.py", line 238 in request