Repository navigation
Description
Apache Airflow version
2.2.2
What happened
When running multiple KubernetesPodOperators with random_name_suffix=False and is_delete_pod_operator=True the following will happen:
- The first task will create the Pod
my-pod - The second task will attempt to create the pod, but fail with a 409 response from the API server (this is expected)
- The second task will delete
my-pod, because it hasis_delete_pod_operator=Trueand the Pod name is consistent between the two tasks. This is unexpected and will cause the first task to fail as well.
I understand that this is a rare circumstance, but I think its still worth fixing as anyone using random_name_suffix=False in an otherwise default KubernetesPodOperator may result in other pods being killed.
As a possible fix, we could find_pod before deleting, to ensure that the pod being deleted has the appropriate execution_date label:
airflow/airflow/providers/cncf/kubernetes/utils/pod_launcher.py
Lines 103 to 112 in ad07923
| def delete_pod(self, pod: V1Pod) -> None: | |
| """Deletes POD""" | |
| try: | |
| self._client.delete_namespaced_pod( | |
| pod.metadata.name, pod.metadata.namespace, body=client.V1DeleteOptions() | |
| ) | |
| except ApiException as e: | |
| # If the pod is already deleted | |
| if e.status != 404: | |
| raise |
Let me know if you have any other suggestions for how this could be fixed, or if this should just be considered expected behaviour when using fixed Kubernetes Pod IDs.
What you expected to happen
The second task should be able to fail without deleting the pod from the first task.
How to reproduce
Create a DAG with a single KubernetesPodOperator with random_name_suffix=False and is_delete_pod_operator=True and run it twice in parallel.
Operating System
Debian GNU/Linux 10 (buster)
Versions of Apache Airflow Providers
apache-airflow-providers-cncf-kubernetes=2.2.0
Deployment
Other 3rd-party Helm chart
Deployment details
No response
Anything else
No response
Are you willing to submit PR?
- Yes I am willing to submit a PR!
Code of Conduct
- I agree to follow this project's Code of Conduct
Activity
ferruzzi commentedon Jan 27, 2022
Interesting combination of events. Another possible solution might be to check the failure cause before calling delete_pod, if it failed because the pod already existed, then don't delete it?
SamWheating commentedon Aug 24, 2022
This was fixed in #22092