update service annotation with ip of node that is set as gateway
parent
564dc1d9a1
commit
1f9f45baf5
|
|
@ -11,6 +11,7 @@ v1 = client.CoreV1Api()
|
|||
SERVICE_NAME = "traefik"
|
||||
NAMESPACE = "kube-system"
|
||||
ANNOTATION_KEY = "kube-vip.io/loadbalancerIPs"
|
||||
NODE_ANNOTATION_KEY = "svccontroller.k3s.cattle.io/enablelb"
|
||||
|
||||
|
||||
def update_service_annotation(external_ip):
|
||||
|
|
@ -31,11 +32,13 @@ def main():
|
|||
for event in w.stream(v1.list_node, _request_timeout=60):
|
||||
node = event["object"]
|
||||
node_name = node.metadata.name
|
||||
is_gateway = node.metadata.annotations.get(NODE_ANNOTATION_KEY)
|
||||
print(f"{node_name} is gateway?: {is_gateway}, type:{type(is_gateway)}")
|
||||
|
||||
# Extract the external IP if it exists
|
||||
external_ip = None
|
||||
for address in node.status.addresses:
|
||||
if address.type == "ExternalIP":
|
||||
if address.type == "ExternalIP" and is_gateway == True:
|
||||
external_ip = address.address
|
||||
break
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue