khuedoan-homelab/scripts/wait-main-apps

64 lines
1.4 KiB
Plaintext
Raw Normal View History

#!/usr/bin/python
# TODO wip clean this up
import requests
import time
from kubernetes import client, config
from rich.console import Console
requests.urllib3.disable_warnings()
# Essential services
ingresses = [
{
'name': 'argocd-server',
'fullname': 'ArgoCD',
'namespace': 'argocd',
},
{
'name': 'hajimari',
'fullname': 'Homepage',
'namespace': 'hajimari',
}
]
config.load_kube_config(config_file='./metal/kubeconfig.yaml')
def wait_app(name: str, fullname: str, namespace: str) -> None:
console = Console()
success = False
with console.status(f"Waiting for {fullname}"):
while not success:
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
# from concurrent.futures import ThreadPoolExecutor
# with ThreadPoolExecutor(max_workers=4) as pool:
# # Number of tasks is greater than max workers
# pool.map(wait_app, range(8))
for ingress in ingresses:
wait_app(
name=ingress['name'],
fullname=ingress['fullname'],
namespace=ingress['namespace'],
)