From 8249f15812deeb2bde3f5ba581d0024efe4f8e54 Mon Sep 17 00:00:00 2001 From: Andreas Geissler Date: Mon, 8 Apr 2024 10:24:42 +0200 Subject: [READINESS] Add functionality to check services without Selector Services can be defined without Selector, but via EndpointSlices (https://kubernetes.io/docs/concepts/services-networking/service/#services-without-selectors) This was not covered by the ready.py and is now added. Issue-ID: OOM-3280 Change-Id: Ie386257bd6533cb735ab872b70a2ecd845ee424a Signed-off-by: Andreas Geissler --- ready.py | 38 +++++++++++++++----------------------- 1 file changed, 15 insertions(+), 23 deletions(-) diff --git a/ready.py b/ready.py index ac7a3ea..a8b1999 100755 --- a/ready.py +++ b/ready.py @@ -237,7 +237,7 @@ def is_service_ready(service_name): for k,v in svc.spec.selector.items(): selector += k + '=' + v + ',' selector = selector[:-1] - log.info("Selector %s", selector) + log.info("Found Selector %s", selector) # Get the pods that match the selector pods = coreV1Api.list_namespaced_pod(namespace=namespace, label_selector=selector, @@ -245,17 +245,19 @@ def is_service_ready(service_name): for item in pods.items: name = read_name(item) log.info("Found pod %s selected by service %s", name, service_name) - if item.metadata.owner_references[0].kind == "StatefulSet": - ready = wait_for_statefulset_complete(name) - elif item.metadata.owner_references[0].kind == "ReplicaSet": - deployment_name = get_deployment_name(name) - ready = wait_for_deployment_complete(deployment_name) - elif item.metadata.owner_references[0].kind == "Job": - ready = is_job_complete(name) - elif item.metadata.owner_references[0].kind == "DaemonSet": - ready = wait_for_daemonset_complete( - item.metadata.owner_references[0].name) - return ready + return is_pod_ready (name) + else: + log.info("No Selector found, check Endpoints") + endpoints = coreV1Api.list_namespaced_endpoints(namespace=namespace, + watch=False) + for ep in endpoints.items: + if (ep.metadata.name.startswith(service_name)): + if ep.subsets: + addresses = ep.subsets[0].addresses + if addresses: + name = addresses[0].target_ref.name + log.info("Found pod %s selected by service %s", name, service_name) + return is_pod_ready (name) except ApiException as exc: log.error("Exception when calling list_namespaced_service: %s\n", exc) return ready @@ -321,17 +323,7 @@ def is_app_ready(app_name): if item.metadata.labels.get('app', "NOKEY") == app_name: name = read_name(item) log.info("Found pod %s", name) - if item.metadata.owner_references[0].kind == "StatefulSet": - ready = wait_for_statefulset_complete(name) - elif item.metadata.owner_references[0].kind == "ReplicaSet": - deployment_name = get_deployment_name(name) - ready = wait_for_deployment_complete(deployment_name) - elif item.metadata.owner_references[0].kind == "Job": - ready = is_job_complete(name) - elif item.metadata.owner_references[0].kind == "DaemonSet": - ready = wait_for_daemonset_complete( - item.metadata.owner_references[0].name) - return ready + return is_pod_ready (name) except ApiException as exc: log.error("Exception when calling list_namespaced_pod: %s\n", exc) return ready -- cgit 1.2.3-korg