From 148190ab02aa818dc6777c17c4750459b2c8f276 Mon Sep 17 00:00:00 2001 From: Malar Invention Date: Fri, 1 Nov 2024 11:40:22 +0530 Subject: [PATCH] use ipam address as kube vip target as well --- node_external_ip_controller.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/node_external_ip_controller.py b/node_external_ip_controller.py index d368d91..9b484f9 100644 --- a/node_external_ip_controller.py +++ b/node_external_ip_controller.py @@ -21,11 +21,19 @@ def update_service_annotation(external_ip): # Check if the annotation needs to be updated current_annotation = service.metadata.annotations.get(ANNOTATION_KEY) - if current_annotation != external_ip: + ipam_address = service.spec.load_balancer_ip + if ipam_address: + print(f"service {SERVICE_NAME} has existing ipam IP: {ipam_address}") + target_annotation = ",".join({ipam_address, external_ip}) + else: + target_annotation = external_ip + if current_annotation != target_annotation: # Update the annotation - body = {"metadata": {"annotations": {ANNOTATION_KEY: external_ip}}} + body = {"metadata": {"annotations": {ANNOTATION_KEY: target_annotation}}} v1.patch_namespaced_service(SERVICE_NAME, NAMESPACE, body) - print(f"Updated service {SERVICE_NAME} with new external IP: {external_ip}") + print( + f"Updated service {SERVICE_NAME} with new external IPs: {target_annotation}" + ) def main():