Skip to content

Commit 3c4b29e

Browse files
committed
add hasadna-k8s command to list volumes
1 parent 198a14b commit 3c4b29e

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

hasadna_k8s/storage/cli.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import os
22
import json
3+
import subprocess
4+
35
import click
46

57

8+
69
@click.group()
710
def main():
811
pass
@@ -16,3 +19,29 @@ def cleanup_old_logs(path, log_path_prefixes, no_dry_run):
1619
from .cleanup_old_logs import main
1720
main(path, dry_run=not no_dry_run, log_path_prefixes=log_path_prefixes)
1821
print("OK")
22+
23+
24+
@main.command()
25+
@click.argument('SEARCH_TERM', required=False)
26+
def find_volumes(search_term):
27+
for volume in json.loads(subprocess.check_output([
28+
"kubectl", "get", "pv", "-o", "json"
29+
]))['items']:
30+
if not search_term or search_term in json.dumps(volume):
31+
if 'local' in volume['spec']:
32+
spec = f'local({volume["spec"]["local"]['path']})'
33+
elif 'csi' in volume['spec']:
34+
spec = ','.join([
35+
volume['spec']['csi']['driver'],
36+
volume['spec']['csi']['volumeHandle'],
37+
])
38+
spec = f'csi({spec})'
39+
else:
40+
spec = 'unknown'
41+
print(
42+
volume['metadata']['name'],
43+
spec,
44+
f"{volume['spec']['claimRef']['namespace']}/{volume['spec']['claimRef']['name']}",
45+
)
46+
47+

0 commit comments

Comments
 (0)