Skip to content

Commit

Permalink
Wait until endpoint to be ready for k8s
Browse files Browse the repository at this point in the history
  • Loading branch information
Michaelvll committed Jun 5, 2024
1 parent 7cab4f5 commit 6fc56be
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 3 additions & 1 deletion sky/provision/kubernetes/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,9 @@ def _query_ports_for_loadbalancer(
cluster_name_on_cloud=cluster_name_on_cloud)
external_ip = network_utils.get_loadbalancer_ip(
namespace=provider_config.get('namespace', 'default'),
service_name=service_name)
service_name=service_name,
timeout=10,
)

if external_ip is None:
return {}
Expand Down
11 changes: 10 additions & 1 deletion sky/provision/kubernetes/network_utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Kubernetes network provisioning utils."""
import os
import time
from typing import Dict, List, Optional, Tuple, Union

import jinja2
Expand Down Expand Up @@ -222,7 +223,9 @@ def get_ingress_external_ip_and_ports(
return external_ip, None


def get_loadbalancer_ip(namespace: str, service_name: str) -> Optional[str]:
def get_loadbalancer_ip(namespace: str,
service_name: str,
timeout: int = 0) -> Optional[str]:
"""Returns the IP address of the load balancer."""
core_api = kubernetes.core_api()
service = core_api.read_namespaced_service(
Expand All @@ -233,6 +236,12 @@ def get_loadbalancer_ip(namespace: str, service_name: str) -> Optional[str]:

ip = service.status.load_balancer.ingress[
0].ip or service.status.load_balancer.ingress[0].hostname
start_time = time.time()
while ip is None and time.time() - start_time < timeout:
service = core_api.read_namespaced_service(
service_name, namespace, _request_timeout=kubernetes.API_TIMEOUT)
ip = (service.status.load_balancer.ingress[0].ip or
service.status.load_balancer.ingress[0].hostname)
return ip if ip is not None else None


Expand Down

0 comments on commit 6fc56be

Please sign in to comment.