Compare commits

...

3 Commits

1 changed files with 23 additions and 7 deletions

View File

@ -25,7 +25,9 @@ async def update_service_annotation(v1, service, external_ips):
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
zlan_gateway_ip = service_obj.metadata.labels.get(SERVICE_LABEL_KEY)
logger.debug(f"Zlan Gateway IP: {zlan_gateway_ip}")
target_annotation = ",".join(external_ips) + "," + zlan_gateway_ip
logger.debug(f"Current annotation: {current_annotation}")
logger.debug(f"Target annotation: {target_annotation}")
if current_annotation != target_annotation:
@ -44,6 +46,7 @@ async def update_service_annotation(v1, service, external_ips):
async def watch_nodes(v1, external_ips_update_queue):
w = watch.Watch()
external_node_ipset = set()
while True:
try:
logger.debug("Starting to watch nodes")
@ -53,17 +56,30 @@ async def watch_nodes(v1, external_ips_update_queue):
_request_timeout=NODE_REQUEST_TIMEOUT,
):
node = event["object"]
logger.debug(f"Received event for node: {node.metadata.name}")
event_type = event["type"]
logger.debug(
f"Received {event_type} event for node: {node.metadata.name}"
)
external_ips = [
addr.address
for addr in node.status.addresses
if addr.type == "ExternalIP"
]
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}")
if event_type in {"ADDED", "MODIFIED"}:
external_node_ipset.update(external_ips)
logger.debug(
f"External IPs for node {node.metadata.name}: {external_ips}"
)
elif event_type == "REMOVED":
for ip in external_ips:
if ip in external_node_ipset:
external_node_ipset.remove(ip)
logger.debug(
f"External IPs for node {node.metadata.name}: {external_ips}"
)
external_node_ips = list(external_node_ipset)
await external_ips_update_queue.put(external_node_ips)
logger.debug(f"Added external IPs to update queue: {external_node_ips}")
except client.exceptions.ApiException as e:
logger.error(f"API Exception in watch_nodes: {e}")