Skip to content

Commit 390b758

Browse files
committed
status: add exception handling
Adds exception handling around misconfigured kubeconfig files and also bad network connections.
1 parent 67e67f5 commit 390b758

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

src/warnet/status.py

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1+
import sys
2+
13
import click
4+
from kubernetes.config.config_exception import ConfigException
25
from rich.console import Console
36
from rich.panel import Panel
47
from rich.table import Table
58
from rich.text import Text
9+
from urllib3.exceptions import MaxRetryError
610

711
from .k8s import get_mission
812
from .network import _connected
@@ -13,8 +17,28 @@ def status():
1317
"""Display the unified status of the Warnet network and active scenarios"""
1418
console = Console()
1519

16-
tanks = _get_tank_status()
17-
scenarios = _get_deployed_scenarios()
20+
try:
21+
tanks = _get_tank_status()
22+
scenarios = _get_deployed_scenarios()
23+
except ConfigException as e:
24+
print(e)
25+
print(
26+
"The kubeconfig file has not been properly set. This may mean that you need to "
27+
"authorize with a cluster such as by starting minikube, starting docker-desktop, or "
28+
"authorizing with a configuration file provided by a cluster administrator."
29+
)
30+
sys.exit(1)
31+
except MaxRetryError as e:
32+
print(e)
33+
print(
34+
"Warnet cannot get the status of a Warnet network. To resolve this, you may need to "
35+
"confirm you have access to a Warnet cluster. Start by checking your network "
36+
"connection. Then, if running a local cluster, check that minikube or docker-desktop "
37+
"is running properly. If you are trying to connect to a remote cluster, check that "
38+
"the relevant authorization file has been configured properly as instructed by a "
39+
"cluster administrator."
40+
)
41+
sys.exit(1)
1842

1943
# Create a unified table
2044
table = Table(title="Warnet Status", show_header=True, header_style="bold magenta")

0 commit comments

Comments
 (0)