retry connection if timeout is reached

main
Malar Invention 2024-10-31 22:51:32 +05:30
parent 1f9f45baf5
commit dfb89f1608
1 changed files with 25 additions and 14 deletions

View File

@ -29,10 +29,13 @@ def update_service_annotation(external_ip):
def main():
w = watch.Watch()
for event in w.stream(v1.list_node, _request_timeout=60):
while True:
try:
for event in w.stream(v1.list_node, _request_timeout=300):
node = event["object"]
node_name = node.metadata.name
is_gateway = node.metadata.annotations.get(NODE_ANNOTATION_KEY)
print(f"Node annotations: {node.metadata.annotations}")
is_gateway = node.metadata.annotations.get(NODE_ANNOTATION_KEY, False)
print(f"{node_name} is gateway?: {is_gateway}, type:{type(is_gateway)}")
# Extract the external IP if it exists
@ -46,6 +49,14 @@ def main():
print(f"Detected external IP {external_ip} for node {node_name}")
update_service_annotation(external_ip)
except client.exceptions.ApiException as e:
print(f"API Exception: {e}")
time.sleep(5) # Wait before retrying
except Exception as e:
print(f"Unexpected error: {e}")
time.sleep(5)
if __name__ == "__main__":
main()