Skip to content

KubernetesPodOperator dry_run failure #45812

Closed

Description

@baryluk

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_cluster label in dry run mode, if user requests to do so.
  • never populate it in dry_run mode. (change signature of build_pod_request_obj to have dry_run: bool = False kwarg and invoke it with dry_run=True in 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

Activity

  1. added
    kind:bug
    needs-triage
    on Jan 20, 2025
  2. added
    provider:cncf-kubernetes
    on Jan 20, 2025
  3. added and removed
    needs-triage
    on Jan 20, 2025
  4. potiuk commented on Jan 20, 2025

    @potiuk
    Member

    Feel free to attempt to fix it and provide PR

  5. baryluk commented on Jan 21, 2025

    @baryluk
    ContributorAuthor

    @potiuk Sure, I can, but I wanted to get some feedback from kubernetes provider maintainers first what would they prefer.

  6. potiuk commented on Jan 21, 2025

    @potiuk
    Member

    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.

  7. nevcohen commented on Jan 29, 2025

    @nevcohen
    Contributor

    If I'm not mistaken, the purpose of dry run is 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?

  8. github-actions commented on Jan 30, 2026

    @github-actions
    Contributor

    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.

  9. baryluk commented on Feb 7, 2026

    @baryluk
    ContributorAuthor

    If I'm not mistaken, the purpose of dry run is 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?

    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.

  10. added
    needs-triage
    and removed on Feb 8, 2026
  11. potiuk commented on Feb 15, 2026

    @potiuk
    Member

    If I'm not mistaken, the purpose of dry run is 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?

    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.

    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.

  12. potiuk commented on Mar 2, 2026

    @potiuk
    Member

    @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.

  13. Vedant-Agarwal commented on Jun 12, 2026

    @Vedant-Agarwal
    Contributor

    Working on this, following the scoping @potiuk described in the February comment: dry_run should only build and print the pod spec, without instantiating any client or needing a kube config. Fix plus tests (running dry_run with no credentials available) coming shortly as a PR.

  14. added a commit that references this issue on Jul 30, 2026
    9481c8e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:providersgood first issuekind:bugneeds-triageprovider:cncf-kubernetes

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions