File tree Expand file tree Collapse file tree 2 files changed +40
-0
lines changed Expand file tree Collapse file tree 2 files changed +40
-0
lines changed Original file line number Diff line number Diff line change 1010from .namespaces import copy_namespaces_defaults , namespaces
1111from .network import copy_network_defaults
1212from .process import run_command
13+ from .service_accounts import service_accounts
1314
1415
1516@click .group (name = "admin" , hidden = True )
@@ -19,6 +20,7 @@ def admin():
1920
2021
2122admin .add_command (namespaces )
23+ admin .add_command (service_accounts )
2224
2325
2426@admin .command ()
Original file line number Diff line number Diff line change 1+ import click
2+
3+ from .constants import (
4+ WARGAMES_NAMESPACE_PREFIX ,
5+ )
6+ from .k8s import get_static_client
7+
8+
9+ @click .group (name = "service-accounts" )
10+ def service_accounts ():
11+ """Service account commands"""
12+
13+
14+ @service_accounts .command ()
15+ def list ():
16+ """List all service accounts with 'wargames-' prefix"""
17+ # Load the kubeconfig file
18+ sclient = get_static_client ()
19+ namespaces = sclient .list_namespace ().items
20+
21+ filtered_namespaces = [
22+ ns .metadata .name
23+ for ns in namespaces
24+ if ns .metadata .name .startswith (WARGAMES_NAMESPACE_PREFIX )
25+ ]
26+
27+ if len (filtered_namespaces ) == 0 :
28+ click .secho ("Could not find any matching service accounts." , fg = "yellow" )
29+
30+ for namespace in filtered_namespaces :
31+ click .secho (f"Service accounts in namespace: { namespace } " )
32+ service_accounts = sclient .list_namespaced_service_account (namespace = namespace ).items
33+
34+ if len (service_accounts ) == 0 :
35+ click .secho ("...Could not find any matching service accounts" , fg = "yellow" )
36+
37+ for sa in service_accounts :
38+ click .secho (f"- { sa .metadata .name } " , fg = "green" )
You can’t perform that action at this time.
0 commit comments