From: Fiete Ostkamp Date: Mon, 23 Jun 2025 10:08:33 +0000 (+0200) Subject: Use pagination when listing pods X-Git-Url: https://gerrit.onap.org/r/gitweb?a=commitdiff_plain;h=dc132bd6d2113ca16674f76612a116329cfc5eff;p=oom%2Freadiness.git Use pagination when listing pods - 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 --- diff --git a/ready.py b/ready.py index 4bd62a9..f53d845 100755 --- 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"): diff --git a/requirements.txt b/requirements.txt index ca17c50..27ca490 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,2 @@ -requests==2.31.0 -kubernetes==29.0.0 +requests==2.32.4 +kubernetes==33.1.0 diff --git a/version.properties b/version.properties index e164ca9..4f3cf83 100644 --- a/version.properties +++ b/version.properties @@ -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}