Skip to content

Commit a1cf827

Browse files
authored
cli: Add versions of all pods in kadalu-namespace (kadalu#674)
This PR adds versions of all pods managed by kadalu, by exec into them. Helps while debugging for version related errors. Fixes: kadalu#664 Signed-off-by: Shree Vatsa N <[email protected]>
1 parent 60567e9 commit a1cf827

File tree

2 files changed

+50
-5
lines changed

2 files changed

+50
-5
lines changed

cli/kubectl_kadalu/__main__.py

+48-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from argparse import ArgumentParser
99

1010
from version import VERSION
11+
import utils
1112

1213
# Subcommands list that are currently supported, if any new subcommand has to
1314
# be implemeted add argument to this list and implement `validate` and `run`
@@ -18,10 +19,9 @@
1819
"storage-list",
1920
"storage-remove",
2021
"logs",
21-
"healinfo",
22+
"healinfo"
2223
]
2324

24-
2525
def get_args():
2626
"""Argument Parser"""
2727
parser = ArgumentParser()
@@ -39,9 +39,54 @@ def get_args():
3939
return parser.parse_args()
4040

4141

42+
def get_all_kadalu_pods():
43+
""" List of all pods in kadalu namespace """
44+
45+
try:
46+
cmd = ["kubectl", "get", "pods", "-nkadalu", "-oname"]
47+
resp = utils.execute(cmd)
48+
# Remove empty lines(pod-names) from command response
49+
pods = resp.stdout.split()
50+
return pods
51+
except utils.CommandError as err:
52+
utils.command_error(cmd, err.stderr)
53+
return None
54+
55+
56+
def get_kadalu_version_in_pod(pod):
57+
""" Get kadalu version from pods inside kadalu-namespace by exec """
58+
59+
try:
60+
61+
cmd = ["kubectl", "exec", "-nkadalu", pod, "--", "bash",
62+
"-c", "echo $KADALU_VERSION"]
63+
64+
if "nodeplugin" in pod or "provisioner" in pod:
65+
version_container = "kadalu-nodeplugin"
66+
if "provisioner" in pod:
67+
version_container = "kadalu-provisioner"
68+
cmd.insert(3, "-c")
69+
cmd.insert(4, version_container)
70+
71+
version_resp = utils.execute(cmd)
72+
version = version_resp.stdout.strip()
73+
74+
return version
75+
76+
except utils.CommandError as err:
77+
utils.command_error(cmd, err.stderr)
78+
return None
79+
80+
4281
def show_version():
4382
"""Show version information"""
44-
print("kubectl-kadalu %s" % VERSION)
83+
print("kubectl-kadalu plugin: %s" % VERSION)
84+
pods = get_all_kadalu_pods()
85+
if pods:
86+
print("kadalu pod(s) versions")
87+
for pod in pods:
88+
version = get_kadalu_version_in_pod(pod)
89+
print("%s: %s" %(pod, version))
4590

4691

4792
def version_set_args(name, parser):

cli/kubectl_kadalu/logs.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ def set_args(name, subparsers):
2626

2727
arg("-c",
2828
"--container",
29-
help="Specify container name to get log info.\n"
29+
help="Specify the container name to get log info.\n"
3030
"To be used along with '--podname'")
3131

3232
arg("-A",
3333
"--allcontainers",
3434
action="store_true",
35-
help=("Show logs of all containers"
35+
help=("Show logs of all containers "
3636
"of a particular pod.\n"
3737
"To be used along with '--podname'"))
3838

0 commit comments

Comments
 (0)