amoghrajesh commented on code in PR #46860:
URL: https://github.com/apache/airflow/pull/46860#discussion_r1961806752
##########
providers/cncf/kubernetes/src/airflow/providers/cncf/kubernetes/pod_generator.py:
##########
@@ -341,18 +350,45 @@ def construct_pod(
run_id=run_id,
),
),
- spec=k8s.V1PodSpec(
- containers=[
- k8s.V1Container(
- name="base",
- args=args,
- image=image,
- env=[k8s.V1EnvVar(name="AIRFLOW_IS_K8S_EXECUTOR_POD",
value="True")],
- )
- ]
- ),
)
+ podspec = k8s.V1PodSpec(
+ containers=[main_container],
+ )
+
+ if content_json_for_volume:
+ input_file_path = "/tmp/execute/input.json"
+ execute_volume = V1Volume(
+ name="execute-volume",
+ empty_dir=V1EmptyDirVolumeSource(),
+ )
+
+ execute_volume_mount = V1VolumeMount(
+ name="execute-volume",
+ mount_path="/tmp/execute",
+ read_only=False,
+ )
+
+ init_container = k8s.V1Container(
+ name="init-container",
+ image="busybox",
+ command=["/bin/sh", "-c", f"echo '{content_json_for_volume}' >
{input_file_path}"],
+ volume_mounts=[execute_volume_mount],
+ )
Review Comment:
Thanks, yeah i just tried and handled it using shlex in the last commit,
seems to work fine:
```
airflow@sleep-dag-sleep-10-minutes-b94kc3cj:/tmp/execute$ cat input.json
{"token":"","ti":{"id":"01951ea1-251c-7140-a358-dd6f1c9c07fb","task_id":"sleep_10_minutes","dag_id":"sleep_dag","run_id":"manual__2025-02-19T14:33:52.129551+00:00_9R99UOPR","try_number":1,"map_index":-1,"pool_slots":1,"queue":"default","priority_weight":1},"dag_rel_path":"sleep_dag.py","bundle_info":{"name":"dags-folder","version":null},"log_path":"dag_id=sleep_dag/run_id=manual__2025-02-19T14:33:52.129551+00:00_9R99UOPR/task_id=sleep_10_minutes/attempt=.log","kind":"ExecuteTask"}
airflow@sleep-dag-sleep-10-minutes-b94kc3cj:/tmp/execute$
airflow@sleep-dag-sleep-10-minutes-b94kc3cj:/tmp/execute$
airflow@sleep-dag-sleep-10-minutes-b94kc3cj:/tmp/execute$
airflow@sleep-dag-sleep-10-minutes-b94kc3cj:/tmp/execute$
airflow@sleep-dag-sleep-10-minutes-b94kc3cj:/tmp/execute$ python
Python 3.9.21 (main, Feb 4 2025, 14:21:23)
[GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> with open("with open("/tmp/execute/input.json") as file:
KeyboardInterrupt
>>> with open("/tmp/execute/input.json") as file:
... input_data = file.read()
...
>>> input
<built-in function input>
>>> input_data
'{"token":"","ti":{"id":"01951ea1-251c-7140-a358-dd6f1c9c07fb","task_id":"sleep_10_minutes","dag_id":"sleep_dag","run_id":"manual__2025-02-19T14:33:52.129551+00:00_9R99UOPR","try_number":1,"map_index":-1,"pool_slots":1,"queue":"default","priority_weight":1},"dag_rel_path":"sleep_dag.py","bundle_info":{"name":"dags-folder","version":null},"log_path":"dag_id=sleep_dag/run_id=manual__2025-02-19T14:33:52.129551+00:00_9R99UOPR/task_id=sleep_10_minutes/attempt=.log","kind":"ExecuteTask"}\n'
>>> exit()
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]