You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "insomnes (via GitHub)" <gi...@apache.org> on 2025/02/28 01:12:34 UTC
[PR] Retry k8s API requests in `KubernetesPodTrigger` [airflow]
insomnes opened a new pull request, #47187:
URL: https://github.com/apache/airflow/pull/47187
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
c
<!--
Thank you for contributing! Please make sure that your code changes
are covered with tests. And in case of new features or big changes
remember to adjust the documentation.
Feel free to ping committers for the review!
In case of an existing issue, reference it using one of the following:
closes: #ISSUE
related: #ISSUE
How to write a good git commit message:
http://chris.beams.io/posts/git-commit/
-->
There is only one method calling the k8s API in `KubernetesPodTrigger` -> `hook.get_pod`, so it was covered by
`@tenacity.retry` the same way as `PodManager.read_pod`.
Misc:
- Deleted `_get_async_hook` as was stated in the `TODO`
closes: #46908
<!-- Please keep an empty line above the dashes. -->
---
**^ Add meaningful description above**
Read the **[Pull Request Guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#pull-request-guidelines)** for more information.
In case of fundamental code changes, an Airflow Improvement Proposal ([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvement+Proposals)) is needed.
In case of a new dependency, check compliance with the [ASF 3rd Party License Policy](https://www.apache.org/legal/resolved.html#category-x).
In case of backwards incompatible changes please leave a note in a newsfragment file, named `{pr_number}.significant.rst` or `{issue_number}.significant.rst`, in [newsfragments](https://github.com/apache/airflow/tree/main/newsfragments).
--
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: [PR] Retry k8s API requests in `KubernetesPodTrigger` [airflow]
Posted by "bugraoz93 (via GitHub)" <gi...@apache.org>.
bugraoz93 commented on PR #47187:
URL: https://github.com/apache/airflow/pull/47187#issuecomment-2692183393
> Thank you @bugraoz93 ! Could you please clarify a bit on what should be done? I don't get it about the operator and the new condition.
We could add a small test to see if the operator going into the new condition. I mean when the status of the event is an `error`, we can see if the log is triggered via mocking the log. Not sure if being a perfectionist here :)
https://github.com/apache/airflow/blob/fd21b6169a8bda672f2ace40e0c5939d06c80efa/providers/cncf/kubernetes/src/airflow/providers/cncf/kubernetes/operators/pod.py#L837-L838
--
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: [PR] Retry k8s API requests in `KubernetesPodTrigger` [airflow]
Posted by "dstandish (via GitHub)" <gi...@apache.org>.
dstandish merged PR #47187:
URL: https://github.com/apache/airflow/pull/47187
--
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: [PR] Retry k8s API requests in `KubernetesPodTrigger` [airflow]
Posted by "dstandish (via GitHub)" <gi...@apache.org>.
dstandish commented on code in PR #47187:
URL: https://github.com/apache/airflow/pull/47187#discussion_r1977934884
##########
providers/cncf/kubernetes/src/airflow/providers/cncf/kubernetes/triggers/pod.py:
##########
@@ -257,19 +259,30 @@ async def _wait_for_container_completion(self) -> TriggerEvent:
self.log.debug("Sleeping for %s seconds.", self.poll_interval)
await asyncio.sleep(self.poll_interval)
- def _get_async_hook(self) -> AsyncKubernetesHook:
- # TODO: Remove this method when the min version of kubernetes provider is 7.12.0 in Google provider.
+ @tenacity.retry(stop=tenacity.stop_after_attempt(3), wait=tenacity.wait_exponential(), reraise=True)
+ async def _get_pod(self) -> V1Pod:
+ """
+ Get the pod from Kubernetes.
+
+ Separate method for retrying. Retry logic here should mimic the retry logic in
+ PodManager.read_pod method.
+ """
+ pod = await self.hook.get_pod(name=self.pod_name, namespace=self.pod_namespace)
+ # Due to AsyncKubernetesHook overriding get_pod, we need to cast the return
+ # value to kubernetes_asyncio.V1Pod, because it's perceived as different type
+ if TYPE_CHECKING:
+ pod = cast(V1Pod, pod)
+ return pod
Review Comment:
lesser of two evils i'd say, to reduce the noise. i don't think the import is of much consequence.
--
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: [PR] Retry k8s API requests in `KubernetesPodTrigger` [airflow]
Posted by "dstandish (via GitHub)" <gi...@apache.org>.
dstandish commented on code in PR #47187:
URL: https://github.com/apache/airflow/pull/47187#discussion_r1977944589
##########
providers/cncf/kubernetes/src/airflow/providers/cncf/kubernetes/operators/pod.py:
##########
@@ -834,6 +834,8 @@ def trigger_reentry(self, context: Context, event: dict[str, Any]) -> Any:
last_log_time = event.get("last_log_time")
if event["status"] in ("error", "failed", "timeout"):
+ if event["status"] == "error":
+ self.log.error("Trigger emitted an error event, failing the task: %s", event["message"])
Review Comment:
you could use a walrus op to get the status and reuse that. -- optionally, just a thought. might be ugly. choose your adventure
--
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: [PR] Retry k8s API requests in `KubernetesPodTrigger` [airflow]
Posted by "insomnes (via GitHub)" <gi...@apache.org>.
insomnes commented on PR #47187:
URL: https://github.com/apache/airflow/pull/47187#issuecomment-2689484557
I am also unsure about the propagation of these changes to `GKEStartPodTrigger`.
--
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: [PR] Retry k8s API requests in `KubernetesPodTrigger` [airflow]
Posted by "dstandish (via GitHub)" <gi...@apache.org>.
dstandish commented on code in PR #47187:
URL: https://github.com/apache/airflow/pull/47187#discussion_r1977941230
##########
providers/cncf/kubernetes/src/airflow/providers/cncf/kubernetes/triggers/pod.py:
##########
@@ -257,6 +259,21 @@ async def _wait_for_container_completion(self) -> TriggerEvent:
self.log.debug("Sleeping for %s seconds.", self.poll_interval)
await asyncio.sleep(self.poll_interval)
+ @tenacity.retry(stop=tenacity.stop_after_attempt(3), wait=tenacity.wait_exponential(), reraise=True)
+ async def _get_pod(self) -> V1Pod:
+ """
+ Get the pod from Kubernetes.
+
+ Separate method for retrying. Retry logic here should mimic the retry logic in
+ PodManager.read_pod method.
+ """
Review Comment:
```suggestion
"""Get the pod from Kubernetes with retries."""
```
--
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: [PR] Retry k8s API requests in `KubernetesPodTrigger` [airflow]
Posted by "insomnes (via GitHub)" <gi...@apache.org>.
insomnes commented on code in PR #47187:
URL: https://github.com/apache/airflow/pull/47187#discussion_r1978002246
##########
providers/cncf/kubernetes/src/airflow/providers/cncf/kubernetes/operators/pod.py:
##########
@@ -834,6 +834,8 @@ def trigger_reentry(self, context: Context, event: dict[str, Any]) -> Any:
last_log_time = event.get("last_log_time")
if event["status"] in ("error", "failed", "timeout"):
+ if event["status"] == "error":
+ self.log.error("Trigger emitted an error event, failing the task: %s", event["message"])
Review Comment:
I removed the status condition check and added it to the log.
--
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: [PR] Retry k8s API requests in `KubernetesPodTrigger` [airflow]
Posted by "dstandish (via GitHub)" <gi...@apache.org>.
dstandish commented on code in PR #47187:
URL: https://github.com/apache/airflow/pull/47187#discussion_r1977944589
##########
providers/cncf/kubernetes/src/airflow/providers/cncf/kubernetes/operators/pod.py:
##########
@@ -834,6 +834,8 @@ def trigger_reentry(self, context: Context, event: dict[str, Any]) -> Any:
last_log_time = event.get("last_log_time")
if event["status"] in ("error", "failed", "timeout"):
+ if event["status"] == "error":
+ self.log.error("Trigger emitted an error event, failing the task: %s", event["message"])
Review Comment:
you could use a walrus op to get the status and reuse that.
--
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: [PR] Retry k8s API requests in `KubernetesPodTrigger` [airflow]
Posted by "insomnes (via GitHub)" <gi...@apache.org>.
insomnes commented on PR #47187:
URL: https://github.com/apache/airflow/pull/47187#issuecomment-2709816733
Up
--
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: [PR] Retry k8s API requests in `KubernetesPodTrigger` [airflow]
Posted by "insomnes (via GitHub)" <gi...@apache.org>.
insomnes commented on PR #47187:
URL: https://github.com/apache/airflow/pull/47187#issuecomment-2692311955
> We could add a small test to see if the operator going into the new condition. I mean when the status of the event is an error, we can see if the log is triggered via mocking the log
I've added this small check to the existing exception-throwing test for error event
--
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: [PR] Retry k8s API requests in `KubernetesPodTrigger` [airflow]
Posted by "insomnes (via GitHub)" <gi...@apache.org>.
insomnes commented on PR #47187:
URL: https://github.com/apache/airflow/pull/47187#issuecomment-2695111553
> can you please split up this into distinct PRs that are focused on one thing at a time. This is supposed to be about retries but, it's got other elective stuff going on here.
Sure, I've deleted the unrelated change
--
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: [PR] Retry k8s API requests in `KubernetesPodTrigger` [airflow]
Posted by "dstandish (via GitHub)" <gi...@apache.org>.
dstandish commented on PR #47187:
URL: https://github.com/apache/airflow/pull/47187#issuecomment-2695081779
@insomnes can you please split up this into distinct PRs that are focused on one thing at a time. This is supposed to be about retries but, it's got other elective stuff going on here. I just want to see one that implements the retry behavior. Then we can look at the others stuff separately and in a focused manner please. Thank you
--
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: [PR] Retry k8s API requests in `KubernetesPodTrigger` [airflow]
Posted by "dstandish (via GitHub)" <gi...@apache.org>.
dstandish commented on code in PR #47187:
URL: https://github.com/apache/airflow/pull/47187#discussion_r1977943898
##########
providers/cncf/kubernetes/src/airflow/providers/cncf/kubernetes/operators/pod.py:
##########
@@ -834,6 +834,8 @@ def trigger_reentry(self, context: Context, event: dict[str, Any]) -> Any:
last_log_time = event.get("last_log_time")
if event["status"] in ("error", "failed", "timeout"):
+ if event["status"] == "error":
+ self.log.error("Trigger emitted an error event, failing the task: %s", event["message"])
Review Comment:
Since we unconditionally raise after this point, why only log in the `error` case?
I would just say `trigger exited with status {status}; failing the task` or something -- no matter the status. might as well cover all the cases.
--
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: [PR] Retry k8s API requests in `KubernetesPodTrigger` [airflow]
Posted by "insomnes (via GitHub)" <gi...@apache.org>.
insomnes commented on PR #47187:
URL: https://github.com/apache/airflow/pull/47187#issuecomment-2689481823
I was trying to understand if it's possible to configure the underlying generated client somehow, but it's complicated for now:
https://github.com/tomplus/kubernetes_asyncio/issues/288
--
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: [PR] Retry k8s API requests in `KubernetesPodTrigger` [airflow]
Posted by "dstandish (via GitHub)" <gi...@apache.org>.
dstandish commented on code in PR #47187:
URL: https://github.com/apache/airflow/pull/47187#discussion_r1977907395
##########
providers/cncf/kubernetes/src/airflow/providers/cncf/kubernetes/triggers/pod.py:
##########
@@ -257,19 +259,30 @@ async def _wait_for_container_completion(self) -> TriggerEvent:
self.log.debug("Sleeping for %s seconds.", self.poll_interval)
await asyncio.sleep(self.poll_interval)
- def _get_async_hook(self) -> AsyncKubernetesHook:
- # TODO: Remove this method when the min version of kubernetes provider is 7.12.0 in Google provider.
+ @tenacity.retry(stop=tenacity.stop_after_attempt(3), wait=tenacity.wait_exponential(), reraise=True)
+ async def _get_pod(self) -> V1Pod:
+ """
+ Get the pod from Kubernetes.
+
+ Separate method for retrying. Retry logic here should mimic the retry logic in
+ PodManager.read_pod method.
+ """
+ pod = await self.hook.get_pod(name=self.pod_name, namespace=self.pod_namespace)
+ # Due to AsyncKubernetesHook overriding get_pod, we need to cast the return
+ # value to kubernetes_asyncio.V1Pod, because it's perceived as different type
+ if TYPE_CHECKING:
+ pod = cast(V1Pod, pod)
+ return pod
Review Comment:
```suggestion
return cast(V1Pod, pod)
```
--
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: [PR] Retry k8s API requests in `KubernetesPodTrigger` [airflow]
Posted by "bugraoz93 (via GitHub)" <gi...@apache.org>.
bugraoz93 commented on PR #47187:
URL: https://github.com/apache/airflow/pull/47187#issuecomment-2692384222
CI is unrelated. The fix is coming in #47259. You may need to rebase later once more
--
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: [PR] Retry k8s API requests in `KubernetesPodTrigger` [airflow]
Posted by "bugraoz93 (via GitHub)" <gi...@apache.org>.
bugraoz93 commented on PR #47187:
URL: https://github.com/apache/airflow/pull/47187#issuecomment-2692253731
> > We could add a small test to see if the operator going into the new condition. I mean when the status of the event is an `error`, we can see if the log is triggered via mocking the log. Not sure if being a perfectionist here :)
>
> Thank you for the clarification!
>
> Now I see. Yes, that's very reasonable to check, especially with the comment mentioning the behaviour in the issue. I will try to add it later today.
Amazing, thanks!
--
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: [PR] Retry k8s API requests in `KubernetesPodTrigger` [airflow]
Posted by "insomnes (via GitHub)" <gi...@apache.org>.
insomnes commented on PR #47187:
URL: https://github.com/apache/airflow/pull/47187#issuecomment-2692064715
Thank you @bugraoz93 ! Could you please clarify a bit on what should be done? I don't get it about the operator and the new condition.
--
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: [PR] Retry k8s API requests in `KubernetesPodTrigger` [airflow]
Posted by "insomnes (via GitHub)" <gi...@apache.org>.
insomnes commented on code in PR #47187:
URL: https://github.com/apache/airflow/pull/47187#discussion_r1977922020
##########
providers/cncf/kubernetes/src/airflow/providers/cncf/kubernetes/triggers/pod.py:
##########
@@ -257,19 +259,30 @@ async def _wait_for_container_completion(self) -> TriggerEvent:
self.log.debug("Sleeping for %s seconds.", self.poll_interval)
await asyncio.sleep(self.poll_interval)
- def _get_async_hook(self) -> AsyncKubernetesHook:
- # TODO: Remove this method when the min version of kubernetes provider is 7.12.0 in Google provider.
+ @tenacity.retry(stop=tenacity.stop_after_attempt(3), wait=tenacity.wait_exponential(), reraise=True)
+ async def _get_pod(self) -> V1Pod:
+ """
+ Get the pod from Kubernetes.
+
+ Separate method for retrying. Retry logic here should mimic the retry logic in
+ PodManager.read_pod method.
+ """
+ pod = await self.hook.get_pod(name=self.pod_name, namespace=self.pod_namespace)
+ # Due to AsyncKubernetesHook overriding get_pod, we need to cast the return
+ # value to kubernetes_asyncio.V1Pod, because it's perceived as different type
+ if TYPE_CHECKING:
+ pod = cast(V1Pod, pod)
+ return pod
Review Comment:
This would require extracting `V1Pod` import outside of `if TYPE_CHECKING` import block. I am not sure that it is a reasonable thing to do here.
--
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: [PR] Retry k8s API requests in `KubernetesPodTrigger` [airflow]
Posted by "insomnes (via GitHub)" <gi...@apache.org>.
insomnes commented on PR #47187:
URL: https://github.com/apache/airflow/pull/47187#issuecomment-2692185418
> We could add a small test to see if the operator going into the new condition. I mean when the status of the event is an `error`, we can see if the log is triggered via mocking the log. Not sure if being a perfectionist here :)
Thank you for the clarification!
Now I see. Yes, that's very reasonable to check, especially with the comment mentioning the behaviour in the issue. I will try to add it later today.
--
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: [PR] Retry k8s API requests in `KubernetesPodTrigger` [airflow]
Posted by "insomnes (via GitHub)" <gi...@apache.org>.
insomnes commented on code in PR #47187:
URL: https://github.com/apache/airflow/pull/47187#discussion_r1979907638
##########
providers/cncf/kubernetes/src/airflow/providers/cncf/kubernetes/triggers/pod.py:
##########
@@ -257,19 +259,30 @@ async def _wait_for_container_completion(self) -> TriggerEvent:
self.log.debug("Sleeping for %s seconds.", self.poll_interval)
await asyncio.sleep(self.poll_interval)
- def _get_async_hook(self) -> AsyncKubernetesHook:
- # TODO: Remove this method when the min version of kubernetes provider is 7.12.0 in Google provider.
+ @tenacity.retry(stop=tenacity.stop_after_attempt(3), wait=tenacity.wait_exponential(), reraise=True)
+ async def _get_pod(self) -> V1Pod:
+ """
+ Get the pod from Kubernetes.
+
+ Separate method for retrying. Retry logic here should mimic the retry logic in
+ PodManager.read_pod method.
+ """
+ pod = await self.hook.get_pod(name=self.pod_name, namespace=self.pod_namespace)
+ # Due to AsyncKubernetesHook overriding get_pod, we need to cast the return
+ # value to kubernetes_asyncio.V1Pod, because it's perceived as different type
+ if TYPE_CHECKING:
+ pod = cast(V1Pod, pod)
+ return pod
Review Comment:
This is also fixed as suggested
--
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