Repository navigation
Description
Apache Airflow Provider(s)
cncf-kubernetes
Versions of Apache Airflow Providers
apache-airflow-providers-cncf-kubernetes 4.3.0
Apache Airflow version
2.3.4
Operating System
Linux
Deployment
Official Apache Airflow Helm Chart
Deployment details
n/a
What happened
We are upgrading from apache-airflow-providers-cncf-kubernetes 3.0.0 to 4.3.0 (going slowly through releases).
We have a custom script, that during docker image build of our airflow, tests all dags and all dag tasks in dry_run mode. Mostly to detect Python syntax errors, dag cycles duplicate tasks, wrong imports, ntemplating errors etc.
This was working all fine with our existing airflow, but we decided to upgrade airflow to newer version, and that also means updating airflow providers. After fixing bunch of other issues, I found the issues with KubernetedPodOperator dry run.
New dry_run added in d56ff76 invokes KubernetesPodOperator build_pod_request_obj() method which has a call to a property self.hook.is_in_cluster:
pod.metadata.labels.update(
{
'airflow_version': airflow_version.replace('+', '-'),
'airflow_kpo_in_cluster': str(self.hook.is_in_cluster),
}
)Unfortunately this property constructs a Kube API client object which requires kube client config / credentials to work.
@property
def is_in_cluster(self):
"""Expose whether the hook is configured with ``load_incluster_config`` or not"""
if self._is_in_cluster is not None:
return self._is_in_cluster
self.api_client # so we can determine if we are in_cluster or not
return self._is_in_cluster```This causes dry_run to not able to execute in isolated test environment:
Traceback (most recent call last):
File "<stdin>", line 97, in <module>
File "/home/airflow/.local/lib/python3.9/site-packages/airflow/models/dag.py", line 2307, in cli
args.func(args, self)
File "/home/airflow/.local/lib/python3.9/site-packages/airflow/cli/cli_parser.py", line 51, in command
return func(*args, **kwargs)
File "/home/airflow/.local/lib/python3.9/site-packages/airflow/utils/cli.py", line 99, in wrapper
return f(*args, **kwargs)
File "/home/airflow/.local/lib/python3.9/site-packages/airflow/cli/commands/task_command.py", line 545, in task_test
ti.dry_run()
File "/home/airflow/.local/lib/python3.9/site-packages/airflow/models/taskinstance.py", line 1815, in dry_run
self.task.dry_run()
File "/home/airflow/.local/lib/python3.9/site-packages/airflow/providers/cncf/kubernetes/operators/kubernetes_pod.py", line 607, in dry_run
pod = self.build_pod_request_obj()
File "/home/airflow/.local/lib/python3.9/site-packages/airflow/providers/cncf/kubernetes/operators/kubernetes_pod.py", line 595, in build_pod_request_obj
'airflow_kpo_in_cluster': str(self.hook.is_in_cluster),
File "/home/airflow/.local/lib/python3.9/site-packages/airflow/providers/cncf/kubernetes/hooks/kubernetes.py", line 283, in is_in_cluster
self.api_client # so we can determine if we are in_cluster or not
File "/usr/local/lib/python3.9/functools.py", line 993, in __get__
val = self.func(instance)
File "/home/airflow/.local/lib/python3.9/site-packages/airflow/providers/cncf/kubernetes/hooks/kubernetes.py", line 291, in api_client
return self.get_conn()
File "/home/airflow/.local/lib/python3.9/site-packages/airflow/providers/cncf/kubernetes/hooks/kubernetes.py", line 239, in get_conn
config.load_kube_config(
File "/home/airflow/.local/lib/python3.9/site-packages/kubernetes/config/kube_config.py", line 808, in load_kube_config
loader = _get_kube_config_loader(
File "/home/airflow/.local/lib/python3.9/site-packages/kubernetes/config/kube_config.py", line 767, in _get_kube_config_loader
raise ConfigException(
kubernetes.config.config_exception.ConfigException: Invalid kube-config file. No configuration found.
We would like to continue using dry_run, but be able to run it without providing credentials or kube config. It does not need to be 100% accurate.
Two options:
- env var to bypass setting of
airflow_kpo_in_clusterlabel in dry run mode, if user requests to do so. - never populate it in dry_run mode. (change signature of
build_pod_request_objto havedry_run: bool = Falsekwarg and invoke it withdry_run=Truein KubernetesPodOperator.dry_run()` method.
(or both)
What you think should happen instead
n/a
How to reproduce
n/a
Anything else
n/a
Are you willing to submit PR?
- Yes I am willing to submit a PR!
Code of Conduct
- I agree to follow this project's Code of Conduct
Activity
potiuk commentedon Jan 20, 2025
Feel free to attempt to fix it and provide PR
baryluk commentedon Jan 21, 2025
@potiuk Sure, I can, but I wanted to get some feedback from kubernetes provider maintainers first what would they prefer.
potiuk commentedon Jan 21, 2025
There are no "kubernetes provider maintainers" here. It's all "airflow" maintainers - anyone can comment here, and any maintainer can approve PR that is created. Since we are in the hottest part of Airlfow 3 building, it's not very likely that you will get more feedback than that, so creating a good PR with proposal how you would like to solve it is the best way to grab attention of maintainers who could approve it.
nevcohen commentedon Jan 29, 2025
If I'm not mistaken, the purpose of
dry runis to simulate running in a real environment, so you must give a credential (or kube config), if not, then where do you want it to run?github-actions commentedon Jan 30, 2026
This issue has been automatically marked as stale because it has been open for 365 days without any activity. There has been several Airflow releases since last activity on this issue. Kindly asking to recheck the report against latest Airflow version and let us know if the issue is reproducible. The issue will be closed in next 30 days if no further activity occurs from the issue author.
baryluk commentedon Feb 7, 2026
You do not need credentials nor connection to any real or test k8s environment. You can dry run in a sense that pod spec validates and has no syntax or type errors. There is no way to actually simulate full run in dry run, as that would require full clone of production setup.
We use dry run to just make sure that all functions execute, there are no undefined variables, or undefined functions / modules used for example. And for tasks,that all passed arguments are correct (name, value and type). And check that there are no cycles, or other dag issues.
potiuk commentedon Feb 15, 2026
Again. Opening PR is a good idea here. This is hte best way to get a discussion going if your proposed solution will work - especially if you try it in your environment. There is little sense in waiting for a mythical "kubernetes maintainer" to discuss it with. this is such a small change, that showing a working PR that whoever can comment on, showing th extent of change it introduces and something tested in your environment, is the fastest way to get this one implemented.
potiuk commentedon Mar 2, 2026
@baryluk We are unassigning you from this issue as part of our updated assignment policy.
This is not meant to discourage your contribution — quite the opposite! You are still very welcome to work on this issue and submit a PR for it. Simply comment that you are working on it and open a PR when ready.
We found that formal assignments were not working well, as they often prevented others from contributing when the assignee was not actively working on the issue.
Vedant-Agarwal commentedon Jun 12, 2026
Working on this, following the scoping @potiuk described in the February comment:
dry_runshould only build and print the pod spec, without instantiating any client or needing a kube config. Fix plus tests (runningdry_runwith no credentials available) coming shortly as a PR.Fix KubernetesPodOperator dry_run requiring live Kubernetes API client (