AbigailColwell opened a new issue, #47738:
URL: https://github.com/apache/airflow/issues/47738

   ### Apache Airflow Provider(s)
   
   cncf-kubernetes
   
   ### Versions of Apache Airflow Providers
   
   `apache-airflow-providers-cncf-kubernetes==10.3.0`
   
   ### Apache Airflow version
   
   `apache-airflow==2.10.5`
   
   ### Operating System
   
   macOs Sequioa 15.3.1
   
   ### Deployment
   
   Virtualenv installation
   
   ### Deployment details
   
   1. Create virtual environment with uv
     - `uv venv --python 3.12`
     - `source .venv/bin/activate`
     - `uv pip install apache-airflow-providers-cncf-kubernetes`
   
   
   ### What happened
   
   ```log
   Traceback (most recent call last):
     File "/Users/acolwell/Code/airflow-dags/dynamic_volume_dag.py", line 51, 
in <module>
       example_k8s_volume_template_error_dag = 
example_k8s_volume_template_error()
                                               
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     File 
"/Users/acolwell/Code/airflow-dags/.venv/lib/python3.12/site-packages/airflow/models/dag.py",
 line 4307, in factory
       f(**f_kwargs)
     File "/Users/acolwell/Code/airflow-dags/dynamic_volume_dag.py", line 42, 
in example_k8s_volume_template_error
       run_pod = KubernetesPodOperator(
                 ^^^^^^^^^^^^^^^^^^^^^^
     File 
"/Users/acolwell/Code/airflow-dags/.venv/lib/python3.12/site-packages/airflow/models/baseoperator.py",
 line 506, in apply_defaults
       result = func(self, **kwargs, default_args=default_args)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     File 
"/Users/acolwell/Code/airflow-dags/.venv/lib/python3.12/site-packages/airflow/providers/cncf/kubernetes/operators/pod.py",
 line 347, in __init__
       volume_mounts = [convert_volume_mount(v) for v in volume_mounts] if 
volume_mounts else []
                                                         ^^^^^^^^^^^^^
     File 
"/Users/acolwell/Code/airflow-dags/.venv/lib/python3.12/site-packages/airflow/models/xcom_arg.py",
 line 329, in __iter__
       raise TypeError("'XComArg' object is not iterable")
   TypeError: 'XComArg' object is not iterable
   ```
   
   ### What you think should happen instead
   
   The DAG should parse without issue and should properly set up the volumes 
and mounts when run
   
   ### How to reproduce
   
   1. Set up virtual environment as described above
   2. Create a dag `dynanic_volume_dag.py`
   ```python
   """
   Example DAG showing error when using KubernetesPodOperator trying to 
template a volume_mount or volume
   """
   
   from datetime import datetime
   from airflow.decorators import dag, task
   from airflow.providers.cncf.kubernetes.operators.pod import 
KubernetesPodOperator
   
   
   @dag(
       schedule=None,
       start_date=datetime(2023, 8, 28),
       catchup=False,
   )
   def example_k8s_volume_template_error():
       """
       Example DAG showing error when using KubernetesPodOperator trying to 
template a volume_mount or volume
       """
   
       @task(multiple_outputs=True)
       def generate_mount_config():
           """Generate the volume_mounts and volumes configuration. Assume this 
is a complex function that generates the configuration"""
           return {
               "volume_mounts": [
                   {
                       "name": "example-volume",
                       "mountPath": "/example",
                   }
               ],
               "volumes": [
                   {
                       "name": "example-volume",
                       "persistent_volume_claim": {
                           "claim_name": "example-claim",
                       },
                   }
               ],
           }
   
       mount_config = generate_mount_config()
   
       run_pod = KubernetesPodOperator(
           task_id="run_pod",
           image="alpine",
           cmds=["sh", "-c", "ls /example"],
           volume_mounts=mount_config["volume_mounts"],
           volumes=mount_config["volumes"],
       )
   
   
   example_k8s_volume_template_error_dag = example_k8s_volume_template_error()
   ```
   3. Run the dag
   ```shell
   python dynamic_volume_dag.py
   ```
   
   ### Anything else
   
   I believe we should just be able to move the calls to `convert_volume_mount` 
and `convert_volumes` into the `build_pod_request_obj` method, similar to how 
`env_vars` is handled
   
   ### Are you willing to submit PR?
   
   - [x] Yes I am willing to submit a PR!
   
   ### Code of Conduct
   
   - [x] I agree to follow this project's [Code of 
Conduct](https://github.com/apache/airflow/blob/main/CODE_OF_CONDUCT.md)
   


-- 
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]

Reply via email to