Fix KubernetesPodOperator dry_run requiring live Kubernetes API client - #70234
Conversation
7f3ce00 to
b9eba59
Compare
b9eba59 to
e540c09
Compare
|
There are couple of unrelated changes in the PR + conflics - could you resolve it? |
e540c09 to
e91dc6e
Compare
|
Thanks for flagging this. The branch had two extra commits that were unrelated to this fix (a check_provider_yaml_files.py namespaced-provider crash fix and a Jira provider.yaml conn-field fix) — those were already merged into main separately via #70224 and #70261, which is what caused the conflicts. I dropped both commits and rebased the actual KubernetesPodOperator dry_run fix cleanly onto latest main. The branch now only contains the two files relevant to this PR (pod.py and its test) and is mergeable. |
airflow dags test and dry_run() failed outside a cluster because build_pod_request_obj() unconditionally read hook.is_in_cluster to set the airflow_kpo_in_cluster label, which instantiates a Kubernetes API client and requires kube credentials/config to be available. A dry run should not need cluster access at all. closes: apache#45812
e91dc6e to
910515b
Compare
potiuk
left a comment
There was a problem hiding this comment.
Thanks — real usability bug. dry_run() existing to show what would be submitted shouldn't require working kube credentials, and self.hook.is_in_cluster instantiates an API client purely to compute a label value. Threading a keyword-only dry_run flag through build_pod_request_obj is the minimal way to fix it, and keyword-only keeps it backward compatible for the many subclasses that override or call this method.
The tests are the right shape: making is_in_cluster raise and asserting the dry-run path survives and the normal path still raises proves the flag actually gates the client instantiation, rather than just that dry_run happens to work.
One consequence worth deciding on inline.
Drafted-by: Claude Code (Opus 5); reviewed by @potiuk before posting
airflow dags test(and callingKubernetesPodOperator.dry_run()directly) failed outside a real cluster becausebuild_pod_request_obj()unconditionally readhook.is_in_clusterto set theairflow_kpo_in_clusterlabel. That property instantiates a Kubernetes API client, which requires kube credentials/config to be available — something a dry run must not need.This adds a keyword-only
dry_runparameter tobuild_pod_request_obj()(defaultFalse, so existing callers are unaffected) and hasdry_run()skip theis_in_clusterlookup when set.closes: #45812