khuedoan-homelab/scripts/wait-main-apps

56 lines
1.4 KiB
Python
Executable File

#!/usr/bin/python
import requests
from kubernetes import client, config
from rich.console import Console
from time import sleep
# Essential services
ingresses = [
{
'name': 'argocd-server',
'fullname': 'ArgoCD',
'namespace': 'argocd'
},
{
'name': 'hajimari',
'fullname': 'Homepage',
'namespace': 'hajimari'
}
]
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:
ingress = client.NetworkingV1Api().read_namespaced_ingress(
name,
namespace
)
url = f"https://{ingress.spec.rules[0].host}"
requests.get(url, verify=False).raise_for_status()
console.log(f"{fullname} is ready, visit {url}")
success = True
except Exception:
sleep(60)
def main() -> None:
Console().rule("Waiting for essential applications")
config.load_kube_config(config_file='./metal/kubeconfig.yaml')
requests.urllib3.disable_warnings()
for ingress in ingresses:
wait_app(ingress['name'], ingress['fullname'], ingress['namespace'])
print("There's more, but you can start exploring right away!")
if __name__ == '__main__':
main()