Skip to content

Unable to specify dns_config for kubernetes pod executor #31689

Description

@rokos-angus

Apache Airflow version

2.6.1

What happened

Seem to be unable to specify dns_config in KubernetesPodOperator, despite it being an argument.

Broken DAG: [/opt/airflow/dags/repo/bug-report-dag.py] Traceback (most recent call last): File "/home/airflow/.local/lib/python3.7/site-packages/airflow/models/baseoperator.py", line 429, in apply_defaults result = func(self, **kwargs, default_args=default_args) File "/home/airflow/.local/lib/python3.7/site-packages/airflow/models/baseoperator.py", line 789, in __init__ f"Invalid arguments were passed to {self.__class__.__name__} (task_id: {task_id}). " airflow.exceptions.AirflowException: Invalid arguments were passed to KubernetesPodOperator (task_id: task). Invalid arguments were: **kwargs: {'dns_config': {'nameservers': None, 'options': None, 'searches': ['mydomain.com']}}

What you think should happen instead

dnsConfig should be correctly added to the pod manifest

How to reproduce

from airflow import DAG
from airflow.providers.cncf.kubernetes.operators.pod import KubernetesPodOperator
from airflow.utils.dates import days_ago
from kubernetes.client import models as k8s

default_args = {
    'owner': 'airflow'
}

env = [
    k8s.V1EnvVar(name="TEST_ARG", value="test")
]
dns = k8s.V1PodDNSConfig(searches=["mydomain.com"])

with DAG(
    dag_id='my-dag',
    default_args=default_args,
    schedule_interval="*/5 * * * *",
    start_date=days_ago(2),
    catchup=False,
    tags=['k8s-pod-operator','example', 'python'],
) as dag:
    k = KubernetesPodOperator(
        namespace='airflow',
        image="python",
        cmds=["python", "-c"],
        arguments=["print('hello ...')"],
        name="k8s-pod",
        task_id="task",
        env_vars=env,
        dns_config=dns,
        is_delete_operator_pod=True,
        hostnetwork=False,
        startup_timeout_seconds=1000,
        kubernetes_conn_id=None
    )

Operating System

Debian GNU/Linux 11 (bullseye)

Versions of Apache Airflow Providers

No response

Deployment

Official Apache Airflow Helm Chart

Deployment details

Official helm chart via flux with
defaultAirflowTag: "2.6.1"
airflowVersion: "2.6.1"

Anything else

No response

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:corekind:bugThis is a clearly a bugneeds-triagelabel for new issues that we didn't triage yet

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions