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

pankaj 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 f3982aa2a4 Use startup_check_interval_seconds instead of poll_interval 
to check pod while startup (#38075)
f3982aa2a4 is described below

commit f3982aa2a4464acc6b5a5fe757aa3d2660c5197d
Author: Pankaj Singh <[email protected]>
AuthorDate: Mon Mar 18 13:12:12 2024 +0530

    Use startup_check_interval_seconds instead of poll_interval to check pod 
while startup (#38075)
    
    * Use startup_check_interval_seconds instead of poll_interval to check pod 
while startup
    
    * Update default value for startup_check_interval_seconds to 5 seconds
    
    * Reuse startup_check_interval
---
 airflow/providers/cncf/kubernetes/operators/pod.py   | 2 +-
 airflow/providers/cncf/kubernetes/triggers/pod.py    | 6 ++++--
 tests/providers/cncf/kubernetes/triggers/test_pod.py | 1 +
 3 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/airflow/providers/cncf/kubernetes/operators/pod.py 
b/airflow/providers/cncf/kubernetes/operators/pod.py
index e926a1f49d..410b94dd87 100644
--- a/airflow/providers/cncf/kubernetes/operators/pod.py
+++ b/airflow/providers/cncf/kubernetes/operators/pod.py
@@ -274,7 +274,7 @@ class KubernetesPodOperator(BaseOperator):
         labels: dict | None = None,
         reattach_on_restart: bool = True,
         startup_timeout_seconds: int = 120,
-        startup_check_interval_seconds: int = 1,
+        startup_check_interval_seconds: int = 5,
         get_logs: bool = True,
         container_logs: Iterable[str] | str | Literal[True] = 
BASE_CONTAINER_NAME,
         image_pull_policy: str | None = None,
diff --git a/airflow/providers/cncf/kubernetes/triggers/pod.py 
b/airflow/providers/cncf/kubernetes/triggers/pod.py
index 7cfb34a97e..82d8da1d8f 100644
--- a/airflow/providers/cncf/kubernetes/triggers/pod.py
+++ b/airflow/providers/cncf/kubernetes/triggers/pod.py
@@ -67,6 +67,7 @@ class KubernetesPodTrigger(BaseTrigger):
     :param in_cluster: run kubernetes client with in_cluster configuration.
     :param get_logs: get the stdout of the container as logs of the tasks.
     :param startup_timeout: timeout in seconds to start up the pod.
+    :param startup_check_interval: interval in seconds to check if the pod has 
already started.
     :param on_finish_action: What to do when the pod reaches its final state, 
or the execution is interrupted.
         If "delete_pod", the pod will be deleted regardless its state; if 
"delete_succeeded_pod",
         only succeeded pod will be deleted. You can set to "keep_pod" to keep 
the pod.
@@ -92,7 +93,7 @@ class KubernetesPodTrigger(BaseTrigger):
         in_cluster: bool | None = None,
         get_logs: bool = True,
         startup_timeout: int = 120,
-        startup_check_interval: int = 1,
+        startup_check_interval: int = 5,
         on_finish_action: str = "delete_pod",
         should_delete_pod: bool | None = None,
         last_log_time: DateTime | None = None,
@@ -145,6 +146,7 @@ class KubernetesPodTrigger(BaseTrigger):
                 "in_cluster": self.in_cluster,
                 "get_logs": self.get_logs,
                 "startup_timeout": self.startup_timeout,
+                "startup_check_interval": self.startup_check_interval,
                 "trigger_start_time": self.trigger_start_time,
                 "should_delete_pod": self.should_delete_pod,
                 "on_finish_action": self.on_finish_action.value,
@@ -223,7 +225,7 @@ class KubernetesPodTrigger(BaseTrigger):
             if not pod.status.phase == "Pending":
                 return self.define_container_state(pod)
             self.log.info("Still waiting for pod to start. The pod state is 
%s", pod.status.phase)
-            await asyncio.sleep(self.poll_interval)
+            await asyncio.sleep(self.startup_check_interval)
             delta = datetime.datetime.now(tz=datetime.timezone.utc) - 
self.trigger_start_time
         raise PodLaunchTimeoutException("Pod did not leave 'Pending' phase 
within specified timeout")
 
diff --git a/tests/providers/cncf/kubernetes/triggers/test_pod.py 
b/tests/providers/cncf/kubernetes/triggers/test_pod.py
index 93b1da5c92..5a4887297c 100644
--- a/tests/providers/cncf/kubernetes/triggers/test_pod.py
+++ b/tests/providers/cncf/kubernetes/triggers/test_pod.py
@@ -105,6 +105,7 @@ class TestKubernetesPodTrigger:
             "in_cluster": IN_CLUSTER,
             "get_logs": GET_LOGS,
             "startup_timeout": STARTUP_TIMEOUT_SECS,
+            "startup_check_interval": 5,
             "trigger_start_time": TRIGGER_START_TIME,
             "on_finish_action": ON_FINISH_ACTION,
             "should_delete_pod": ON_FINISH_ACTION == "delete_pod",

Reply via email to