1+ import itertools
12import sys
23
34import click
89from rich .text import Text
910from urllib3 .exceptions import MaxRetryError
1011
12+ from .constants import COMMANDER_MISSION , TANK_MISSION
1113from .k8s import get_mission
1214from .network import _connected
15+ from .plugins import get_plugin_missions
1316
1417
1518@click .command ()
@@ -20,6 +23,7 @@ def status():
2023 try :
2124 tanks = _get_tank_status ()
2225 scenarios = _get_deployed_scenarios ()
26+ plugins = _get_plugin_status ()
2327 except ConfigException as e :
2428 print (e )
2529 print (
@@ -65,6 +69,20 @@ def status():
6569 else :
6670 table .add_row ("Scenario" , "No active scenarios" , "" )
6771
72+ # Add a separator if there are plugins
73+ if plugins :
74+ table .add_row ("" , "" , "" )
75+
76+ # Add plugins to the table
77+ active_plugins = 0
78+ if plugins :
79+ for plugin in plugins :
80+ table .add_row ("Plugin" , plugin ["name" ], plugin ["status" ], plugin ["namespace" ])
81+ if plugin ["status" ] == "running" or plugin ["status" ] == "pending" :
82+ active_plugins += 1
83+ else :
84+ table .add_row ("Plugin" , "No active plugins" , "" )
85+
6886 # Create a panel to wrap the table
6987 panel = Panel (
7088 table ,
@@ -81,12 +99,13 @@ def status():
8199 summary = Text ()
82100 summary .append (f"\n Total Tanks: { len (tanks )} " , style = "bold cyan" )
83101 summary .append (f" | Active Scenarios: { active } " , style = "bold green" )
102+ summary .append (f" | Active Plugins: { active_plugins } " , style = "bold green" )
84103 console .print (summary )
85104 _connected (end = "\r " )
86105
87106
88107def _get_tank_status ():
89- tanks = get_mission ("tank" )
108+ tanks = get_mission (TANK_MISSION )
90109 return [
91110 {
92111 "name" : tank .metadata .name ,
@@ -97,8 +116,20 @@ def _get_tank_status():
97116 ]
98117
99118
119+ def _get_plugin_status ():
120+ plugin_pods = [get_mission (mission ) for mission in get_plugin_missions ()]
121+ return [
122+ {
123+ "name" : pod .metadata .name ,
124+ "status" : pod .status .phase .lower (),
125+ "namespace" : pod .metadata .namespace ,
126+ }
127+ for pod in list (itertools .chain .from_iterable (plugin_pods )) # flatten
128+ ]
129+
130+
100131def _get_deployed_scenarios ():
101- commanders = get_mission ("commander" )
132+ commanders = get_mission (COMMANDER_MISSION )
102133 return [
103134 {
104135 "name" : c .metadata .name ,
0 commit comments