diff --git a/providers/cncf/kubernetes/src/airflow/providers/cncf/kubernetes/operators/pod.py b/providers/cncf/kubernetes/src/airflow/providers/cncf/kubernetes/operators/pod.py index 1fafe9b216c8f..9f59fcb66d368 100644 --- a/providers/cncf/kubernetes/src/airflow/providers/cncf/kubernetes/operators/pod.py +++ b/providers/cncf/kubernetes/src/airflow/providers/cncf/kubernetes/operators/pod.py @@ -1228,12 +1228,13 @@ def cleanup( istio_enabled = self.is_istio_enabled(remote_pod) pod_phase = remote_pod.status.phase if hasattr(remote_pod, "status") else None + should_keep = self.on_finish_action in { + OnFinishAction.KEEP_POD, + OnFinishAction.DELETE_ACTIVE_POD, + } + # if the pod fails or success, but we don't want to delete it - if ( - pod_phase != PodPhase.SUCCEEDED - or self.on_finish_action == OnFinishAction.KEEP_POD - or self.on_finish_action == OnFinishAction.DELETE_ACTIVE_POD - ): + if pod_phase != PodPhase.SUCCEEDED or should_keep: self.patch_already_checked(remote_pod, reraise=False) if istio_enabled or self.do_xcom_push: