Skip to content
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

added "name" and "hostname" to template_fields in KubernetesPodOperator #43601

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

eilon246810
Copy link
Contributor

@eilon246810 eilon246810 commented Nov 2, 2024

Hi,

This PR closes: #43480.
It's a small change, which involves adding the name and hostname to the template_fields in the KubernetesPodOperator.

I decided to use a different approach from the one suggested by the issue creator.
This was to avoid changing the class API by renaming self.name to self.pod_name.

What do you think?


Comment on lines 262 to +264
"kubernetes_conn_id",
"name",
"hostname",
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you please add tests that cover this change in test_pod.py?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added, thanks!

@eilon246810
Copy link
Contributor Author

I see I have some tests failing, setting PR to draft until I fix these.

@eilon246810 eilon246810 marked this pull request as draft November 12, 2024 19:23
@eilon246810
Copy link
Contributor Author

The tests seem to fail because some of them mock the name parameter, and then the validate_key function inside _set_name fails because it expects a string.

I need help here - what is the way to solve this in your opinion?

@@ -594,6 +596,8 @@ def extract_xcom(self, pod: k8s.V1Pod) -> dict[Any, Any] | None:

def execute(self, context: Context):
"""Based on the deferrable parameter runs the pod asynchronously or synchronously."""
context["task"].name = self._set_name(context["task"].name) # type: ignore[attr-defined]
Copy link
Contributor

Choose a reason for hiding this comment

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

you don't need to use the context here.
you can just use self.name like this

Suggested change
context["task"].name = self._set_name(context["task"].name) # type: ignore[attr-defined]
self.name = self._set_name(self.name)

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 provider related issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add KubernetesPodOperator's name in templated fields
5 participants