-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlist_all_pods
executable file
·43 lines (35 loc) · 1.1 KB
/
list_all_pods
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env python3
import argparse
import os
import helpers as hp
def main(opts):
if opts.control_system:
namespaces = hp.STANDARD_NAMESPACES
output = []
for i, namespace in enumerate(namespaces):
command = hp.GET_PODS_CMD + f" -n {namespace}"
lines = hp.run_cmd(command, as_lines=True)
if i == 0:
output.extend(lines[:-1])
else:
output.extend(lines[1:-1])
print(os.linesep.join(output))
else:
command = hp.GET_PODS_CMD + " --all-namespaces"
output = hp.run_cmd(command)
print(output)
if __name__ == "__main__":
description = ["This program lists all pods on Kubernetes."]
parser = argparse.ArgumentParser(
description=" ".join(description),
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
)
parser.add_argument(
"-c",
"--control-system",
dest="control_system",
action="store_true",
help="Show only the pods for the control system.",
)
args = parser.parse_args()
main(args)