Skip to content

Commit 99ef27c

Browse files
Modified kubectl-applogs plugin file and crlogs.py file (#1374)
* Modified kubectl-applogs plusing file and crlogs.py file. removed "connections" parameter from the command "python /$KUBEPLUS_HOME/plugins/crlogs.py $canonicalKind $instance $namespace $kubeconfig" in kubectl-applogs plugin file. removed unnecessary code from crlogs.py file including the commented code and relation block for connections and composition. * Removed two unused functions from clogs.py 1. get_resources_composition 2. get_pods1
1 parent 9c156ef commit 99ef27c

File tree

2 files changed

+8
-74
lines changed

2 files changed

+8
-74
lines changed

plugins/crlogs.py

Lines changed: 5 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ def _get_container_logs(self, pod, namespace, containers, kubeconfig):
2525

2626
def get_logs(self, pod, namespace, kubeconfig):
2727
cmd = 'kubectl get pods ' + pod + ' -n ' + namespace + ' -o json ' + kubeconfig
28-
#print(cmd)
2928
try:
3029
out = subprocess.Popen(cmd, stdout=subprocess.PIPE,
3130
stderr=subprocess.PIPE, shell=True).communicate()[0]
@@ -42,72 +41,17 @@ def get_logs(self, pod, namespace, kubeconfig):
4241
except Exception as e:
4342
print(e)
4443

45-
def get_resources_composition(self, kind, instance, namespace, kubeconfig):
46-
platf = platform.system()
47-
kubeplus_home = os.getenv('KUBEPLUS_HOME')
48-
cmd = ''
49-
json_output = {}
50-
if platf == "Darwin":
51-
cmd = kubeplus_home + '/plugins/kubediscovery-macos composition '
52-
elif platf == "Linux":
53-
cmd = kubeplus_home + '/plugins/kubediscovery-linux composition '
54-
else:
55-
print("OS not supported:" + platf)
56-
return json_output
57-
cmd = cmd + kind + ' ' + instance + ' ' + namespace + ' ' + kubeconfig
58-
#print(cmd)
59-
out = ''
60-
try:
61-
out = subprocess.Popen(cmd, stdout=subprocess.PIPE,
62-
stderr=subprocess.PIPE, shell=True).communicate()[0]
63-
out = out.decode('utf-8')
64-
except Exception as e:
65-
print(e)
66-
if out:
67-
print(out)
68-
try:
69-
json_output = json.loads(out)
70-
except Exception as e:
71-
print(e)
72-
return json_output
73-
74-
def get_pods1(self, resources):
75-
pod_list = []
76-
for resource in resources:
77-
#print(resource)
78-
if resource['Kind'] == 'Pod':
79-
present = False
80-
for p in pod_list:
81-
if p['Name'] == resource['Name']:
82-
present = True
83-
break
84-
if not present:
85-
pod_list.append(resource)
86-
#print(pod_list)
87-
return pod_list
88-
8944
if __name__ == '__main__':
9045
crLogs = CRLogs()
91-
#crLogs.get_logs(sys.argv[1], sys.argv[2])
92-
#resources = sys.argv[1]
93-
relation = sys.argv[1]
94-
kind = sys.argv[2]
95-
instance = sys.argv[3]
96-
namespace = sys.argv[4]
97-
kubeconfig = sys.argv[5]
98-
#print(kind + " " + instance + " " + namespace + " " + kubeconfig)
46+
kind = sys.argv[1]
47+
instance = sys.argv[2]
48+
namespace = sys.argv[3]
49+
kubeconfig = sys.argv[4]
9950
resources = {}
100-
#if relation == 'connections':
101-
# resources = crLogs.get_resources_connections(kind, instance, namespace, kubeconfig)
102-
# #print(resources)
103-
#if relation == 'composition':
104-
# resources = crLogs.get_resources_composition(kind, instance, namespace, kubeconfig)
105-
# #print(resources)
106-
#resource_json = json.loads(resources)
51+
10752
pods = crLogs.get_pods_in_ns(kind, instance, kubeconfig)
10853
for pod in pods:
10954
pod_name = pod['Name']
11055
pod_namespace = pod['Namespace']
111-
#print(pod_name)
11256
crLogs.get_logs(pod_name, pod_namespace, kubeconfig)
11357
print("---------------------------------------")

plugins/kubectl-applogs

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ fi
2121
kind=$1
2222
instance=$2
2323
namespace=$3
24-
# Only --kubeconfig specified
25-
kubeconfig1="$HOME/.kube/config" #default value
24+
25+
kubeconfig1="$HOME/.kube/config" # Default value
2626

2727
shift;
2828
shift;
@@ -51,8 +51,6 @@ fi
5151

5252
check_namespace $namespace $kubeconfig
5353

54-
#echo "$kind $instance $namespace"
55-
5654
canonicalKind=$(get_canonical_kind $kind)
5755

5856
if [[ $canonicalKind == *"Unknown"* ]]; then
@@ -62,16 +60,8 @@ fi
6260

6361
resStatus=`kubectl $kubeconfig get $kind $instance -n $namespace -o json 2>&1`
6462
if [[ $resStatus =~ 'Error' ]]; then
65-
# echo "Instance $instance of $kind not deployed properly."
6663
echo $resStatus
6764
exit 0
6865
fi
6966

70-
71-
72-
python /$KUBEPLUS_HOME/plugins/crlogs.py connections $canonicalKind $instance $namespace $kubeconfig
73-
74-
75-
#echo "kubectl grouplogs cr connections"
76-
#echo "kubectl grouplogs service"
77-
#echo "kubectl grouplogs helmrelease"
67+
python /$KUBEPLUS_HOME/plugins/crlogs.py $canonicalKind $instance $namespace $kubeconfig

0 commit comments

Comments
 (0)