Skip to content

Commit

Permalink
Fix mark as success when pod fails while fetching log (apache#42815)
Browse files Browse the repository at this point in the history
* fix: always defer once more after log fetching to ensure pod completion is handled

* add tests

* removing print

---------

Co-authored-by: Jean-Eudes Peloye <[email protected]>
  • Loading branch information
romsharon98 and peloyeje authored Oct 9, 2024
1 parent a5ffbbd commit 00d6ae7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
4 changes: 1 addition & 3 deletions airflow/providers/cncf/kubernetes/operators/pod.py
Original file line number Diff line number Diff line change
Expand Up @@ -790,9 +790,7 @@ def trigger_reentry(self, context: Context, event: dict[str, Any]) -> Any:
since_time=last_log_time,
)

if pod_log_status.running:
self.log.info("Container still running; deferring again.")
self.invoke_defer_method(pod_log_status.last_log_time)
self.invoke_defer_method(pod_log_status.last_log_time)
else:
self.invoke_defer_method()

Expand Down
12 changes: 12 additions & 0 deletions tests/providers/cncf/kubernetes/operators/test_pod.py
Original file line number Diff line number Diff line change
Expand Up @@ -1780,6 +1780,18 @@ def test_process_duplicate_label_pods__pod_removed_if_delete_pod(
process_pod_deletion_mock.assert_called_once_with(pod_1)
assert result.metadata.name == pod_2.metadata.name

@patch(POD_MANAGER_CLASS.format("fetch_container_logs"))
@patch(KUB_OP_PATH.format("invoke_defer_method"))
def test_defere_call_one_more_time_after_error(self, invoke_defer_method, fetch_container_logs):
fetch_container_logs.return_value = PodLoggingStatus(False, None)
op = KubernetesPodOperator(task_id="test_task", name="test-pod", get_logs=True)

op.trigger_reentry(
create_context(op), event={"name": TEST_NAME, "namespace": TEST_NAMESPACE, "status": "running"}
)

invoke_defer_method.assert_called_with(None)


class TestSuppress:
def test__suppress(self, caplog):
Expand Down

0 comments on commit 00d6ae7

Please sign in to comment.