This is an automated email from the ASF dual-hosted git repository.

jedcunningham pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new c8b86e6  Add more information to PodLauncher timeout error (#17953)
c8b86e6 is described below

commit c8b86e69e49e330ab2f551358a6998d5800adb9a
Author: James Lamb <[email protected]>
AuthorDate: Tue Oct 12 16:19:49 2021 -0500

    Add more information to PodLauncher timeout error (#17953)
---
 airflow/providers/cncf/kubernetes/utils/pod_launcher.py    |  9 +++++++--
 tests/providers/cncf/kubernetes/utils/test_pod_launcher.py | 14 ++++++++++++++
 2 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/airflow/providers/cncf/kubernetes/utils/pod_launcher.py 
b/airflow/providers/cncf/kubernetes/utils/pod_launcher.py
index 43bb513..d3a7c44 100644
--- a/airflow/providers/cncf/kubernetes/utils/pod_launcher.py
+++ b/airflow/providers/cncf/kubernetes/utils/pod_launcher.py
@@ -120,7 +120,8 @@ class PodLauncher(LoggingMixin):
         Launches the pod synchronously and waits for completion.
 
         :param pod:
-        :param startup_timeout: Timeout for startup of the pod (if pod is 
pending for too long, fails task)
+        :param startup_timeout: Timeout (in seconds) for startup of the pod
+            (if pod is pending for too long, fails task)
         :return:
         """
         resp = self.run_pod_async(pod)
@@ -130,7 +131,11 @@ class PodLauncher(LoggingMixin):
                 self.log.warning("Pod not yet started: %s", pod.metadata.name)
                 delta = dt.now() - curr_time
                 if delta.total_seconds() >= startup_timeout:
-                    raise AirflowException("Pod took too long to start")
+                    msg = (
+                        f"Pod took longer than {startup_timeout} seconds to 
start. "
+                        "Check the pod events in kubernetes to determine why."
+                    )
+                    raise AirflowException(msg)
                 time.sleep(1)
 
     def monitor_pod(self, pod: V1Pod, get_logs: bool) -> Tuple[State, V1Pod, 
Optional[str]]:
diff --git a/tests/providers/cncf/kubernetes/utils/test_pod_launcher.py 
b/tests/providers/cncf/kubernetes/utils/test_pod_launcher.py
index d485dec..74c910d 100644
--- a/tests/providers/cncf/kubernetes/utils/test_pod_launcher.py
+++ b/tests/providers/cncf/kubernetes/utils/test_pod_launcher.py
@@ -262,3 +262,17 @@ class TestPodLauncher(unittest.TestCase):
             self.pod_launcher.start_pod(mock.sentinel)
 
         assert mock_run_pod_async.call_count == 3
+
+    
@mock.patch("airflow.providers.cncf.kubernetes.utils.pod_launcher.PodLauncher.pod_not_started")
+    
@mock.patch("airflow.providers.cncf.kubernetes.utils.pod_launcher.PodLauncher.run_pod_async")
+    def test_start_pod_raises_informative_error_on_timeout(self, 
mock_run_pod_async, mock_pod_not_started):
+        pod_response = mock.MagicMock()
+        pod_response.status.start_time = None
+        mock_run_pod_async.return_value = pod_response
+        mock_pod_not_started.return_value = True
+        expected_msg = "Check the pod events in kubernetes"
+        with pytest.raises(AirflowException, match=expected_msg):
+            self.pod_launcher.start_pod(
+                pod=mock.sentinel,
+                startup_timeout=0,
+            )

Reply via email to