Skip to content

Kubernetes Pod Operator Callbacks progress_callbacks repeat same line #59366

@johnhoran

Description

@johnhoran

Apache Airflow Provider(s)

cncf-kubernetes

Versions of Apache Airflow Providers

No response

Apache Airflow version

2.11

Operating System

linux

Deployment

Official Apache Airflow Helm Chart

Deployment details

No response

What happened

I constructed a fairly simple dag

"""Example DAG demonstrating the use of the KubernetesPodOperator."""

from datetime import datetime, timedelta

from airflow import DAG
from airflow.providers.cncf.kubernetes.operators.pod import KubernetesPodOperator
from airflow.providers.cncf.kubernetes.callbacks import KubernetesPodOperatorCallback

from typing import TYPE_CHECKING
if TYPE_CHECKING:
    from airflow.providers.cncf.kubernetes.callbacks import client_type


class MyCallback(KubernetesPodOperatorCallback):
    @classmethod
    def progress_callback(cls, *, line: str, client: "client_type", mode: str, **kwargs) -> None:
        print(">>>" + line)
with DAG(
    dag_id="example_kubernetes_operator",
    schedule=None,
    start_date=datetime(2021, 1, 1),
    tags=["example"],
    doc_md=__doc__,

    dagrun_timeout=timedelta(minutes=60),
) as dag:
    k = KubernetesPodOperator(

        image="ubuntu:16.04",
        cmds=["bash", "-cx"],
        arguments=["for i in {1..20}; do echo \"Hi $i\"; sleep 1; done"],
        labels={"foo": "bar"},
        name="airflow-test-pod",
        task_id="task",
        # deferrable=True,
        # logging_interval=2,
        callbacks=MyCallback
    )

From this I expect to see both the log lines from KPO as well as the lines repeated from my print statement in the callback, but instead I get the regular KPO output and then the same line repeated over and over >>>2025-12-12T13:14:33.549732798Z + for i in '{1..20}', which was the first line from KPO.

I tried going back to older versions thinking a bug had been introduced somewhere, but I went all the way back to "apache-airflow-providers-cncf-kubernetes==7.14.0", and still couldn't get proper output.

What you think should happen instead

No response

How to reproduce

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

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions