mirror of
https://github.com/khuedoan/homelab.git
synced 2024-12-23 01:04:32 +07:00
refactor(scripts): clean up wait main apps script
This commit is contained in:
parent
de6fc8ec06
commit
3f9e422975
@ -1,31 +1,30 @@
|
||||
#!/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()
|
||||
from time import sleep
|
||||
|
||||
# Essential services
|
||||
ingresses = [
|
||||
{
|
||||
'name': 'argocd-server',
|
||||
'fullname': 'ArgoCD',
|
||||
'namespace': 'argocd',
|
||||
'namespace': 'argocd'
|
||||
},
|
||||
{
|
||||
'name': 'hajimari',
|
||||
'fullname': 'Homepage',
|
||||
'namespace': 'hajimari',
|
||||
'namespace': 'hajimari'
|
||||
},
|
||||
{
|
||||
'name': 'gitea',
|
||||
'fullname': 'Gitea',
|
||||
'namespace': 'gitea'
|
||||
}
|
||||
]
|
||||
|
||||
config.load_kube_config(config_file='./metal/kubeconfig.yaml')
|
||||
|
||||
|
||||
def wait_app(name: str, fullname: str, namespace: str) -> None:
|
||||
console = Console()
|
||||
@ -38,25 +37,22 @@ def wait_app(name: str, fullname: str, namespace: str) -> None:
|
||||
name,
|
||||
namespace
|
||||
)
|
||||
|
||||
host = ingress.spec.rules[0].host
|
||||
requests.get(f"https://{host}", verify=False)
|
||||
console.log(f"{fullname} is ready, visit https://{host}")
|
||||
url = f"https://{ingress.spec.rules[0].host}"
|
||||
requests.get(url, verify=False).raise_for_status()
|
||||
sleep(3)
|
||||
console.log(f"{fullname} is ready, visit {url}")
|
||||
success = True
|
||||
except Exception:
|
||||
time.sleep(60)
|
||||
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))
|
||||
def main() -> None:
|
||||
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'])
|
||||
|
||||
|
||||
for ingress in ingresses:
|
||||
wait_app(
|
||||
name=ingress['name'],
|
||||
fullname=ingress['fullname'],
|
||||
namespace=ingress['namespace'],
|
||||
)
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
Loading…
Reference in New Issue
Block a user