forked from purestorage/pso-csi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpso-collect-logs.sh
More file actions
120 lines (95 loc) · 3.96 KB
/
pso-collect-logs.sh
File metadata and controls
120 lines (95 loc) · 3.96 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
FULL_MODE="false"
while [ -n "$1" ]; do # while loop starts
case "$1" in
--full)
echo "--full option specified"
FULL_MODE="true";;
--help)
echo -e "Usage: *.bash [OPTION]"
echo -e "If kubeconfig is not configured please run: export KUBECONFIG=[kube-config-file]\n"
echo -e "--full: full log mode, collect pod information outside of PSO and kube-system namespace, please make sure there is no sensitive information."
exit;;
*)
echo "Option $1 not recognized, use --help for more information."
exit;;
esac
shift
done
if [ "$FULL_MODE" == "false" ]; then
tput setaf 2;
echo -e "Will not collect user application info, if there is PVC mount issue, please run with --full option to collect info for all pods in all namespaces, make sure there is no sensitive info."
tput sgr0
fi
KUBECTL=kubectl
if [ -n "$(which oc)" ]; then
echo "oc exists, use oc instead of kubectl"
KUBECTL=oc
fi
LOG_DIR=./pso-logs
PSO_NS=$($KUBECTL get pod -o wide --all-namespaces | grep pso-csi-controller-0 | awk '{print $1}')
tput setaf 2;
echo -e "PSO namespace is $PSO_NS, overwritting log dir $LOG_DIR\n"
tput sgr0
DB_REPLICAS=$($KUBECTL get statefulset -n $PSO_NS | awk '{print $1}' | grep pso-db-)
PODS=$($KUBECTL get pod -n $PSO_NS | awk '{print $1}' | grep -e pso-db- -e pso-csi-)
rm $LOG_DIR -r
mkdir $LOG_DIR
if [[ $KUBECTL == "oc" ]]; then
echo "collect scc info"
# Get log for scc which only exists in openshift cluster, in case oc exists but the cluster is k8s cluster
# we will get "resource type does not exist", which is ok.
oc get scc -o wide > $LOG_DIR/scc.log 2>/dev/null
echo -e "\n" >> $LOG_DIR/scc.log
oc describe scc >> $LOG_DIR/scc.log 2>/dev/null
fi
for pod in $PODS
do
echo "collect logs for pod $pod"
# Get log of volume-publish container and cockroachdb container for pso-db-*-0 pods.
if [[ $pod == "pso-db-"*"-0" ]]; then
$KUBECTL logs $pod -c volume-publish -n $PSO_NS > $LOG_DIR/$pod-volume-publish.log
$KUBECTL logs $pod -c cockroachdb -n $PSO_NS > $LOG_DIR/$pod-cockroachdb.log
fi
if [[ $pod == *"cockroach-operator"* ]]; then
$KUBECTL logs $pod -c cockroach-operator -n $PSO_NS > $LOG_DIR/$pod.log
fi
if [[ $pod == *"db-deployer"* ]]; then
$KUBECTL logs $pod -c db-deployer -n $PSO_NS > $LOG_DIR/$pod.log
fi
if [[ $pod == *"pso-csi-"* ]]; then
$KUBECTL logs $pod -c pso-csi-container -n $PSO_NS > $LOG_DIR/$pod.log
fi
done
if [ "$FULL_MODE" == "true" ]; then
echo "collect info for all pods in all namespaces"
$KUBECTL get pod --all-namespaces -o wide > $LOG_DIR/all-pods.log
echo -e "\n" >> $LOG_DIR/all-pods.log
$KUBECTL describe pod --all-namespaces >> $LOG_DIR/all-pods.log
else
echo "collect info for pods in PSO namespace $PSO_NS and kube-system namespace"
$KUBECTL get pod -n $PSO_NS -o wide > $LOG_DIR/all-pods.log
$KUBECTL get pod -n kube-system -o wide >> $LOG_DIR/all-pods.log
echo -e "\n" >> $LOG_DIR/all-pods.log
$KUBECTL describe pod -n $PSO_NS >> $LOG_DIR/all-pods.log
$KUBECTL describe pod -n kube-system >> $LOG_DIR/all-pods.log
fi
echo "collect logs for all nodes"
$KUBECTL get node -o wide > $LOG_DIR/all-nodes.log
echo "collect logs for all pvcs"
$KUBECTL get pvc -o wide > $LOG_DIR/all-pvcs.log
echo -e "\n" >> $LOG_DIR/all-pvcs.log
$KUBECTL describe pvc >> $LOG_DIR/all-pvcs.log
echo "collect logs for all pvs"
$KUBECTL get pv -o wide > $LOG_DIR/all-pvs.log
echo -e "\n" >> $LOG_DIR/all-pvs.log
$KUBECTL describe pv >> $LOG_DIR/all-pvs.log
echo "collect logs for all resources in PSO namespace"
$KUBECTL get all -o wide -n $PSO_NS > $LOG_DIR/all-resource.log
echo -e "\n" >> $LOG_DIR/all-resource.log
# Supress potential error: Error from server (NotFound): the server could not find the requested resource
$KUBECTL describe all -n $PSO_NS >> $LOG_DIR/all-resource.log 2>/dev/null
COMPRESS_FILE=pso-logs-$(date "+%Y.%m.%d-%H.%M.%S").tar.gz
tput setaf 2;
echo -e "Compressing log folder $LOG_DIR into $COMPRESS_FILE"
tput sgr0
tar -czvf $COMPRESS_FILE $LOG_DIR >/dev/null