Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 10 additions & 12 deletions src/warnet/dashboard.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
import sys

import click

from .k8s import get_ingress_ip_or_host, wait_for_ingress_controller
from .k8s import get_ingress_ip_or_host, wait_for_ingress_endpoint


@click.command()
def dashboard():
"""Open the Warnet dashboard in default browser"""
import webbrowser

wait_for_ingress_controller()
timeout = 300
click.echo(f"Waiting {timeout} seconds for ingress endpoint ...")
try:
wait_for_ingress_endpoint(timeout=timeout)
except Exception as e:
click.echo(e)
sys.exit(1)
ip = get_ingress_ip_or_host()

if not ip:
click.echo("Error: Could not get the IP address of the dashboard")
click.echo(
"If you are running Minikube please run 'minikube tunnel' in a separate terminal"
)
click.echo(
"If you are running in the cloud, you may need to wait a short while while the load balancer is provisioned"
)
return

url = f"http://{ip}"

webbrowser.open(url)
Expand Down
29 changes: 28 additions & 1 deletion src/warnet/k8s.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import tarfile
import tempfile
from pathlib import Path
from time import sleep
from time import time, sleep
from typing import Optional

import yaml
Expand Down Expand Up @@ -334,6 +334,33 @@ def wait_for_ingress_controller(timeout=300):
return wait_for_pod_ready(pod.metadata.name, INGRESS_NAMESPACE, timeout)


def wait_for_ingress_endpoint(timeout=300):
config.load_kube_config()
networking_v1 = client.NetworkingV1Api()
start = time()
while time() - start < timeout:
try:
ingress = networking_v1.read_namespaced_ingress(CADDY_INGRESS_NAME, LOGGING_NAMESPACE)
except ApiException as e:
msg = (
f'Failed to read ingress with name "{CADDY_INGRESS_NAME}" from namespace "{LOGGING_NAMESPACE}"\n'
+ str(e).rstrip()
)
if e.status == 404:
msg += "\n\nDid you deploy a network with caddy enabled?"
raise Exception(msg) from e
lb_ingress = ingress.status.load_balancer.ingress
if lb_ingress and (lb_ingress[0].hostname or lb_ingress[0].ip):
return True
sleep(1)
msg = (
f"Ingress endpoint not found within {timeout} seconds.\n"
+ "If you are running Minikube please run 'minikube tunnel' in a separate terminal.\n"
+ "If you are running in the cloud, you may need to wait a short while while the load balancer is provisioned"
)
raise TimeoutError(msg)


def get_ingress_ip_or_host():
config.load_kube_config()
networking_v1 = client.NetworkingV1Api()
Expand Down