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"
|
SERVICE_NAME = "traefik"
|
||||||
NAMESPACE = "kube-system"
|
NAMESPACE = "kube-system"
|
||||||
ANNOTATION_KEY = "kube-vip.io/loadbalancerIPs"
|
ANNOTATION_KEY = "kube-vip.io/loadbalancerIPs"
|
||||||
|
NODE_ANNOTATION_KEY = "svccontroller.k3s.cattle.io/enablelb"
|
||||||
|
|
||||||
|
|
||||||
def update_service_annotation(external_ip):
|
def update_service_annotation(external_ip):
|
||||||
|
|
@ -31,11 +32,13 @@ def main():
|
||||||
for event in w.stream(v1.list_node, _request_timeout=60):
|
for event in w.stream(v1.list_node, _request_timeout=60):
|
||||||
node = event["object"]
|
node = event["object"]
|
||||||
node_name = node.metadata.name
|
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
|
# 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":
|
if address.type == "ExternalIP" and is_gateway == True:
|
||||||
external_ip = address.address
|
external_ip = address.address
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue