Skip to content

Comments

KubernetesPodOperator add container_resources as templated field#26982

Closed
alanatlemba wants to merge 0 commit intoapache:mainfrom
alanatlemba:main
Closed

KubernetesPodOperator add container_resources as templated field#26982
alanatlemba wants to merge 0 commit intoapache:mainfrom
alanatlemba:main

Conversation

@alanatlemba
Copy link
Contributor

@alanatlemba alanatlemba commented Oct 11, 2022

closes: #23529

This is my first PR for a mainstream large scale open source project, let alone Airflow.
Sorry in advance if I've done anything improper, and thanks for your patience.

Thank you @nitinmuteja & @lior1990 for doing much of the work. This is following up on this closed/abandoned PR: #23531

Here is how I tested:
breeze testing tests --test-type "Providers[cncf]"
breeze k8s run-complete-tests

I'm not sure if further testing is necessary. Should I bother making sure that I see a mapped k8s pod operator dag run with the expected resources? I may need some help working through that. :)


^ Add meaningful description above

Read the Pull Request Guidelines for more information.
In case of fundamental code changes, an 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 newsfragment file, named {pr_number}.significant.rst or {issue_number}.significant.rst, in newsfragments.


@boring-cyborg boring-cyborg bot added provider:cncf-kubernetes Kubernetes (k8s) provider related issues area:providers labels Oct 11, 2022
@boring-cyborg
Copy link

boring-cyborg bot commented Oct 11, 2022

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 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 Consider adding an example DAG that shows how users should use it.
  • Consider using Breeze environment 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 for all communication including (but not limited to) comments on Pull Requests, Mailing list and Slack.
  • Be sure to read the Airflow Coding style.
    Apache Airflow is a community-driven project and together we are making it better 🚀.
    In case of doubts contact the developers at:
    Mailing List: [email protected]
    Slack: https://s.apache.org/airflow-slack

@eladkal eladkal changed the title #23529 - Allow KubernetesPodOperator resources to be templated. KubernetesPodOperator add container_resources as templated field Oct 11, 2022
@alanatlemba
Copy link
Contributor Author

alanatlemba commented Oct 12, 2022

@eladkal thanks for triggering the run before. I'm unfamiliar with the failed. I don't think I touched anything around it, and that test is succeeding on my breeze tests. Could we please re-trigger it? thanks again.

@alanatlemba
Copy link
Contributor Author

perhaps I should just update the branch to re-trigger?

'config_file',
'pod_template_file',
'namespace',
'k8s_resources',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you mean container_resources?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eladkal I wasn't sure, so I went with the comment on the previous PR on this --

#23531 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm also perplexed as to why I'm getting failures on google auth credentials

Copy link
Contributor

@eladkal eladkal Oct 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this was right?

What users are doing is:

compute_resources=k8s.V1ResourceRequirements(
    requests={
        'memory': '512Mi',
        'cpu': '500m'
    },
    limits={
        'memory': '1Gi',
        'cpu': 500m
    }
)

KubernetesPodOperator(..., container_resources=compute_resources)

But what they want to do is instead of specifying hard coded values like 512Mi they want it to be templated so something like:

    requests={
        'memory': '{{ dag_run.conf["request_memory"] }} ',
        'cpu': '500m'
    }

note that the k8s_resources is not a field exposed to the users.
It is used mainly for backward compatibility where users used to pass resources in dict rather than V1ResourceRequirements:

resources: dict[str, Any] | None = None,

container_resources: k8s.V1ResourceRequirements | None = None,

if isinstance(resources, k8s.V1ResourceRequirements):
warnings.warn(
"Specifying resources for the launched pod with 'resources' is deprecated. "
"Use 'container_resources' instead.",
category=DeprecationWarning,
stacklevel=2,
)
container_resources = resources
resources = None

I think we are also about to remove this support for resources in the next release of the provider so the k8s_resources will no longer be needed? cc @jedcunningham @dstandish

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eladkal thanks for the detailed review. I will get to this later today!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Raised PR #27197

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @eladkal I will rebase and re-push this PR once that PR is merged.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#27197 is merged

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huzzah! @eladkal I'll rebase & re-push tomorrow. thx :)

@alanatlemba alanatlemba requested review from eladkal and removed request for jedcunningham October 13, 2022 14:13
@alanatlemba
Copy link
Contributor Author

@jedcunningham github removed you from the reviewer list when I added @eladkal . this was not intended, and it seems I cannot add you back :(

@o-nikolas
Copy link
Contributor

@jedcunningham github removed you from the reviewer list when I added @eladkal . this was not intended, and it seems I cannot add you back :(

I've added Jed back as a reviewer :)

@potiuk
Copy link
Member

potiuk commented Oct 26, 2022

conflicts need resolution.

@alanatlemba
Copy link
Contributor Author

@potiuk awaiting #27197 by @eladkal being merged/closed then I'll resolve the conflicts.

@alanatlemba
Copy link
Contributor Author

I didn't mean to close this - I just updated my fork. I'll just link to this when I create a new PR

@alanatlemba
Copy link
Contributor Author

#27457 raised after rebase. FYI @potiuk , @eladkal @jedcunningham

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:providers provider:cncf-kubernetes Kubernetes (k8s) provider related issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Provide resources attribute in KubernetesPodOperator to be templated

5 participants