Skip to content

Commit 917ee4a

Browse files
authored
Merge pull request #604 from mplsgrant/2024-09-status-exception-handling
Add `warnet status` exception handling
2 parents e0773da + 83b209b commit 917ee4a

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

src/warnet/k8s.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import json
22
import os
3+
import sys
34
import tempfile
45
from pathlib import Path
56

@@ -115,7 +116,16 @@ def delete_pod(pod_name: str) -> bool:
115116

116117
def get_default_namespace() -> str:
117118
command = "kubectl config view --minify -o jsonpath='{..namespace}'"
118-
kubectl_namespace = run_command(command)
119+
try:
120+
kubectl_namespace = run_command(command)
121+
except Exception as e:
122+
print(e)
123+
if str(e).find("command not found"):
124+
print(
125+
"It looks like kubectl is not installed. Please install it to continue: "
126+
"https://kubernetes.io/docs/tasks/tools/"
127+
)
128+
sys.exit(1)
119129
return kubectl_namespace if kubectl_namespace else DEFAULT_NAMESPACE
120130

121131

src/warnet/status.py

+26-2
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)