-
Notifications
You must be signed in to change notification settings - Fork 16.4k
make resources for KubernetesPodTemplate templated #23531
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
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)
|
|
Added test for the change. |
|
Cool. Running tests and hopefully will include it in the next provider's release. |
|
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. |
|
Do we mean to something like? |
|
@eladkal yes. This is the expected behaviour. |
|
I tried locally with kind-cluster and the templating didn't take. @nitinmuteja can you supply a usage example for it? |
|
@nitinmuteja It would be great if you can add a test that verify the templating similar to: airflow/tests/providers/google/cloud/operators/test_cloud_storage_transfer_service.py Lines 870 to 887 in a3c9956
|
|
@nitinmuteja -> last call before preparing newr round of providers - do you have time/capability to add the test as @eladkal asked? |
|
I can add today. |
|
Cool. I can hold on then :) |
|
@talnagar I have added test cases for the requirements. |
|
@potiuk please check the changes. Created a subclass from the k8s class and added class attributes to make limits and requests as template attributes. |
jedcunningham
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
)
I agree |
|
Agree - this one will wait move to next round of providers. |
@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 one does not work as the external V1ResourceRequirements does not have template_fields class attribute. I can only think of Inheritance as a stable solution for this. Let me know if you folks can think of another solution. |
|
Suggestion: you can modify |
|
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 Instead of resources, k8s_resources should be added to template_fields. |
|
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. |
closes: #23529
^ Add meaningful description above
Read the Pull Request Guidelines for more information.
In case of fundamental code change, Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in a newsfragement file, named
{pr_number}.significant.rst, in newsfragments.