You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "paramjeet01 (via GitHub)" <gi...@apache.org> on 2024/05/18 15:30:00 UTC
[PR] Updated kuberentes pod operator to find pods only in running state [airflow]
paramjeet01 opened a new pull request, #39702:
URL: https://github.com/apache/airflow/pull/39702
The proposed changes to the [find_pod](https://github.com/apache/airflow/blob/2.8.3/airflow/providers/cncf/kubernetes/operators/pod.py#L535) method will ensure it selects only pods that are in the running state, effectively ignoring pods that are in the terminating state. This adjustment addresses the issue of pods remaining in the terminating state for an extended period.
closes: https://github.com/apache/airflow/issues/39096
related: https://github.com/apache/airflow/issues/39096
---
--
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] Updated kuberentes pod operator to find pods only in running state [airflow]
Posted by "paramjeet01 (via GitHub)" <gi...@apache.org>.
paramjeet01 commented on code in PR #39702:
URL: https://github.com/apache/airflow/pull/39702#discussion_r1606269684
##########
airflow/providers/cncf/kubernetes/operators/pod.py:
##########
@@ -532,11 +532,12 @@ def find_pod(self, namespace: str, context: Context, *, exclude_checked: bool =
).items
pod = None
- num_pods = len(pod_list)
+ running_pods = [pod for pod in pod_list if pod.status.phase == "Running"]
Review Comment:
Initial commit , I have set `find_pod` block after `await_pod_start` so we'll have only running pods but removed it later as recently introduced callbacks uses `remote_pod` for `on_pod_creation` in `execute_sync`. Now , I have added support for pending pods.
--
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] Updated kuberentes pod operator to find pods only in running state [airflow]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #39702:
URL: https://github.com/apache/airflow/pull/39702#issuecomment-2259398931
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 5 days if no further activity occurs. Thank you for your contributions.
--
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] Updated kuberentes pod operator to find pods only in running state [airflow]
Posted by "dirrao (via GitHub)" <gi...@apache.org>.
dirrao commented on code in PR #39702:
URL: https://github.com/apache/airflow/pull/39702#discussion_r1606205201
##########
airflow/providers/cncf/kubernetes/operators/pod.py:
##########
@@ -532,11 +532,12 @@ def find_pod(self, namespace: str, context: Context, *, exclude_checked: bool =
).items
pod = None
- num_pods = len(pod_list)
+ running_pods = [pod for pod in pod_list if pod.status.phase == "Running"]
Review Comment:
How about the pod which is in pending state? It will result in launching another application pod which is not need.
--
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] Updated kuberentes pod operator to find pods only in running state [airflow]
Posted by "paramjeet01 (via GitHub)" <gi...@apache.org>.
paramjeet01 commented on PR #39702:
URL: https://github.com/apache/airflow/pull/39702#issuecomment-2118866883
@eladkal , When a node is drained in eks due to aws ec2 spot instance interruption or due to some other reasons , usually controllers will detect that the pods have been terminated and will schedule new pods on other available nodes to maintain the desired number of replicas but in our our case airflow deploy pods without controller. So , sometimes the pods stuck in terminating state for a while till kubernetes reconsiders it and terminates.
The issue I'm trying to address is the above case where the pods are stuck in terminating state and not the completed ones , the [find_pod](https://github.com/apache/airflow/blob/2.8.3/airflow/providers/cncf/kubernetes/operators/pod.py#L535) method is used to get pods based on labels and later used in cleanup method.
--
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] Updated kuberentes pod operator to find pods only in running state [airflow]
Posted by "romsharon98 (via GitHub)" <gi...@apache.org>.
romsharon98 commented on PR #39702:
URL: https://github.com/apache/airflow/pull/39702#issuecomment-2170429794
Can you add tests for this 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] Updated kuberentes pod operator to find pods only in running state [airflow]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] closed pull request #39702: Updated kuberentes pod operator to find pods only in running state
URL: https://github.com/apache/airflow/pull/39702
--
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] Updated kuberentes pod operator to find pods only in running state [airflow]
Posted by "paramjeet01 (via GitHub)" <gi...@apache.org>.
paramjeet01 commented on code in PR #39702:
URL: https://github.com/apache/airflow/pull/39702#discussion_r1605983417
##########
airflow/providers/cncf/kubernetes/operators/pod.py:
##########
@@ -597,13 +598,14 @@ def execute_sync(self, context: Context):
ti.xcom_push(key="pod_name", value=self.pod.metadata.name)
ti.xcom_push(key="pod_namespace", value=self.pod.metadata.namespace)
- # get remote pod for use in cleanup methods
- self.remote_pod = self.find_pod(self.pod.metadata.namespace, context=context)
if self.callbacks:
self.callbacks.on_pod_creation(
pod=self.remote_pod, client=self.client, mode=ExecutionMode.SYNC
)
self.await_pod_start(pod=self.pod)
+
+ # get remote pod for use in cleanup methods
+ self.remote_pod = self.find_pod(self.pod.metadata.namespace, context=context)
Review Comment:
Moved `remote_pod` after `await_pod_start` , so that the `find_pod` method will properly choose the running pods as pending pods won't be picked up by `find_pod` method. Pardon , I just now saw that we implemented callbacks, I'll move the block below.
--
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] Updated kuberentes pod operator to find pods only in running state [airflow]
Posted by "paramjeet01 (via GitHub)" <gi...@apache.org>.
paramjeet01 commented on PR #39702:
URL: https://github.com/apache/airflow/pull/39702#issuecomment-2119259082
> @paramjeet01 We have retries with retry_delay of 5 mins. If the pod is still stuck in terminating state or whatever, then Kubernetes cluster is not working as expected. I believe we can't handle all these kind of situations in the airflow. Better to fix this issue in Kubernetes. @jedcunningham / @hussein-awala WDYT?
@dirrao Agreed , We can check the kubernetes and solve this issue but we have an existing problem of creating pods on each retry and not cleaned up properly when the find pod returns more than one 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] Updated kuberentes pod operator to find pods only in running state [airflow]
Posted by "hussein-awala (via GitHub)" <gi...@apache.org>.
hussein-awala commented on code in PR #39702:
URL: https://github.com/apache/airflow/pull/39702#discussion_r1605979210
##########
airflow/providers/cncf/kubernetes/operators/pod.py:
##########
@@ -597,13 +598,14 @@ def execute_sync(self, context: Context):
ti.xcom_push(key="pod_name", value=self.pod.metadata.name)
ti.xcom_push(key="pod_namespace", value=self.pod.metadata.namespace)
- # get remote pod for use in cleanup methods
- self.remote_pod = self.find_pod(self.pod.metadata.namespace, context=context)
if self.callbacks:
self.callbacks.on_pod_creation(
pod=self.remote_pod, client=self.client, mode=ExecutionMode.SYNC
)
self.await_pod_start(pod=self.pod)
+
+ # get remote pod for use in cleanup methods
+ self.remote_pod = self.find_pod(self.pod.metadata.namespace, context=context)
Review Comment:
Why do you need to move this block? The value of `remote_pod` is used in the previous block
--
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] Updated kuberentes pod operator to find pods only in running state [airflow]
Posted by "boring-cyborg[bot] (via GitHub)" <gi...@apache.org>.
boring-cyborg[bot] commented on PR #39702:
URL: https://github.com/apache/airflow/pull/39702#issuecomment-2118858289
Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contributors' Guide (https://github.com/apache/airflow/blob/main/contributing-docs/README.rst)
Here are some useful points:
- Pay attention to the quality of your code (ruff, mypy and type annotations). Our [pre-commits]( https://github.com/apache/airflow/blob/main/contributing-docs/08_static_code_checks.rst#prerequisites-for-pre-commit-hooks) will help you with that.
- In case of a new feature add useful documentation (in docstrings or in `docs/` directory). Adding a new operator? Check this short [guide](https://github.com/apache/airflow/blob/main/docs/apache-airflow/howto/custom-operator.rst) Consider adding an example DAG that shows how users should use it.
- Consider using [Breeze environment](https://github.com/apache/airflow/blob/main/dev/breeze/doc/README.rst) for testing locally, it's a heavy docker but it ships with a working Airflow and a lot of integrations.
- Be patient and persistent. It might take some time to get a review or get the final approval from Committers.
- Please follow [ASF Code of Conduct](https://www.apache.org/foundation/policies/conduct) for all communication including (but not limited to) comments on Pull Requests, Mailing list and Slack.
- Be sure to read the [Airflow Coding style]( https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#coding-style-and-best-practices).
- Always keep your Pull Requests rebased, otherwise your build might fail due to changes not related to your commits.
Apache Airflow is a community-driven project and together we are making it better 🚀.
In case of doubts contact the developers at:
Mailing List: dev@airflow.apache.org
Slack: https://s.apache.org/airflow-slack
--
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] Updated kuberentes pod operator to find pods only in running state [airflow]
Posted by "eladkal (via GitHub)" <gi...@apache.org>.
eladkal commented on PR #39702:
URL: https://github.com/apache/airflow/pull/39702#issuecomment-2118860541
> This adjustment addresses the issue of pods remaining in the terminating state for an extended period.
Is that right?
Completed is also terminated state is it not? Why reataching to complected pod is considered wrong?
--
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] Updated kuberentes pod operator to find pods only in running state [airflow]
Posted by "paramjeet01 (via GitHub)" <gi...@apache.org>.
paramjeet01 commented on PR #39702:
URL: https://github.com/apache/airflow/pull/39702#issuecomment-2118858855
@dirrao , please help to review the above changes.
--
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] Updated kuberentes pod operator to find pods only in running state [airflow]
Posted by "dirrao (via GitHub)" <gi...@apache.org>.
dirrao commented on PR #39702:
URL: https://github.com/apache/airflow/pull/39702#issuecomment-2119106988
@paramjeet01
We have retries with retry_delay of 5 mins. If the pod is still stuck in terminating state or whatever, then Kubernetes cluster is not working as expected. I believe we can't handle all these kind of situations in the airflow. Better to fix this issue in Kubernetes.
@jedcunningham / @hussein-awala WDYT?
--
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