feat(scripts): also wait for Ingress objects

This commit is contained in:
Khue Doan
2022-03-14 02:42:23 +07:00
parent 44c63b3caa
commit e054f2001f

View File

@ -1,11 +1,15 @@
#!/usr/bin/python #!/usr/bin/python
# TODO wip clean this up
import requests import requests
import time import time
from kubernetes import client, config from kubernetes import client, config
from rich.console import Console from rich.console import Console
requests.urllib3.disable_warnings()
# Essential services # Essential services
ingresses = [ ingresses = [
{ {
@ -24,19 +28,24 @@ config.load_kube_config(config_file='./metal/kubeconfig.yaml')
def wait_app(name: str, fullname: str, namespace: str) -> None: def wait_app(name: str, fullname: str, namespace: str) -> None:
i = client.NetworkingV1Api().read_namespaced_ingress(
name,
namespace
)
host = i.spec.rules[0].host
console = Console() console = Console()
success = False
with console.status(f"Waiting for {fullname}") as status: with console.status(f"Waiting for {fullname}"):
while requests.get(f"https://{host}", verify=False).status_code != 200:
time.sleep(30) while not success:
console.log(f"{fullname} is ready, visit https://{host}") try:
i = client.NetworkingV1Api().read_namespaced_ingress(
name,
namespace
)
host = i.spec.rules[0].host
requests.get(f"https://{host}", verify=False)
console.log(f"{fullname} is ready, visit https://{host}")
success = True
except Exception:
time.sleep(60)
# TODO # TODO
@ -46,8 +55,6 @@ def wait_app(name: str, fullname: str, namespace: str) -> None:
# pool.map(wait_app, range(8)) # pool.map(wait_app, range(8))
requests.urllib3.disable_warnings()
for ingress in ingresses: for ingress in ingresses:
wait_app( wait_app(
name=ingress['name'], name=ingress['name'],