Compare commits
No commits in common. "17b90e18ca2ccad26e030c3fc25f0dce17ae79c0" and "1f9f45baf57e8ccf8a528a688650e4329dee9981" have entirely different histories.
17b90e18ca
...
1f9f45baf5
|
|
@ -11,7 +11,7 @@ v1 = client.CoreV1Api()
|
||||||
SERVICE_NAME = "traefik"
|
SERVICE_NAME = "traefik"
|
||||||
NAMESPACE = "kube-system"
|
NAMESPACE = "kube-system"
|
||||||
ANNOTATION_KEY = "kube-vip.io/loadbalancerIPs"
|
ANNOTATION_KEY = "kube-vip.io/loadbalancerIPs"
|
||||||
NODE_LABEL = "svccontroller.k3s.cattle.io/enablelb=true"
|
NODE_ANNOTATION_KEY = "svccontroller.k3s.cattle.io/enablelb"
|
||||||
|
|
||||||
|
|
||||||
def update_service_annotation(external_ip):
|
def update_service_annotation(external_ip):
|
||||||
|
|
@ -29,32 +29,22 @@ def update_service_annotation(external_ip):
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
w = watch.Watch()
|
w = watch.Watch()
|
||||||
while True:
|
for event in w.stream(v1.list_node, _request_timeout=60):
|
||||||
try:
|
node = event["object"]
|
||||||
for event in w.stream(
|
node_name = node.metadata.name
|
||||||
v1.list_node, label_selector=NODE_LABEL, _request_timeout=300
|
is_gateway = node.metadata.annotations.get(NODE_ANNOTATION_KEY)
|
||||||
):
|
print(f"{node_name} is gateway?: {is_gateway}, type:{type(is_gateway)}")
|
||||||
node = event["object"]
|
|
||||||
node_name = node.metadata.name
|
|
||||||
|
|
||||||
# Extract the external IP if it exists
|
# Extract the external IP if it exists
|
||||||
external_ip = None
|
external_ip = None
|
||||||
for address in node.status.addresses:
|
for address in node.status.addresses:
|
||||||
if address.type == "ExternalIP" and is_gateway == True:
|
if address.type == "ExternalIP" and is_gateway == True:
|
||||||
external_ip = address.address
|
external_ip = address.address
|
||||||
break
|
break
|
||||||
|
|
||||||
if external_ip:
|
if external_ip:
|
||||||
print(f"Detected external IP {external_ip} for node {node_name}")
|
print(f"Detected external IP {external_ip} for node {node_name}")
|
||||||
update_service_annotation(external_ip)
|
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__":
|
if __name__ == "__main__":
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue