Skip to content

KubernetesPodOperator new callbacks and allow multiple callbacks#44357

Merged
potiuk merged 15 commits into
apache:mainfrom
johnhoran:kubernetes-callbacks
Jan 27, 2025
Merged

KubernetesPodOperator new callbacks and allow multiple callbacks#44357
potiuk merged 15 commits into
apache:mainfrom
johnhoran:kubernetes-callbacks

Conversation

@johnhoran

Copy link
Copy Markdown
Contributor

I would like to have multiple callbacks in the kubernetes pod operator, and add two new callbacks. on_manifest_finalization would allow the callback to make changes just before the manifest is turned into a pod.
on_pod_wrapup would happen after the calls to on_pod_completion but just before the pod is deleted.

Adding both of these plus allowing multiple callbacks would allow you to do things in the kubernetes pod operator akin to how it approaches XComs but in a modular way. My use case here is I'm running DBT in kpo, and I want to do multiple things to the DBT artefacts after the DBT job has run, I could use on_manifest_finalization to insert an alpine sidecar with volumes mounted with the same intention as the XCom sidecar, where the sidecar keeps the volumes alive as files are extracted from it. on_pod_wrapup would allow me to insert a single sidecar and have multiple callbacks run their on_pod_completion before on_pod_wrapup kills the sidecar.

@boring-cyborg boring-cyborg Bot added area:providers provider:cncf-kubernetes Kubernetes (k8s) provider related issues labels Nov 25, 2024

@amoghrajesh amoghrajesh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Good start!
Can you add few test cases that test more scenarios of more than 1 callback?

  1. Few sync callbacks
  2. Few async
  3. Combination of both - trying to assert for order

Comment thread providers/src/airflow/providers/cncf/kubernetes/callbacks.py Outdated
Comment thread providers/src/airflow/providers/cncf/kubernetes/callbacks.py Outdated
@amoghrajesh amoghrajesh self-requested a review December 17, 2024 06:00
Comment thread providers/tests/cncf/kubernetes/operators/test_pod.py
@johnhoran johnhoran requested a review from amoghrajesh January 21, 2025 11:11
@potiuk

potiuk commented Jan 26, 2025

Copy link
Copy Markdown
Member

Some static checks to solve after rebase

@potiuk

potiuk commented Jan 26, 2025

Copy link
Copy Markdown
Member

Note: We are in the process of moving all providers to a new structure - as part of #46045 so if you would like to avoid having to resolve conflicts, speedy fix and rebase is something that you might want to do @johnhoran

@potiuk

potiuk commented Jan 26, 2025

Copy link
Copy Markdown
Member

See also devlist announcement: https://lists.apache.org/thread/dzbj5yx5kwpbwyr5yscp4wnlsp6p9v8l

Comment thread providers/tests/cncf/kubernetes/operators/test_pod.py Outdated
@eladkal

eladkal commented Jan 27, 2025

Copy link
Copy Markdown
Contributor

I fixed the static checks but the PR has conflicts @johnhoran can you please revase and resolve them?

@eladkal

eladkal commented Jan 27, 2025

Copy link
Copy Markdown
Contributor

Failures are on papermill provider, not related to this PR

@potiuk potiuk merged commit cc5f2f9 into apache:main Jan 27, 2025
@boring-cyborg

boring-cyborg Bot commented Jan 27, 2025

Copy link
Copy Markdown

Awesome work, congrats on your first merged pull request! You are invited to check our Issue Tracker for additional contributions.

@potiuk

potiuk commented Jan 27, 2025

Copy link
Copy Markdown
Member

Failures are on papermill provider, not related to this PR

Yep. already fixed in main

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:providers provider:cncf-kubernetes Kubernetes (k8s) provider related issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants