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/06 13:50:50 UTC
[GitHub] [airflow] nitinmuteja opened a new pull request, #23531: make resources for KubernetesPodTemplate templated
nitinmuteja opened a new pull request, #23531:
URL: https://github.com/apache/airflow/pull/23531
<!--
Thank you for contributing! Please make sure that your code changes
are covered with tests. And in case of new features or big changes
remember to adjust the documentation.
Feel free to ping committers for the review!
In case of existing issue, reference it using one of the following:
closes: #23529
How to write a good git commit message:
http://chris.beams.io/posts/git-commit/
-->
---
**^ Add meaningful description above**
Read the **[Pull Request Guidelines](https://github.com/apache/airflow/blob/main/CONTRIBUTING.rst#pull-request-guidelines)** for more information.
In case of fundamental code change, Airflow Improvement Proposal ([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvements+Proposals)) is needed.
In case of a new dependency, check compliance with the [ASF 3rd Party License Policy](https://www.apache.org/legal/resolved.html#category-x).
In case of backwards incompatible changes please leave a note in a newsfragement file, named `{pr_number}.significant.rst`, in [newsfragments](https://github.com/apache/airflow/tree/main/newsfragments).
--
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 pull request #23531: make resources for KubernetesPodTemplate templated
Posted by GitBox <gi...@apache.org>.
eladkal commented on PR #23531:
URL: https://github.com/apache/airflow/pull/23531#issuecomment-1123854304
> I'm not really on board with having our own `V1ResourceRequirements` - we intentionally moved away from this pattern for a reason.
I agree
--
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] lior1990 commented on pull request #23531: make resources for KubernetesPodTemplate templated
Posted by GitBox <gi...@apache.org>.
lior1990 commented on PR #23531:
URL: https://github.com/apache/airflow/pull/23531#issuecomment-1126878905
Suggestion: you can modify `_render_nested_template_fields` in `KubernetesPodOperator` and add the following code, right after the custom code that is handling `k8s.V1EnvVar`:
```
if id(content) not in seen_oids and isinstance(content, k8s.V1ResourceRequirements):
seen_oids.add(id(content))
self._do_render_template_fields(content, ("limits", "requests"), context, jinja_env, seen_oids)
return
````
--
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] talnagar commented on pull request #23531: make resources for KubernetesPodTemplate templated
Posted by GitBox <gi...@apache.org>.
talnagar commented on PR #23531:
URL: https://github.com/apache/airflow/pull/23531#issuecomment-1122283560
I tried locally with kind-cluster and the templating didn't take. @nitinmuteja can you supply a usage example for it?
this is what I tried using the example_kubernetes_executor.py from the example_dags in the repo:
```
....
with DAG(
dag_id='example_kubernetes_executor',
schedule_interval=None,
start_date=pendulum.datetime(2021, 1, 1, tz="UTC"),
catchup=False,
tags=['example3'],
params={
'mem': Param(default='512Mi',type='string', description="memory"),
}
....
# Use k8s_client.V1ResourceRequirements to define resource limits
k8s_resource_requirements = k8s.V1ResourceRequirements(
requests={'memory': "{{ params['mem'] }}"}, limits={'memory': '512Mi'}
)
```
--
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 pull request #23531: make resources for KubernetesPodTemplate templated
Posted by GitBox <gi...@apache.org>.
eladkal commented on PR #23531:
URL: https://github.com/apache/airflow/pull/23531#issuecomment-1121584193
How can we template resources? Its not a string. Its a list object of V1ResourceRequirements.
Maybe im missing something here but I would love to see an actual test that template this field.
--
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 pull request #23531: make resources for KubernetesPodTemplate templated
Posted by GitBox <gi...@apache.org>.
boring-cyborg[bot] commented on PR #23531:
URL: https://github.com/apache/airflow/pull/23531#issuecomment-1119645366
Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contribution Guide (https://github.com/apache/airflow/blob/main/CONTRIBUTING.rst)
Here are some useful points:
- Pay attention to the quality of your code (flake8, mypy and type annotations). Our [pre-commits]( https://github.com/apache/airflow/blob/main/STATIC_CODE_CHECKS.rst#prerequisites-for-pre-commit-hooks) will help you with that.
- In case of a new feature add useful documentation (in docstrings or in `docs/` directory). Adding a new operator? Check this short [guide](https://github.com/apache/airflow/blob/main/docs/apache-airflow/howto/custom-operator.rst) Consider adding an example DAG that shows how users should use it.
- Consider using [Breeze environment](https://github.com/apache/airflow/blob/main/BREEZE.rst) for testing locally, itโs a heavy docker but it ships with a working Airflow and a lot of integrations.
- Be patient and persistent. It might take some time to get a review or get the final approval from Committers.
- Please follow [ASF Code of Conduct](https://www.apache.org/foundation/policies/conduct) for all communication including (but not limited to) comments on Pull Requests, Mailing list and Slack.
- Be sure to read the [Airflow Coding style]( https://github.com/apache/airflow/blob/main/CONTRIBUTING.rst#coding-style-and-best-practices).
Apache Airflow is a community-driven project and together we are making it better ๐.
In case of doubts contact the developers at:
Mailing List: dev@airflow.apache.org
Slack: https://s.apache.org/airflow-slack
--
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] nitinmuteja commented on pull request #23531: make resources for KubernetesPodTemplate templated
Posted by GitBox <gi...@apache.org>.
nitinmuteja commented on PR #23531:
URL: https://github.com/apache/airflow/pull/23531#issuecomment-1123260546
I can add today.
--
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] potiuk commented on pull request #23531: make resources for KubernetesPodTemplate templated
Posted by GitBox <gi...@apache.org>.
potiuk commented on PR #23531:
URL: https://github.com/apache/airflow/pull/23531#issuecomment-1124208195
Agree - this one will wait move to next round of providers.
--
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] nitinmuteja commented on pull request #23531: make resources for KubernetesPodTemplate templated
Posted by GitBox <gi...@apache.org>.
nitinmuteja commented on PR #23531:
URL: https://github.com/apache/airflow/pull/23531#issuecomment-1124542216
> > I'm not really on board with having our own `V1ResourceRequirements` - we intentionally moved away from this pattern for a reason.
@jedcunningham we are just inheriting the object and will continue using the object. The only advantage it provides us with is that the props can be templated.
--
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] akakakakakaa commented on pull request #23531: make resources for KubernetesPodTemplate templated
Posted by GitBox <gi...@apache.org>.
akakakakakaa commented on PR #23531:
URL: https://github.com/apache/airflow/pull/23531#issuecomment-1134181785
In addition to previously mentioned by @lior1990,
```
class CustomKubernetesPodOperator(KubernetesPodOperator):
template_fields: Sequence[str] = KubernetesPodOperator.template_fields + ('k8s_resources', )
def _render_nested_template_fields(
self,
content: Any,
context: 'Context',
jinja_env: "jinja2.Environment",
seen_oids: set,
) -> None:
if id(content) not in seen_oids and isinstance(content, k8s.V1ResourceRequirements):
seen_oids.add(id(content))
self._do_render_template_fields(content, ("limits", "requests"), context, jinja_env, seen_oids)
return
super()._render_nested_template_fields(content, context, jinja_env, seen_oids)
```
In KubernetesPodOperator, resources allocated to k8s_resources
```
self.k8s_resources = convert_resources(resources) if resources else {}
````
Instead of resource, k8s_resource should be added to template_fields.
--
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] nitinmuteja commented on pull request #23531: make resources for KubernetesPodTemplate templated
Posted by GitBox <gi...@apache.org>.
nitinmuteja commented on PR #23531:
URL: https://github.com/apache/airflow/pull/23531#issuecomment-1120697440
Added test for the change.
--
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] potiuk commented on pull request #23531: make resources for KubernetesPodTemplate templated
Posted by GitBox <gi...@apache.org>.
potiuk commented on PR #23531:
URL: https://github.com/apache/airflow/pull/23531#issuecomment-1121486322
Cool. Running tests and hopefully will include it in the next provider's release.
--
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] nitinmuteja commented on pull request #23531: make resources for KubernetesPodTemplate templated
Posted by GitBox <gi...@apache.org>.
nitinmuteja commented on PR #23531:
URL: https://github.com/apache/airflow/pull/23531#issuecomment-1123681295
@potiuk please check the changes. Created a subclass from the k8s class and added class attributes to make limits and requests as template attributes.
--
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] nitinmuteja commented on pull request #23531: make resources for KubernetesPodTemplate templated
Posted by GitBox <gi...@apache.org>.
nitinmuteja commented on PR #23531:
URL: https://github.com/apache/airflow/pull/23531#issuecomment-1124543118
> I'm not really on board with having our own `V1ResourceRequirements` - we intentionally moved away from this pattern for a reason.
>
> I haven't tried it, but would this pattern work instead (making this a documentation issue)?
>
> ```
> resources = k8s.V1ResourceRequirements(requests={'memory': '100Mi'})
> resources.template_fields = ('requests')
>
> KPO(
> ...,
> resources=resources
> )
> ```
This one does not work as the external V1ResourceRequirements does not have template_fields class attribute.
--
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] github-actions[bot] closed pull request #23531: make resources for KubernetesPodTemplate templated
Posted by GitBox <gi...@apache.org>.
github-actions[bot] closed pull request #23531: make resources for KubernetesPodTemplate templated
URL: https://github.com/apache/airflow/pull/23531
--
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 pull request #23531: make resources for KubernetesPodTemplate templated
Posted by GitBox <gi...@apache.org>.
eladkal commented on PR #23531:
URL: https://github.com/apache/airflow/pull/23531#issuecomment-1121587702
Do we mean to something like?
```
V1ResourceRequirements(
requests={"cpu": "{{ dag_run.conf[\'request_cpu\'] }}", "memory": "8G"},
limits={"cpu": "16000m", "memory": "128G"},
)
```
--
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] nitinmuteja commented on pull request #23531: make resources for KubernetesPodTemplate templated
Posted by GitBox <gi...@apache.org>.
nitinmuteja commented on PR #23531:
URL: https://github.com/apache/airflow/pull/23531#issuecomment-1122197800
@eladkal yes. This is the expected behaviour.
--
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] nitinmuteja commented on pull request #23531: make resources for KubernetesPodTemplate templated
Posted by GitBox <gi...@apache.org>.
nitinmuteja commented on PR #23531:
URL: https://github.com/apache/airflow/pull/23531#issuecomment-1123678882
@talnagar I have added test cases for the requirements.
--
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] akakakakakaa commented on pull request #23531: make resources for KubernetesPodTemplate templated
Posted by GitBox <gi...@apache.org>.
akakakakakaa commented on PR #23531:
URL: https://github.com/apache/airflow/pull/23531#issuecomment-1134177937
```
--
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] github-actions[bot] commented on pull request #23531: make resources for KubernetesPodTemplate templated
Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on PR #23531:
URL: https://github.com/apache/airflow/pull/23531#issuecomment-1194803223
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 5 days if no further activity occurs. Thank you for your contributions.
--
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 pull request #23531: make resources for KubernetesPodTemplate templated
Posted by GitBox <gi...@apache.org>.
eladkal commented on PR #23531:
URL: https://github.com/apache/airflow/pull/23531#issuecomment-1122292005
@nitinmuteja It would be great if you can add a test that verify the templating similar to:
https://github.com/apache/airflow/blob/a3c9956f79310b529a79c1e43fb881c5e173d321/tests/providers/google/cloud/operators/test_cloud_storage_transfer_service.py#L870-L887
--
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] potiuk commented on pull request #23531: make resources for KubernetesPodTemplate templated
Posted by GitBox <gi...@apache.org>.
potiuk commented on PR #23531:
URL: https://github.com/apache/airflow/pull/23531#issuecomment-1122615378
@nitinmuteja -> last call before preparing newr round of providers - do you have time/capability to add the test as @eladkal asked?
--
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] potiuk commented on pull request #23531: make resources for KubernetesPodTemplate templated
Posted by GitBox <gi...@apache.org>.
potiuk commented on PR #23531:
URL: https://github.com/apache/airflow/pull/23531#issuecomment-1123472712
Cool. I can hold on then :)
--
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