Add KubernetesPodExecOperator for existing Kubernetes Pods - #71244
Conversation
031ffbc to
52b1cc6
Compare
What's the User story and real-world use cases for this? |
Thanks for asking. The user story is:
Our concrete use case is running dbt on EKS. Today, our workflow starts a new Pod, initializes the dbt project and its dependencies, and then executes a command such as We want to manage that Pod separately and keep it warm, then use Airflow to execute ad hoc commands such as More generally, this is useful whenever a Pod’s lifecycle is managed outside the task and its environment is already initialized. The operator exposes the equivalent of |
|
@SameerMesiah97 Could you please review it when you have a chance? Thank you! |
There was a problem hiding this comment.
I am 50/50 on this new operator for 3 main reasons:
-
I think this new operator diverges from the existing operators in the sense that it is trying to orchestrate externally managed resources that have their own lifecycle and control plane. This introduces some unclear lifecycle and ownership semantics. For example, what happens if the Pod/container is restarted or replaced while the task is executing, or if the exec connection is lost and the Airflow task retries? Could the original command still be running while the retry starts another exec?
-
Should we be introducing a new operator i.e.
KubernetesPodExecOperatoror could we consider supporting externally managed Pods as an execution mode ofKubernetesPodOperatorinstead? I can see an argument for keeping them separate because KPO owns the Pod lifecycle whereas this operator would only own the exec lifecycle, but both ultimately represent executing an Airflow task inside a Kubernetes container. I think it would be useful to establish why a separate public operator is preferable before introducing another Kubernetes execution abstraction. -
I have to build on @kaxil's reservations regarding potential use cases by questioning whether an operator strictly for
kubectl execcommands is the right abstraction. What about fetching logs or waiting on/monitoring an externally managed Pod (this may be a senor or trigger; this needs discussion too) ? If the broader use case is for Airflow to interact with Pods whose lifecycle it does not own, thenexecfeels like only one specific operation within that model. Perhaps, a broader operator that handles several commands may be better.
These points could be addresesd in the description. For an atypical operator in a high blast radius provider, I think we need to really nail the rationale.
|
Thanks for the feedback. Airflow commonly acts as a client of infrastructure it does not own: Although this can be implemented with Keeping this provider-neutral also allows GKE- or EKS-specific operators to reuse it and add only their cloud authentication and cluster configuration, following the existing provider layering. I prefer keeping it separate from KPO because KPO owns the complete Pod lifecycle, while this operator deliberately treats the Pod as externally managed. If the Pod disappears, restarts, or the connection fails, the task fails. A retry creates a new exec session; Airflow never creates, replaces, or deletes the Pod. |
I think this is the strongest argument here. If using this operator saves time and effort for users who want this specific functionality, then I believe it is justified. But like I mentioned above, why only |
|
Combining
This also differs from |
|
@SameerMesiah97 Could you help me with a code review? I’ve already tested it with the end-to-end system test and an Apache Magpie review. Thank you! 🙏 |
Reusing a running Pod avoids the startup latency incurred when each task creates a new Pod.
Exec sessions need predictable cleanup and bounded memory use when commands stream output or fail partway through execution.
52b1cc6 to
0ab3ba2
Compare
Add
KubernetesPodExecOperatorto execute commands in a running container of an existing Kubernetes Pod without creating, restarting, or deleting it. This supports pre-warmed or externally managed Pods where avoiding startup latency is important.The operator validates the target Pod and container, streams stdout and stderr, waits for the command exit code, and reliably closes the exec connection. Optional stdout XCom is disabled by default and protected by a configurable size limit to avoid retaining unbounded output in worker memory.
Provider metadata, RBAC guidance, operator documentation, unit tests, and an end-to-end system test are included.
Tests:
39 passed)1 passed)Was generative AI tooling used to co-author this PR?
Generated-by: Codex (GPT-5) following the guidelines