Compare commits
No commits in common. "924c24b16bff1edde14fdad635a028cf5069118b" and "041b45bb94da301d720b9c2c6bef9bdab05e9b46" have entirely different histories.
924c24b16b
...
041b45bb94
|
|
@ -25,9 +25,7 @@ async def update_service_annotation(v1, service, external_ips):
|
||||||
service_obj = await v1.read_namespaced_service(service_name, namespace)
|
service_obj = await v1.read_namespaced_service(service_name, namespace)
|
||||||
|
|
||||||
current_annotation = service_obj.metadata.annotations.get(ANNOTATION_KEY)
|
current_annotation = service_obj.metadata.annotations.get(ANNOTATION_KEY)
|
||||||
zlan_gateway_ip = service_obj.metadata.labels.get(SERVICE_LABEL_KEY)
|
target_annotation = ",".join(external_ips) + "," + ZERO_GATEWAY_IP
|
||||||
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"Current annotation: {current_annotation}")
|
||||||
logger.debug(f"Target annotation: {target_annotation}")
|
logger.debug(f"Target annotation: {target_annotation}")
|
||||||
if current_annotation != target_annotation:
|
if current_annotation != target_annotation:
|
||||||
|
|
@ -46,7 +44,6 @@ async def update_service_annotation(v1, service, external_ips):
|
||||||
|
|
||||||
async def watch_nodes(v1, external_ips_update_queue):
|
async def watch_nodes(v1, external_ips_update_queue):
|
||||||
w = watch.Watch()
|
w = watch.Watch()
|
||||||
external_node_ipset = set()
|
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
logger.debug("Starting to watch nodes")
|
logger.debug("Starting to watch nodes")
|
||||||
|
|
@ -56,30 +53,17 @@ async def watch_nodes(v1, external_ips_update_queue):
|
||||||
_request_timeout=NODE_REQUEST_TIMEOUT,
|
_request_timeout=NODE_REQUEST_TIMEOUT,
|
||||||
):
|
):
|
||||||
node = event["object"]
|
node = event["object"]
|
||||||
event_type = event["type"]
|
logger.debug(f"Received event for node: {node.metadata.name}")
|
||||||
logger.debug(
|
|
||||||
f"Received {event_type} event for node: {node.metadata.name}"
|
|
||||||
)
|
|
||||||
external_ips = [
|
external_ips = [
|
||||||
addr.address
|
addr.address
|
||||||
for addr in node.status.addresses
|
for addr in node.status.addresses
|
||||||
if addr.type == "ExternalIP"
|
if addr.type == "ExternalIP"
|
||||||
]
|
]
|
||||||
if event_type in {"ADDED", "MODIFIED"}:
|
|
||||||
external_node_ipset.update(external_ips)
|
|
||||||
logger.debug(
|
logger.debug(
|
||||||
f"External IPs for node {node.metadata.name}: {external_ips}"
|
f"External IPs for node {node.metadata.name}: {external_ips}"
|
||||||
)
|
)
|
||||||
elif event_type == "REMOVED":
|
await external_ips_update_queue.put(external_ips)
|
||||||
for ip in external_ips:
|
logger.debug(f"Added external IPs to update queue: {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:
|
except client.exceptions.ApiException as e:
|
||||||
logger.error(f"API Exception in watch_nodes: {e}")
|
logger.error(f"API Exception in watch_nodes: {e}")
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue