You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "miloszszymczak (via GitHub)" <gi...@apache.org> on 2025/03/11 08:57:03 UTC
[I] Google Cloud + CNCF Kubernetes OnFinishAction equality test [airflow]
miloszszymczak opened a new issue, #47601:
URL: https://github.com/apache/airflow/issues/47601
### Apache Airflow Provider(s)
cncf-kubernetes, google
### Versions of Apache Airflow Providers
_No response_
### Apache Airflow version
2.10.5
### Operating System
Linux
### Deployment
Other Docker-based deployment
### Deployment details
Using official Docker image in k8s (issue is related to usage of GKEStartPodOperator)
### What happened
Somewhere https://github.com/apache/airflow/blob/2b1c2758f41e438280380a1e11b61d6b0085ee7c/providers/google/src/airflow/providers/google/cloud/operators/kubernetes_engine.py#L641 a new approach to pod deletion is utilized so we are on par with CNCF k8s package enum OnFinishAction. Unfortunately the values set there don't compare with the values withing CNCF k8s package (maybe it's because differences in imports) resulting in failing equality tests here https://github.com/apache/airflow/blob/2b1c2758f41e438280380a1e11b61d6b0085ee7c/providers/cncf/kubernetes/src/airflow/providers/cncf/kubernetes/operators/pod.py#L1047
### What you think should happen instead
I guess another way to compare the enums could be used here so the pods are deleted if operator is properly configured.
### How to reproduce
Use GKEStartPodOperator to run a job in k8s environment with on_finish_action='DELETE_POD' - the pod will be kept with message "Skipping deleting pod" instead of deletion.
### Anything else
_No response_
### Are you willing to submit PR?
- [ ] Yes I am willing to submit a PR!
### Code of Conduct
- [x] I agree to follow this project's [Code of Conduct](https://github.com/apache/airflow/blob/main/CODE_OF_CONDUCT.md)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Google Cloud + CNCF Kubernetes OnFinishAction equality test [airflow]
Posted by "agomez-etsy (via GitHub)" <gi...@apache.org>.
agomez-etsy commented on issue #47601:
URL: https://github.com/apache/airflow/issues/47601#issuecomment-2988850159
👋 We also faced this error and found a workaround. Our setup:
* `Airflow Version 2.10.5`
* `apache-airflow-providers-cncf-kubernetes==10.1.0`
* `apache-airflow-providers-google==12.0.0`
The bug was introduced in the google provider 12.0.0, specifically in [this commit](https://github.com/apache/airflow/pull/44568/files#diff-f5760a834348cda4a0d190366066c1e16dc0ab9eb8a8e08a92948bbdb3465bfbR620).
`on_finish_action` was added to the list of `template_fields` of the `GKEStartPodOperator`, as shown in the screenshot

This causes `self.on_finish_action` to be rendered as a string (`OnFinishAction.DELETE_POD`) when the task is executed, instead of the original enum instance (`<OnFinishAction.DELETE_POD: 'delete_pod'>`), and hence the `should_delete_pod` [equality](https://github.com/apache/airflow/blob/providers-google/12.0.0/providers/src/airflow/providers/cncf/kubernetes/operators/pod.py#L989-L995) returns `False`.
```py3
self.on_finish_action == OnFinishAction.DELETE_POD
```
Some ideas for whoever wants to submit the PR:
### 1. Remove `on_finish_action` from `template_fields`
Simple, yet effective :).
### 2. Override `process_pod_deletion`
```py3
def process_pod_deletion(self, pod: k8s.V1Pod, *, reraise=True):
from airflow.providers.cncf.kubernetes.utils.pod_manager import OnFinishAction
if isinstance(self.on_finish_action, str):
# Handle the case where the enum was casted using `str(on_finish_action)`
# which results in a string like `OnFinishAction.DELETE_POD`
if self.on_finish_action.startswith("OnFinishAction."):
self.on_finish_action = OnFinishAction[self.on_finish_action.split(".")[-1]]
else:
# Handle the case where `on_finish_action = on_finish_action.value`
# which results in a string like `delete_pod`
try:
self.on_finish_action = OnFinishAction(self.on_finish_action)
except KeyError:
self.log.error(f"Invalid on_finish_action {self.on_finish_action}")
super().process_pod_deletion(pod, reraise)
```
### 3. Override `render_template_fields`
```py3
def render_template_fields(self, context: Context, jinja_env: Environment | None = None):
# Remove "on_finish_action" from template fields if it's not a jinja template string
# to prevent the enum from being casted as a string
if not (isinstance(self.on_finish_action, str) and "{{" in self.on_finish_action):
self.template_fields = [f for f in self.template_fields if f != "on_finish_action"]
super().render_template_fields(context, jinja_env)
```
We are using approach #2, but any of these _should_ work.
cc - @miloszszymczak
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Google Cloud + CNCF Kubernetes OnFinishAction equality test [airflow]
Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk closed issue #47601: Google Cloud + CNCF Kubernetes OnFinishAction equality test
URL: https://github.com/apache/airflow/issues/47601
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Google Cloud + CNCF Kubernetes OnFinishAction equality test [airflow]
Posted by "neko1437 (via GitHub)" <gi...@apache.org>.
neko1437 commented on issue #47601:
URL: https://github.com/apache/airflow/issues/47601#issuecomment-2952231722
### Apache Airflow Version
- `2.11.0`
### Apache Airflow Providers Versions
- `apache-airflow-providers-cncf-kubernetes==10.5.0`
- `apache-airflow-providers-google==15.1.0`
---
### Issue Description
I encountered the same issue when using the `GKEStartPodOperator` with `on_finish_action="delete_pod"`. Despite this configuration, the pod does **not** get deleted at the end of a task run. The task logs contain messages like:
```
"Skipping deleting pod ..."
```
---
### Diagnostics
To isolate the cause, I downgraded the `apache-airflow-providers-google` package step by step. I found that the issue was introduced in **version 12.0.0**. Everything works as expected when using:
- `apache-airflow-providers-cncf-kubernetes==10.5.0`
- `apache-airflow-providers-google==11.0.0`
With this combination, the pod is correctly deleted at the end of the task.
---
### Impact
This issue significantly affects task reliability. When a task fails and retries are enabled, the retry attempt gets **skipped** because it detects an existing pod (with the same labels) that was not cleaned up. This behavior undermines Airflow’s retry mechanism and can lead to missed or incomplete processing.
Given the potential for skipped retries and unintended side effects, I believe this is a **critical issue** that should be addressed.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Google Cloud + CNCF Kubernetes OnFinishAction equality test [airflow]
Posted by "boring-cyborg[bot] (via GitHub)" <gi...@apache.org>.
boring-cyborg[bot] commented on issue #47601:
URL: https://github.com/apache/airflow/issues/47601#issuecomment-2713214089
Thanks for opening your first issue here! Be sure to follow the issue template! If you are willing to raise PR to address this issue please do so, no need to wait for approval.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Google Cloud + CNCF Kubernetes OnFinishAction equality test [airflow]
Posted by "olegkachur-e (via GitHub)" <gi...@apache.org>.
olegkachur-e commented on issue #47601:
URL: https://github.com/apache/airflow/issues/47601#issuecomment-3150481375
I've checked it again and it is not reproducible now.
@potiuk Can we close it, pls?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Google Cloud + CNCF Kubernetes OnFinishAction equality test [airflow]
Posted by "olegkachur-e (via GitHub)" <gi...@apache.org>.
olegkachur-e commented on issue #47601:
URL: https://github.com/apache/airflow/issues/47601#issuecomment-3126735366
> ### 1. Remove `on_finish_action` from `template_fields`
> Simple, yet effective :).
Seems it's already been done in https://github.com/apache/airflow/pull/49637 and released in `google-provider==16.0.0`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org