-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathkexec
executable file
·34 lines (27 loc) · 1.03 KB
/
kexec
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
#!/usr/bin/python
import argparse
import util
parser = argparse.ArgumentParser(description='kubectl exec in pods that matches prefix')
parser.add_argument("--all", dest='all', action='store_true',
help='exec in all matched pods')
parser.add_argument('pod_prefix', metavar='PodPrefix', type=str, nargs=1,
help='prefix of pod')
parser.set_defaults(all=False)
# unkonw arguments will be passed to kubectl
args, unknown_args = parser.parse_known_args()
if len(unknown_args) <= 0:
print("Try to bash into pod by default")
unknown_args = ["bash"]
pod_prefix = args.pod_prefix[0]
pods = util.get_all_pods()
matched_pods = util.find_all_pods_with_prefix(pods, pod_prefix)
if len(matched_pods) <= 0:
print("Could not find pod with prefix %s" % pod_prefix)
exit(1)
for pod in matched_pods:
if not pod.status == "Running":
print("######Skipping pod %s since its status is %s" % (pod.name, pod.status))
continue
util.exec_in_pod(pod, unknown_args)
if not args.all:
break