Skip to content

Commit

Permalink
Fix KubernetesPodOperator sub classes default container_logs (#33090)
Browse files Browse the repository at this point in the history
  • Loading branch information
hussein-awala committed Aug 4, 2023
1 parent e3d82c6 commit f83d63e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 1 addition & 3 deletions airflow/providers/cncf/kubernetes/operators/pod.py
Expand Up @@ -361,9 +361,7 @@ def __init__(
self.get_logs = get_logs
self.container_logs = container_logs
if self.container_logs == KubernetesPodOperator.BASE_CONTAINER_NAME:
self.container_logs = (
base_container_name if base_container_name else KubernetesPodOperator.BASE_CONTAINER_NAME
)
self.container_logs = base_container_name if base_container_name else self.BASE_CONTAINER_NAME
self.image_pull_policy = image_pull_policy
self.node_selector = node_selector or {}
self.annotations = annotations or {}
Expand Down
8 changes: 8 additions & 0 deletions tests/providers/cncf/kubernetes/operators/test_pod.py
Expand Up @@ -1724,3 +1724,11 @@ def test_async_kpo_wait_termination_before_cleanup_on_failure(

# assert that the cleanup is called
post_complete_action.assert_called_once()


def test_default_container_logs():
class TestSubclassKPO(KubernetesPodOperator):
BASE_CONTAINER_NAME = "test-base-container"

k = TestSubclassKPO(task_id="task")
assert k.container_logs == "test-base-container"

0 comments on commit f83d63e

Please sign in to comment.