Skip to content

Commit

Permalink
Add annotations field into in KubernetesPodOperator (#35641)
Browse files Browse the repository at this point in the history
  • Loading branch information
shohamy7 committed Nov 15, 2023
1 parent a8c062f commit 6f51e50
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 2 additions & 1 deletion airflow/providers/cncf/kubernetes/operators/pod.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ class KubernetesPodOperator(BaseOperator):
:param image_pull_policy: Specify a policy to cache or always pull an image.
:param annotations: non-identifying metadata you can attach to the Pod.
Can be a large range of data, and can include characters
that are not permitted by labels.
that are not permitted by labels. (templated)
:param container_resources: resources for the launched pod. (templated)
:param affinity: affinity scheduling rules for the launched pod.
:param config_file: The path to the Kubernetes config file. (templated)
Expand Down Expand Up @@ -261,6 +261,7 @@ class KubernetesPodOperator(BaseOperator):
template_fields: Sequence[str] = (
"image",
"cmds",
"annotations",
"arguments",
"env_vars",
"labels",
Expand Down
2 changes: 2 additions & 0 deletions tests/providers/cncf/kubernetes/operators/test_pod.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ def test_templates(self, create_task_instance_of_operator):
arguments="{{ dag.dag_id }}",
cmds="{{ dag.dag_id }}",
image="{{ dag.dag_id }}",
annotations={"dag-id": "{{ dag.dag_id }}"},
)

rendered = ti.render_templates()
Expand All @@ -167,6 +168,7 @@ def test_templates(self, create_task_instance_of_operator):
assert dag_id == ti.task.pod_template_file
assert dag_id == ti.task.arguments
assert dag_id == ti.task.env_vars[0]
assert dag_id == rendered.annotations["dag-id"]

def run_pod(self, operator: KubernetesPodOperator, map_index: int = -1) -> k8s.V1Pod:
with self.dag_maker(dag_id="dag") as dag:
Expand Down

0 comments on commit 6f51e50

Please sign in to comment.