use ipam address as kube vip target as well
parent
a7a2271da6
commit
148190ab02
|
|
@ -21,11 +21,19 @@ def update_service_annotation(external_ip):
|
||||||
|
|
||||||
# Check if the annotation needs to be updated
|
# Check if the annotation needs to be updated
|
||||||
current_annotation = service.metadata.annotations.get(ANNOTATION_KEY)
|
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
|
# 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)
|
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():
|
def main():
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue