Skip to content

Write KubernetesJobOperator pod logs before raising on a failed Job - #76328

Open
Ankitraj-builds wants to merge 5 commits into
apache:mainfrom
Ankitraj-builds:fix/k8s-job-logs-on-failure
Open

Ankitraj-builds wants to merge 5 commits into
apache:mainfrom
Ankitraj-builds:fix/k8s-job-logs-on-failure

Conversation

@Ankitraj-builds

Copy link
Copy Markdown
Contributor

closes: #76325

In deferrable mode, KubernetesJobOperator.execute_complete raised on status == "error" before the get_logs block, so the pod logs of a failed Job were never written. With on_finish_action="delete_pod" the pod is then deleted, so the cause of the failure was lost.

This writes the pod logs first and raises afterwards. A failure while writing logs is logged as a warning, so it doesn't replace the Job's own error.

Tests:

  • test_execute_complete_fail_writes_logs: logs are written for a failed Job, and the Job error is still raised.
  • test_execute_complete_fail_log_error_keeps_job_error: an error while writing logs doesn't hide the Job error.

Both fail on main and pass with this change. All 95 tests in test_job.py pass.

@boring-cyborg

boring-cyborg Bot commented Nov 2, 2026

Copy link
Copy Markdown

Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contributors' Guide
Here are some useful points:

  • Pay attention to the quality of your code (ruff, mypy and type annotations). Our prek-hooks will help you with that.
  • In case of a new feature add useful documentation (in docstrings or in docs/ directory). Adding a new operator? Check this short guide Consider adding an example Dag that shows how users should use it.
  • Consider using Breeze environment for testing locally, it's a heavy docker but it ships with a working Airflow and a lot of integrations.
  • Be patient and persistent. It might take some time to get a review or get the final approval from Committers.
  • Please follow ASF Code of Conduct for all communication including (but not limited to) comments on Pull Requests, Mailing list and Slack.
  • Be sure to read the Airflow Coding style.
  • Always keep your Pull Requests rebased, otherwise your build might fail due to changes not related to your commits.
    Apache Airflow is a community-driven project and together we are making it better 🚀.
    In case of doubts contact the developers at:
    Mailing List: [email protected]
    Slack: https://s.apache.org/airflow-slack

@henry3260 henry3260 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good, leave some comments

@Ankitraj-builds

Copy link
Copy Markdown
Contributor Author

Hi @jscheffl , I’ve addressed @henry3260’s review (retry pods are now logged too, and the tests are parametrized). Could you take a look when you have time? The CI workflows are also waiting for approval.

@Miretpl
Miretpl requested a review from henry3260 November 15, 2026 23:09

This branch has not been deployed

No deployments
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 (k8s) provider related issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

KubernetesJobOperator (deferrable): get_logs=True writes no pod logs when the Job fails

3 participants