ashb commented on a change in pull request #10315:
URL: https://github.com/apache/airflow/pull/10315#discussion_r483569475



##########
File path: airflow/providers/cncf/kubernetes/operators/kubernetes_pod.py
##########
@@ -408,17 +430,18 @@ def create_new_pod_for_operator(self, labels, launcher) 
-> Tuple[State, k8s.V1Po
 
         self.pod = pod
         self.log.debug("Starting pod:\n%s", yaml.safe_dump(pod.to_dict()))
+        final_state, result = None, None
         try:
             launcher.start_pod(
                 pod,
                 startup_timeout=self.startup_timeout_seconds)
             final_state, result = launcher.monitor_pod(pod=pod, 
get_logs=self.get_logs)
-        except AirflowException:
-            if self.log_events_on_failure:
-                for event in launcher.read_pod_events(pod).items:
-                    self.log.error("Pod Event: %s - %s", event.reason, 
event.message)
-            raise
         finally:
+            if final_state != State.SUCCESS:
+                # Before deleting the pod we get events and status of the pod 
(events can be fetched
+                # after pod deletion but not statuses). For consistency both 
are fetched before deletion.
+                self._log_pod_events_on_failure(pod, launcher)
+                self._log_pod_status_on_failure(pod, launcher)

Review comment:
       If either of these fail, the pod won't be deleted anymore.




----------------------------------------------------------------
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.

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


Reply via email to