Skip to content

Introduce ExecutionMode.WATCHER_KUBERNETES to use watcher with KubernetesPodOperator#2207

Merged
tatiana merged 68 commits into
mainfrom
k8s-watcher-mess
Jan 7, 2026
Merged

Introduce ExecutionMode.WATCHER_KUBERNETES to use watcher with KubernetesPodOperator#2207
tatiana merged 68 commits into
mainfrom
k8s-watcher-mess

Conversation

@tatiana
Copy link
Copy Markdown
Collaborator

@tatiana tatiana commented Dec 16, 2025

Introduce ExecutionMode.WATCHER_KUBERNETES, allowing users to use the Producer/Consumer approach without requiring dbt to be installed in the same environment as Airflow.

This PR includes an example DAG illustrating the use-case.

Given an existing bug in the latest releases of apache-airflow-providers-cncf-kubernetes (apache/airflow#59366), we had to subclass the KubernetesPodManager class and override a method. This may not be needed once the fix is merged and the new provider version is released. Given this issue, we have tested and successfully validated the usage of this execution mode with the following versions of apache-airflow-providers-cncf-kubernetes

  • 10.8.0
  • 10.9.0
  • 10.10.0
  • 10.11.0
  • 10.12.2 (tested on 30 January 2026, after this PR was merged)

Why

There is significant overhead each time a K8S Pod is spawned and when the dbt project is parsed.

Cosmos ExecutionMode.WATCHER (docs) has delivered significant performance improvements for users who were previously using ExecutionMode.LOCAL; however, some users need to keep Airflow and dbt dependencies isolated.

This PR extends the ExecutionMode.WATCHER performance gains to Kubernetes.

Comparison of the same dbt project DAG run with Jaffle Shop (reproducible by modifying the DAG jaffle_shop_watcher_kubernetes included in this PR):

  • ExecutionMode.KUBERNETES: 00:00:32.155
  • ExecutionMode.WATCHER_KUBERNETES: 00:00:11.783

Limitations

  • Does not work with older versions of the apache-airflow-providers-cncf-kubernetes provider (<=10.7.0)
  • Only works withdeferrable=False.

** Pending work**

  • The documentation will come in a follow-up PR.

How to use

  • Users previously using ExecutionMode.KUBERNETES can just replace the execution_mode to use ExecutionMode.WATCHER_KUBERNETES.

Example DAG

This PR includes an example DAG that runs with our integration tests, jaffle_shop_watcher_kubernetes:
Screenshot 2026-01-06 at 11 12 59

The producer task runs dbt build using the KubernetesPodOperator:
Screenshot 2026-01-06 at 11 12 15
This task will populate XCom with status updates for each dbt node that is completed.

By default, the consumer tasks will be native Airflow deferrable sensors:
Screenshot 2026-01-06 at 11 12 25

And, in case of retries, the consumer tasks use Cosmos ExecutionMode.KUBERNETES KPO operators:
Screenshot 2026-01-06 at 11 18 42

Closes: #2042

@netlify
Copy link
Copy Markdown

netlify Bot commented Dec 16, 2025

Deploy Preview for astronomer-cosmos canceled.

Name Link
🔨 Latest commit 1f18858
🔍 Latest deploy log https://app.netlify.com/projects/astronomer-cosmos/deploys/695e67c643be610008310299

@codecov
Copy link
Copy Markdown

codecov Bot commented Dec 18, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.03%. Comparing base (345aab8) to head (c6c156e).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2207      +/-   ##
==========================================
+ Coverage   97.97%   98.03%   +0.05%     
==========================================
  Files          97       98       +1     
  Lines        6273     6352      +79     
==========================================
+ Hits         6146     6227      +81     
+ Misses        127      125       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

tatiana and others added 6 commits January 6, 2026 11:06
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Comment thread .github/workflows/test.yml Outdated
Comment thread cosmos/airflow/_override.py
@tatiana
Copy link
Copy Markdown
Collaborator Author

tatiana commented Jan 6, 2026

Thanks a lot for the reviews, @johnhoran @pankajkoti @pankajastro - I think I addressed most, if not all, of them

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 24 out of 24 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread cosmos/operators/_watcher/triggerer.py Outdated
Comment thread cosmos/airflow/_override.py Outdated
Comment thread tests/test_example_k8s_dags.py Outdated
tatiana and others added 4 commits January 6, 2026 13:05
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

@pankajastro pankajastro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Comment thread cosmos/constants.py
Comment thread cosmos/operators/watcher.py
Copy link
Copy Markdown
Contributor

@pankajkoti pankajkoti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Couple of questions inline

Comment thread tests/operators/test_watcher_kubernetes.py Outdated
Comment thread tests/operators/test_watcher_kubernetes.py Outdated
Comment thread cosmos/operators/watcher_kubernetes.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support ExecutionMode.WATCHER via virtualenv and/or kubernetespod

5 participants