refactor(scripts): clean up wait main apps script

This commit is contained in:
Khue Doan 2022-03-14 20:33:11 +07:00
parent de6fc8ec06
commit 3f9e422975

View File

@ -1,31 +1,30 @@
#!/usr/bin/python #!/usr/bin/python
# TODO wip clean this up
import requests import requests
import time
from kubernetes import client, config from kubernetes import client, config
from rich.console import Console from rich.console import Console
from time import sleep
requests.urllib3.disable_warnings()
# Essential services # Essential services
ingresses = [ ingresses = [
{ {
'name': 'argocd-server', 'name': 'argocd-server',
'fullname': 'ArgoCD', 'fullname': 'ArgoCD',
'namespace': 'argocd', 'namespace': 'argocd'
}, },
{ {
'name': 'hajimari', 'name': 'hajimari',
'fullname': 'Homepage', '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: def wait_app(name: str, fullname: str, namespace: str) -> None:
console = Console() console = Console()
@ -38,25 +37,22 @@ def wait_app(name: str, fullname: str, namespace: str) -> None:
name, name,
namespace namespace
) )
url = f"https://{ingress.spec.rules[0].host}"
host = ingress.spec.rules[0].host requests.get(url, verify=False).raise_for_status()
requests.get(f"https://{host}", verify=False) sleep(3)
console.log(f"{fullname} is ready, visit https://{host}") console.log(f"{fullname} is ready, visit {url}")
success = True success = True
except Exception: except Exception:
time.sleep(60) sleep(60)
# TODO def main() -> None:
# from concurrent.futures import ThreadPoolExecutor config.load_kube_config(config_file='./metal/kubeconfig.yaml')
# with ThreadPoolExecutor(max_workers=4) as pool: requests.urllib3.disable_warnings()
# # Number of tasks is greater than max workers
# pool.map(wait_app, range(8)) for ingress in ingresses:
wait_app(ingress['name'], ingress['fullname'], ingress['namespace'])
for ingress in ingresses: if __name__ == '__main__':
wait_app( main()
name=ingress['name'],
fullname=ingress['fullname'],
namespace=ingress['namespace'],
)