Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modified kubectl-applogs plusing file and crlogs.py file #1374

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 5 additions & 20 deletions plugins/crlogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ def _get_container_logs(self, pod, namespace, containers, kubeconfig):

def get_logs(self, pod, namespace, kubeconfig):
cmd = 'kubectl get pods ' + pod + ' -n ' + namespace + ' -o json ' + kubeconfig
#print(cmd)
try:
out = subprocess.Popen(cmd, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, shell=True).communicate()[0]
Expand Down Expand Up @@ -55,7 +54,6 @@ def get_resources_composition(self, kind, instance, namespace, kubeconfig):
print("OS not supported:" + platf)
return json_output
cmd = cmd + kind + ' ' + instance + ' ' + namespace + ' ' + kubeconfig
#print(cmd)
out = ''
try:
out = subprocess.Popen(cmd, stdout=subprocess.PIPE,
Expand All @@ -74,7 +72,6 @@ def get_resources_composition(self, kind, instance, namespace, kubeconfig):
def get_pods1(self, resources):
pod_list = []
for resource in resources:
#print(resource)
if resource['Kind'] == 'Pod':
present = False
for p in pod_list:
Expand All @@ -83,31 +80,19 @@ def get_pods1(self, resources):
break
if not present:
pod_list.append(resource)
#print(pod_list)
return pod_list

if __name__ == '__main__':
crLogs = CRLogs()
#crLogs.get_logs(sys.argv[1], sys.argv[2])
#resources = sys.argv[1]
relation = sys.argv[1]
kind = sys.argv[2]
instance = sys.argv[3]
namespace = sys.argv[4]
kubeconfig = sys.argv[5]
#print(kind + " " + instance + " " + namespace + " " + kubeconfig)
kind = sys.argv[1]
instance = sys.argv[2]
namespace = sys.argv[3]
kubeconfig = sys.argv[4]
resources = {}
#if relation == 'connections':
# resources = crLogs.get_resources_connections(kind, instance, namespace, kubeconfig)
# #print(resources)
#if relation == 'composition':
# resources = crLogs.get_resources_composition(kind, instance, namespace, kubeconfig)
# #print(resources)
#resource_json = json.loads(resources)

pods = crLogs.get_pods_in_ns(kind, instance, kubeconfig)
for pod in pods:
pod_name = pod['Name']
pod_namespace = pod['Namespace']
#print(pod_name)
crLogs.get_logs(pod_name, pod_namespace, kubeconfig)
print("---------------------------------------")
16 changes: 3 additions & 13 deletions plugins/kubectl-applogs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ fi
kind=$1
instance=$2
namespace=$3
# Only --kubeconfig specified
kubeconfig1="$HOME/.kube/config" #default value

kubeconfig1="$HOME/.kube/config" # Default value

shift;
shift;
Expand Down Expand Up @@ -51,8 +51,6 @@ fi

check_namespace $namespace $kubeconfig

#echo "$kind $instance $namespace"

canonicalKind=$(get_canonical_kind $kind)

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

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



python /$KUBEPLUS_HOME/plugins/crlogs.py connections $canonicalKind $instance $namespace $kubeconfig


#echo "kubectl grouplogs cr connections"
#echo "kubectl grouplogs service"
#echo "kubectl grouplogs helmrelease"
python /$KUBEPLUS_HOME/plugins/crlogs.py $canonicalKind $instance $namespace $kubeconfig
Loading