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

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,8 @@ class KubernetesPodOperator(BaseOperator):
"env_from",
"node_selector",
"kubernetes_conn_id",
"name",
"hostname",
Comment on lines 262 to +264
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!

)
template_fields_renderers = {"env_vars": "py"}

Expand Down Expand Up @@ -388,7 +390,7 @@ def __init__(
self.priority_class_name = priority_class_name
self.pod_template_file = pod_template_file
self.pod_template_dict = pod_template_dict
self.name = self._set_name(name)
self.name = name
self.random_name_suffix = random_name_suffix
self.termination_grace_period = termination_grace_period
self.pod_request_obj: k8s.V1Pod | None = None
Expand Down Expand Up @@ -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."""
self.name = self._set_name(self.name)

if not self.deferrable:
return self.execute_sync(context)

Expand Down
4 changes: 4 additions & 0 deletions providers/tests/cncf/kubernetes/operators/test_pod.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ def test_templates(self, create_task_instance_of_operator, session):
session=session,
dag_id=dag_id,
task_id="task-id",
name="{{ dag.dag_id }}",
hostname="{{ dag.dag_id }}",
namespace="{{ dag.dag_id }}",
container_resources=k8s.V1ResourceRequirements(
requests={"memory": "{{ dag.dag_id }}", "cpu": "{{ dag.dag_id }}"},
Expand Down Expand Up @@ -184,6 +186,8 @@ def test_templates(self, create_task_instance_of_operator, session):
assert dag_id == rendered.container_resources.requests["cpu"]
assert dag_id == rendered.volume_mounts[0].name
assert dag_id == rendered.volume_mounts[0].sub_path
assert dag_id == ti.task.hostname
assert dag_id == ti.task.name
assert dag_id == ti.task.image
assert dag_id == ti.task.cmds
assert dag_id == ti.task.namespace
Expand Down
Loading