amoghrajesh commented on code in PR #77197:
URL: https://github.com/apache/airflow/pull/77197#discussion_r4715797710


##########
providers/cncf/kubernetes/src/airflow/providers/cncf/kubernetes/operators/pod.py:
##########
@@ -1435,6 +1461,15 @@ def cleanup(
         if self._killed or not remote_pod:
             return
 
+        if self._keep_pod_after_timeout:
+            self.log.info(
+                "Task interrupted by execution_timeout and on_kill_action is 
%r, keeping pod %s "
+                "so the next try can reattach.",
+                self.on_kill_action.value,
+                cast("k8s.V1ObjectMeta", remote_pod.metadata).name,
+            )
+            return

Review Comment:
   Handled in 922d4219235



##########
providers/cncf/kubernetes/src/airflow/providers/cncf/kubernetes/operators/pod.py:
##########
@@ -779,6 +788,11 @@ def get_or_create_pod(self, pod_request_obj: k8s.V1Pod, 
context: Context) -> k8s
 
                 if pod_phase == PodPhase.SUCCEEDED:
                     Stats.incr("resumable_job.already_succeeded", 
tags=stats_tags)
+                    # Without XCom there is nothing left to read from the pod, 
so a pod that finished
+                    # after its try was interrupted (e.g. a kept pod after a 
timeout) is this try's run.
+                    if not self.do_xcom_push:

Review Comment:
   Handled in 922d4219235



##########
providers/cncf/kubernetes/src/airflow/providers/cncf/kubernetes/operators/pod.py:
##########
@@ -942,6 +956,18 @@ def execute_sync(self, context: Context):
             self.remote_pod = self.pod_manager.await_pod_completion(
                 self.pod, istio_enabled, self.base_container_name, 
self.do_xcom_push
             )
+        except AirflowTaskTimeout:
+            # The task runner calls on_kill only after this propagates, so 
cleanup has to know now
+            # that the pod must be left running for the next try to reattach. 
A retry_policy (Airflow
+            # 3.3+) can fail the task with tries left, which would leave the 
kept pod running forever.
+            ti = context["ti"]
+            self._keep_pod_after_timeout = (
+                self.reattach_on_restart
+                and self.on_kill_action == OnKillAction.KEEP_POD
+                and ti.try_number <= ti.max_tries
+                and getattr(self, "retry_policy", None) is None

Review Comment:
   Handled in 922d4219235



##########
providers/cncf/kubernetes/docs/operators.rst:
##########
@@ -243,6 +243,12 @@ persisted, the operator falls back to the same label 
search ``reattach_on_restar
 used, so a running pod from a prior attempt is still found and reattached to 
rather than
 duplicated. Once an identity is persisted, subsequent retries skip the label 
search entirely.
 
+By default, a try interrupted by ``execution_timeout`` deletes the pod (per 
``on_finish_action``), so the retry
+starts a fresh pod. To let the retry reattach instead, set 
``on_kill_action="keep_pod"``: the pod is left running
+and is not marked as already checked. On the last try no retry follows, so the 
pod is cleaned up as usual.

Review Comment:
   Handled in 922d4219235



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to