-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
112 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
#! /usr/bin/env python3 | ||
|
||
|
||
### ======================================================================= ### | ||
### A command-line tool to dump irods csi driver logs ### | ||
### Uses: ./dump_irodscsidriver_logs.py ### | ||
### ======================================================================= ### | ||
|
||
import os, sys | ||
import argparse | ||
import subprocess | ||
from datetime import datetime | ||
|
||
try: | ||
from subprocess import DEVNULL # py3k | ||
except ImportError: | ||
import os | ||
DEVNULL = open(os.devnull, 'wb') | ||
|
||
def get_kube_controller_pods(kubeconf=""): | ||
kubepods = [] | ||
kubecommand = "kubectl get pods -n irods-csi-driver --no-headers --ignore-not-found -l app.kubernetes.io/instance=irods-csi-driver-controller" + kubeconf | ||
|
||
pipe = os.popen(kubecommand) | ||
for line in pipe: | ||
fields = line.strip().split() | ||
if len(fields) < 5: | ||
continue | ||
|
||
podname = fields[0].strip() | ||
status = fields[2].strip() | ||
|
||
if status == "Running": | ||
kubepods.append(podname) | ||
|
||
return kubepods | ||
|
||
def get_kube_node_pods(kubeconf=""): | ||
kubepods = [] | ||
kubecommand = "kubectl get pods -n irods-csi-driver --no-headers --ignore-not-found -l app.kubernetes.io/instance=irods-csi-driver-node" + kubeconf | ||
|
||
pipe = os.popen(kubecommand) | ||
for line in pipe: | ||
fields = line.strip().split() | ||
if len(fields) < 5: | ||
continue | ||
|
||
podname = fields[0].strip() | ||
status = fields[2].strip() | ||
|
||
if status == "Running": | ||
kubepods.append(podname) | ||
|
||
return kubepods | ||
|
||
def dump_controllers(kubeconf, dumpdir): | ||
pods = get_kube_controller_pods(kubeconf) | ||
|
||
for pod in pods: | ||
for container in ["irods-plugin", "csi-provisioner"]: | ||
container_flag = " -c " + container | ||
|
||
log_filename = dumpdir + "/" + pod + "_" + container + ".log" | ||
with open(log_filename, "w") as logfile: | ||
kubecommand = "kubectl logs -n irods-csi-driver" + container_flag + kubeconf + " " + pod | ||
p = subprocess.Popen(kubecommand, shell=True, universal_newlines=True, stdout=logfile) | ||
p.wait() | ||
|
||
def dump_nodes(kubeconf, dumpdir): | ||
pods = get_kube_node_pods(kubeconf) | ||
|
||
for pod in pods: | ||
for container in ["irods-plugin", "csi-driver-registrar", "irods-pool"]: | ||
container_flag = " -c " + container | ||
|
||
log_filename = dumpdir + "/" + pod + "_" + container + ".log" | ||
with open(log_filename, "w") as logfile: | ||
kubecommand = "kubectl logs -n irods-csi-driver" + container_flag + kubeconf + " " + pod | ||
p = subprocess.Popen(kubecommand, shell=True, universal_newlines=True, stdout=logfile) | ||
p.wait() | ||
|
||
# dump irodsfs /storage/irodsfs | ||
irodsfs_dumpdir = dumpdir + "/" + pod | ||
if not os.path.exists(irodsfs_dumpdir): | ||
os.makedirs(irodsfs_dumpdir) | ||
|
||
kubecommand = "kubectl cp -c irods-plugin" + kubeconf + " irods-csi-driver/" + pod + ":/storage/irodsfs " + irodsfs_dumpdir + "/" | ||
p = subprocess.Popen(kubecommand, shell=True, universal_newlines=True, stdout=DEVNULL, stderr=DEVNULL) | ||
p.wait() | ||
|
||
|
||
parser = argparse.ArgumentParser() | ||
parser.add_argument("--kubeconfig", dest="kubeconfig", type=str, help="kubernetes configuration filepath") | ||
parser.add_argument("-o", dest="output", type=str, help="dump output directory") | ||
|
||
args = parser.parse_args() | ||
|
||
kubeconf = "" | ||
if args.kubeconfig: | ||
kubeconf = " --kubeconfig=" + args.kubeconfig | ||
|
||
now = datetime.now() | ||
dumpdir = now.strftime("irodscsi_log_%Y%m%d_%H%M%S") | ||
|
||
if args.output: | ||
dumpdir = args.output | ||
|
||
if not os.path.exists(dumpdir): | ||
os.makedirs(dumpdir) | ||
|
||
dump_controllers(kubeconf, dumpdir) | ||
dump_nodes(kubeconf, dumpdir) |
File renamed without changes.
File renamed without changes.