Skip to content

Commit d53fde9

Browse files
committed
flesh out wargames prefix
1 parent 39b6d51 commit d53fde9

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/warnet/namespaces.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
DEFAULTS_NAMESPACE_FILE,
99
NAMESPACES_DIR,
1010
NAMESPACES_FILE,
11+
WARGAMES_NAMESPACE_PREFIX,
1112
)
1213
from .process import run_command, stream_command
1314

@@ -34,11 +35,13 @@ def namespaces():
3435

3536
@namespaces.command()
3637
def list():
37-
"""List all namespaces with 'warnet-' prefix"""
38+
"""List all namespaces with 'wargames-' prefix"""
3839
cmd = "kubectl get namespaces -o jsonpath='{.items[*].metadata.name}'"
3940
res = run_command(cmd)
4041
all_namespaces = res.split()
41-
warnet_namespaces = [ns for ns in all_namespaces if ns.startswith("warnet-")]
42+
warnet_namespaces = [
43+
ns for ns in all_namespaces if ns.startswith(f"{WARGAMES_NAMESPACE_PREFIX}")
44+
]
4245

4346
if warnet_namespaces:
4447
print("Warnet namespaces:")
@@ -52,14 +55,16 @@ def list():
5255
@click.option("--all", "destroy_all", is_flag=True, help="Destroy all warnet- prefixed namespaces")
5356
@click.argument("namespace", required=False)
5457
def destroy(destroy_all: bool, namespace: str):
55-
"""Destroy a specific namespace or all warnet- prefixed namespaces"""
58+
"""Destroy a specific namespace or all 'wargames-' prefixed namespaces"""
5659
if destroy_all:
5760
cmd = "kubectl get namespaces -o jsonpath='{.items[*].metadata.name}'"
5861
res = run_command(cmd)
5962

6063
# Get the list of namespaces
6164
all_namespaces = res.split()
62-
warnet_namespaces = [ns for ns in all_namespaces if ns.startswith("warnet-")]
65+
warnet_namespaces = [
66+
ns for ns in all_namespaces if ns.startswith(f"{WARGAMES_NAMESPACE_PREFIX}")
67+
]
6368

6469
if not warnet_namespaces:
6570
print("No warnet namespaces found to destroy.")
@@ -72,8 +77,8 @@ def destroy(destroy_all: bool, namespace: str):
7277
else:
7378
print(f"Destroyed namespace: {ns}")
7479
elif namespace:
75-
if not namespace.startswith("warnet-"):
76-
print("Error: Can only destroy namespaces with 'warnet-' prefix")
80+
if not namespace.startswith(f"{WARGAMES_NAMESPACE_PREFIX}"):
81+
print(f"Error: Can only destroy namespaces with '{WARGAMES_NAMESPACE_PREFIX}' prefix")
7782
return
7883

7984
destroy_cmd = f"kubectl delete namespace {namespace}"

0 commit comments

Comments
 (0)