Use pagination when listing pods 55/141355/4 master
authorFiete Ostkamp <Fiete.Ostkamp@telekom.de>
Mon, 23 Jun 2025 10:08:33 +0000 (12:08 +0200)
committerFiete Ostkamp <fiete.ostkamp@telekom.de>
Mon, 23 Jun 2025 10:18:03 +0000 (10:18 +0000)
- use pagination to reduce memory consumption/prevent
  OOM kills when there is a very large number of pods
  in the cluster (i.e 1000+)
- we have to fetch a list of pods, since the kubernetes api
  does not support fuzzy matches for fields and the field
  that we are filtering for (`metadata.name`) may contain
  dynamic elements (like some -sha-1234 suffix)
- update python dependencies to their latest versions
  -> requests (2.31.0 -> 2.32.4)
  -> kubernetes (29.0.0 -> 33.1.0)

Issue-ID: INT-2325
Change-Id: I9df0aec35c13b8c6c55db3ee22784a30d033f586
Signed-off-by: Fiete Ostkamp <Fiete.Ostkamp@telekom.de>
ready.py
requirements.txt
version.properties

index 4bd62a9..f53d845 100755 (executable)
--- a/ready.py
+++ b/ready.py
@@ -295,11 +295,23 @@ def fetch_pod_and_check_if_ready(pod_name):
     ready = False
     log.info("Checking if pod %s is ready", pod_name)
     try:
-        response = coreV1Api.list_namespaced_pod(namespace=namespace,
-                                                 watch=False)
-        for pod in response.items:
-          if (pod.metadata.name.startswith(pod_name)):
-            ready = is_pod_ready(pod)
+        _continue = ""
+        while True:
+            if not _continue:
+                response = coreV1Api.list_namespaced_pod(namespace=namespace, watch=False, limit=300)
+            else:
+                response = coreV1Api.list_namespaced_pod(namespace=namespace, watch=False, limit=300, _continue=_continue)
+
+            for pod in response.items:
+                if (pod.metadata.name.startswith(pod_name)):
+                    ready = is_pod_ready(pod)
+                    break
+
+            _continue = response._metadata._continue
+
+            if _continue is None:
+                break
+
     except ApiException as exc:
         log.error("Exception when calling list_namespaced_pod: %s\n", exc)
     return ready
@@ -457,6 +469,7 @@ def main(argv):
     url = DEF_URL
     ns = ""
     interval=None
+
     try:
         opts, _args = getopt.getopt(argv, "hj:s:c:p:a:t:m:u:n:i:", ["service-name=",
                                                     "container-name=",
@@ -467,7 +480,7 @@ def main(argv):
                                                     "url=",
                                                     "job-name=",
                                                     "namespace=",
-                                                    "interval="
+                                                    "interval=",
                                                     "help"])
         for opt, arg in opts:
             if opt in ("-h", "--help"):
index ca17c50..27ca490 100644 (file)
@@ -1,2 +1,2 @@
-requests==2.31.0
-kubernetes==29.0.0
+requests==2.32.4
+kubernetes==33.1.0
index e164ca9..4f3cf83 100644 (file)
@@ -3,8 +3,8 @@
 # because they are used in Jenkins, whose plug-in doesn't support
 
 major=6
-minor=1
-patch=2
+minor=3
+patch=0
 
 base_version=${major}.${minor}.${patch}