henry3260 opened a new pull request, #76035:
URL: https://github.com/apache/airflow/pull/76035
## Why
`on_operator_resuming` is listed as a supported callback in the CNCF
Kubernetes provider
docs, but it has had no call site since #57531. That change moved pod log
reading into the
triggerer and dropped the `event["status"] == "running"` re-defer branch from
`trigger_reentry`; the callback invocation sat inside the adjacent
`event["status"] != "running"` guard and was removed along with it.
The regression is silent.
`KubernetesPodOperatorCallback.on_operator_resuming` is a no-op in
the base class, so a user override that stops being invoked produces no
exception, warning or
log line — the only symptom is that nothing happens.
It also went unnoticed because the test that covered it was left asserting a
different
callback: `test_execute_async_callbacks` checked `on_pod_cleanup` twice,
once under a
`# check on_operator_resuming callback` comment, so it kept passing.
The callback matters most on the `_redefer_count` retry path, where the
trigger reports an
error for a pod that is still alive. There the trigger event holds the only
record of what
went wrong, and `on_operator_resuming` is the only callback that receives it.
## What
*
`providers/cncf/kubernetes/src/airflow/providers/cncf/kubernetes/operators/pod.py`
—
restore the invocation in `trigger_reentry`. It is placed after the pod
lookup guard,
because the callback signature takes a non-optional `V1Pod`, and ahead of
the re-defer
branch, because `invoke_defer_method` raises `TaskDeferred` and nothing
below it runs on a
re-deferred re-entry. The old `event["status"] != "running"` guard is not
reintroduced: the
trigger no longer emits `status: "running"`, so the condition is dead, and
it was what
limited the callback to the final terminal re-entry.
*
`providers/cncf/kubernetes/src/airflow/providers/cncf/kubernetes/callbacks.py`
— document
when the callback fires, including the synchronous short-circuit taken
when the pod is
already terminal before deferral, and the garbage-collected-pod case where
it does not fire.
*
`providers/cncf/kubernetes/tests/unit/cncf/kubernetes/operators/test_pod.py` —
`test_execute_async_callbacks` now asserts `on_operator_resuming` and
checks the `event`
kwarg; it also pins the pod returned by `get_pod`, which is a different
object from the one
`await_pod_completion` returns later. New
`test_on_operator_resuming_fires_before_redefer`
covers the re-defer path and asserts the terminal callbacks stay
untouched. Both tests fail
when only `pod.py` is reverted.
* `providers/cncf/kubernetes/docs/operators.rst` — add the two callbacks
missing from the
supported list (`on_pod_manifest_created`, `on_pod_teardown`) and replace
the stale
"callbacks methods are not called in the async mode" sentence with the
callbacks deferrable
mode actually invokes.
Verification: `pytest
providers/cncf/kubernetes/tests/unit/cncf/kubernetes/operators/test_pod.py`
gives 262 passed, 2 failed, 10 errors; the same 2 failures and 10 errors
occur on `main` with
this change stashed (261 passed), so they are pre-existing locally. `prek`
pre-commit and
manual stages pass, as does `mypy-providers` on the two changed source
files. The
`breeze testing providers-tests` and `breeze build-docs` runs that `breeze
verify` lists could
not be executed locally: the CI image build fails in
`install_os_dependencies.sh` on an apt
conflict (`libffi8`, `libbz2-1.0`, `libgpg-error0` held broken packages),
unrelated to this
change.
---
##### Was generative AI tooling used to co-author this PR?
- [X] Yes — Claude Code (Opus 5)
Generated-by: Claude Code (Opus 5) following [the
guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]