From 041b45bb94da301d720b9c2c6bef9bdab05e9b46 Mon Sep 17 00:00:00 2001 From: Malar Invention Date: Sun, 12 Jan 2025 16:16:25 +0530 Subject: [PATCH] logs: add debug logs --- node_external_ip_controller_async.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/node_external_ip_controller_async.py b/node_external_ip_controller_async.py index 655b4e7..26273af 100644 --- a/node_external_ip_controller_async.py +++ b/node_external_ip_controller_async.py @@ -13,7 +13,7 @@ SERVICE_REQUEST_TIMEOUT = int(os.getenv("SERVICE_REQUEST_TIMEOUT", 300)) NODE_REQUEST_TIMEOUT = int(os.getenv("NODE_REQUEST_TIMEOUT", 30)) # Logging configuration -logging.basicConfig(level=logging.INFO) +logging.basicConfig(level=logging.DEBUG) logger = logging.getLogger(__name__) @@ -21,16 +21,22 @@ async def update_service_annotation(v1, service, external_ips): try: service_name = service.metadata.name namespace = service.metadata.namespace + logger.debug(f"Fetching service {service_name} in namespace {namespace}") service_obj = await v1.read_namespaced_service(service_name, namespace) current_annotation = service_obj.metadata.annotations.get(ANNOTATION_KEY) target_annotation = ",".join(external_ips) + "," + ZERO_GATEWAY_IP + logger.debug(f"Current annotation: {current_annotation}") + logger.debug(f"Target annotation: {target_annotation}") if current_annotation != target_annotation: body = {"metadata": {"annotations": {ANNOTATION_KEY: target_annotation}}} + logger.debug(f"Patching service {service_name} with body: {body}") await v1.patch_namespaced_service(service_name, namespace, body) logger.info( f"Updated service {service_name} with new external IP: {target_annotation}" ) + else: + logger.debug(f"No update required for service {service_name}") except client.exceptions.ApiException as e: logger.error(f"API Exception in update_service_annotation: {e}") @@ -40,19 +46,24 @@ async def watch_nodes(v1, external_ips_update_queue): w = watch.Watch() while True: try: + logger.debug("Starting to watch nodes") async for event in w.stream( v1.list_node, label_selector=NODE_LABEL, _request_timeout=NODE_REQUEST_TIMEOUT, ): node = event["object"] + logger.debug(f"Received event for node: {node.metadata.name}") external_ips = [ addr.address for addr in node.status.addresses if addr.type == "ExternalIP" ] - if external_ips: - await external_ips_update_queue.put(external_ips) + logger.debug( + f"External IPs for node {node.metadata.name}: {external_ips}" + ) + await external_ips_update_queue.put(external_ips) + logger.debug(f"Added external IPs to update queue: {external_ips}") except client.exceptions.ApiException as e: logger.error(f"API Exception in watch_nodes: {e}")