You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2022/05/18 18:46:45 UTC

[GitHub] [airflow] kevin-woodward opened a new issue, #23783: Partial of a KubernetesPodOperator does not allow for limit_cpu and limit_memory in the resources argument

kevin-woodward opened a new issue, #23783:
URL: https://github.com/apache/airflow/issues/23783

   ### Apache Airflow version
   
   2.3.0 (latest released)
   
   ### What happened
   
   When performing dynamic task mapping and providing Kubernetes limits to the `resources` argument, the DAG raises an import error: 
   
   ```
   Broken DAG: [/opt/airflow/dags/bulk_image_processing.py] Traceback (most recent call last):
     File "/home/airflow/.local/lib/python3.7/site-packages/airflow/models/baseoperator.py", line 287, in partial
       partial_kwargs["resources"] = coerce_resources(partial_kwargs["resources"])
     File "/home/airflow/.local/lib/python3.7/site-packages/airflow/models/baseoperator.py", line 133, in coerce_resources
       return Resources(**resources)
   TypeError: __init__() got an unexpected keyword argument 'limit_cpu'
   ```
   
   The offending code is:
   
   ```
   KubernetesPodOperator.partial(
               get_logs: True,
               in_cluster: True,
               is_delete_operator_pod: True,
               namespace: settings.namespace,
               resources={'limit_cpu': settings.IMAGE_PROCESSING_OPERATOR_CPU, 'limit_memory': settings.IMAGE_PROCESSING_OPERATOR_MEMORY},
               service_account_name: settings.SERVICE_ACCOUNT_NAME,
               startup_timeout_seconds: 600,
               **kwargs,
       )```
   
   But you can see this in any DAG utilizing a `KubernetesPodOperator.partial` where the `partial` contains the `resources` argument.
   
   
   
   ### What you think should happen instead
   
   The `resources` argument should be taken at face value and applied to the `MappedOperator`.
   
   ### How to reproduce
   
   Try to import this DAG using Airflow 2.3.0:
   
   ```
   from datetime import datetime
   from airflow import XComArg
   from airflow.models import DAG
   from airflow.providers.cncf.kubernetes.operators.kubernetes_pod import KubernetesPodOperator
   
   
   def make_operator(
       **kwargs
   ):
       return KubernetesPodOperator(
           **{
               'get_logs': True,
               'in_cluster': True,
               'is_delete_operator_pod': True,
               'namespace': 'default',
               'startup_timeout_seconds': 600,
               **kwargs,
           }
       )
   
   
   def make_partial_operator(
       **kwargs
   ):
       return KubernetesPodOperator.partial(
           **{
               'get_logs': True,
               'in_cluster': True,
               'is_delete_operator_pod': True,
               'namespace': 'default',
               'startup_timeout_seconds': 600,
               **kwargs,
           }
       )
   
   
   with DAG(dag_id='bulk_image_processing',
            schedule_interval=None,
            start_date=datetime(2020, 1, 1),
            max_active_tasks=20) as dag:
   
       op1 = make_operator(
           arguments=['--bucket-name', f'{{{{ dag_run.conf.get("bucket", "some-fake-default") }}}}'],
           cmds=['python3', 'get_experiment_keys'],
           image='some-image',
           name='airflow-private-image-pod-1',
           task_id='some-task',
           do_xcom_push=True
       )
   
       op2 = make_partial_operator(
           image='another-image',
           name=f'airflow-private-image-pod-2',
           resources={'limit_cpu': '2000m', 'limit_memory': '16Gi'},
           task_id='another-task',
           cmds=[
               'some',
               'set',
               'of',
               'cmds'
           ]
       ).expand(arguments=XComArg(op1))
   
   ```
   
   ### Operating System
   
   MacOS 11.6.5
   
   ### Versions of Apache Airflow Providers
   
   Relevant:
   ```
   apache-airflow-providers-cncf-kubernetes==4.0.1
   ```
   
   Full:
   ```
   apache-airflow-providers-amazon==3.3.0
   apache-airflow-providers-celery==2.1.4
   apache-airflow-providers-cncf-kubernetes==4.0.1
   apache-airflow-providers-docker==2.6.0
   apache-airflow-providers-elasticsearch==3.0.3
   apache-airflow-providers-ftp==2.1.2
   apache-airflow-providers-google==6.8.0
   apache-airflow-providers-grpc==2.0.4
   apache-airflow-providers-hashicorp==2.2.0
   apache-airflow-providers-http==2.1.2
   apache-airflow-providers-imap==2.2.3
   apache-airflow-providers-microsoft-azure==3.8.0
   apache-airflow-providers-mysql==2.2.3
   apache-airflow-providers-odbc==2.0.4
   apache-airflow-providers-postgres==4.1.0
   apache-airflow-providers-redis==2.0.4
   apache-airflow-providers-sendgrid==2.0.4
   apache-airflow-providers-sftp==2.6.0
   apache-airflow-providers-slack==4.2.3
   apache-airflow-providers-sqlite==2.1.3
   apache-airflow-providers-ssh==2.4.3
   ```
   
   ### Deployment
   
   Official Apache Airflow Helm Chart
   
   ### Deployment details
   
   Docker (Docker Desktop)
   - Server Version: 20.10.13
   - API Version: 1.41
   - Builder: 2
   
   Kubernetes (Docker Desktop)
   - Env: docker-desktop
   - Context: docker-desktop
   - Cluster Name: docker-desktop
   - Namespace: default
   - Container Runtime: docker
   - Version: v1.22.5
   
   Helm:
   - version.BuildInfo{Version:"v3.6.3", GitCommit:"d506314abfb5d21419df8c7e7e68012379db2354", GitTreeState:"dirty", GoVersion:"go1.16.5"}
   
   ### Anything else
   
   _No response_
   
   ### Are you willing to submit PR?
   
   - [ ] 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: commits-unsubscribe@airflow.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [airflow] uranusjr closed issue #23783: Partial of a KubernetesPodOperator does not allow for limit_cpu and limit_memory in the resources argument

Posted by GitBox <gi...@apache.org>.
uranusjr closed issue #23783: Partial of a KubernetesPodOperator does not allow for limit_cpu and limit_memory in the resources argument
URL: https://github.com/apache/airflow/issues/23783


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [airflow] boring-cyborg[bot] commented on issue #23783: Partial of a KubernetesPodOperator does not allow for limit_cpu and limit_memory in the resources argument

Posted by GitBox <gi...@apache.org>.
boring-cyborg[bot] commented on issue #23783:
URL: https://github.com/apache/airflow/issues/23783#issuecomment-1130383864

   Thanks for opening your first issue here! Be sure to follow the issue template!
   


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [airflow] eladkal commented on issue #23783: Partial of a KubernetesPodOperator does not allow for limit_cpu and limit_memory in the resources argument

Posted by GitBox <gi...@apache.org>.
eladkal commented on issue #23783:
URL: https://github.com/apache/airflow/issues/23783#issuecomment-1130491084

   But `resources` is not dict it's `V1ResourceRequirements` object
   
   https://github.com/apache/airflow/blob/dbdcd0fd1de102f5edf77b9ef2a485860b05001b/airflow/providers/cncf/kubernetes/operators/kubernetes_pod.py#L181
   


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [airflow] uranusjr commented on issue #23783: Partial of a KubernetesPodOperator does not allow for limit_cpu and limit_memory in the resources argument

Posted by GitBox <gi...@apache.org>.
uranusjr commented on issue #23783:
URL: https://github.com/apache/airflow/issues/23783#issuecomment-1130726030

   Hmm, technically `KubernetesPodOperator` is breaking the Liskov substitution principle here, therefore does not respond well to base class changes. It is possible we could fix this without changing the operator, but ideally we should rename `resources` to something else so the operator’s implementation can become theoratically sound.


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org