1+ #! /usr/bin/env bash
2+ set +x
3+
4+ print_usage () {
5+ echo " Usage:"
6+ echo " ./diagnose-fluid-curvine.sh COMMAND [OPTIONS]"
7+ echo " COMMAND:"
8+ echo " help"
9+ echo " Display this help message."
10+ echo " collect"
11+ echo " Collect pods logs of controller and runtime."
12+ echo " OPTIONS:"
13+ echo " -r, --name name"
14+ echo " Set the name of runtime."
15+ echo " -n, --namespace name"
16+ echo " Set the namespace of runtime."
17+ echo " --collect-path"
18+ echo " Set which file the information is collected into. (default: $( pwd) /diagnose_fluid_\$ {timestamp}.tar.gz)"
19+ }
20+
21+ run () {
22+ echo
23+ echo " -----------------run $* ------------------"
24+ timeout 10s " $@ "
25+ if [ $? != 0 ]; then
26+ echo " failed to collect info: $* "
27+ fi
28+ echo " ------------End of ${1} ----------------"
29+ }
30+
31+ pod_status () {
32+ local namespace=${1:- " default" }
33+ run kubectl get pods -owide -n ${namespace} & > " $diagnose_dir /pods-${namespace} .log"
34+ run kubectl get pods -oyaml -n ${namespace} & >> " $diagnose_dir /pods-${namespace} .log"
35+ }
36+
37+ fluid_pod_logs () {
38+ core_component " ${fluid_namespace} " " manager" " control-plane=cacheruntime-controller"
39+ core_component " ${fluid_namespace} " " manager" " control-plane=dataset-controller"
40+ core_component " ${fluid_namespace} " " plugins" " app=csi-nodeplugin-fluid"
41+ core_component " ${fluid_namespace} " " node-driver-registrar" " app=csi-nodeplugin-fluid"
42+ }
43+
44+ runtime_pod_logs () {
45+ core_component " ${runtime_namespace} " " master" " cacheruntime.fluid.io/component-name=${runtime_name} -master"
46+ core_component " ${runtime_namespace} " " worker" " cacheruntime.fluid.io/component-name=${runtime_name} -worker"
47+ core_component " ${runtime_namespace} " " client" " cacheruntime.fluid.io/component-name=${runtime_name} -client"
48+ }
49+
50+ core_component () {
51+ # namespace container selectors...
52+ local namespace=" $1 "
53+ local container=" $2 "
54+ shift 2
55+ local selectors=" $* "
56+ local constrains
57+ local pods
58+ constrains=$( echo " ${selectors} " | tr ' ' ' ,' )
59+ if [[ -n ${constrains} ]]; then
60+ constrains=" -l ${constrains} "
61+ fi
62+ mkdir -p " $diagnose_dir /pods-${namespace} "
63+ pods=$( kubectl get po -n ${namespace} " ${constrains} " | awk ' {print $1}' | grep -v NAME)
64+ for po in ${pods} ; do
65+ kubectl logs " ${po} " -c " $container " -n ${namespace} & > " $diagnose_dir /pods-${namespace} /${po} -${container} .log" 2>&1
66+ done
67+ }
68+
69+ kubectl_resource () {
70+ # runtime, dataset, pv and pvc should have the same name
71+ kubectl describe dataset --namespace ${runtime_namespace} ${runtime_name} & > " ${diagnose_dir} /dataset-${runtime_name} .yaml" 2>&1
72+ kubectl describe cacheruntime --namespace ${runtime_namespace} ${name} & > " ${diagnose_dir} /cacheruntime-${runtime_name} .yaml" 2>&1
73+ kubectl describe pv ${runtime_namespace} -${runtime_name} & > " ${diagnose_dir} /pv-${runtime_name} .yaml" 2>&1
74+ kubectl describe pvc ${runtime_name} --namespace ${runtime_namespace} & > " ${diagnose_dir} /pvc-${runtime_name} .yaml" 2>&1
75+ }
76+
77+ archive () {
78+ tar_filename=" ${current_dir} /diagnose_fluid_${timestamp} .tar.gz"
79+ if [[ ! -z " ${collect_path} " ]]; then
80+ tar_filename=${collect_path}
81+ mkdir -p $( dirname " $tar_filename " )
82+ fi
83+ tar -zcvf " ${tar_filename} " " ${diagnose_dir} "
84+ echo " please get ${tar_filename} for diagnostics"
85+ }
86+
87+ pd_collect () {
88+ echo " Start collecting, runtime-name=${runtime_name} , runtime-namespace=${runtime_namespace} "
89+
90+ pod_status " ${fluid_namespace} "
91+ pod_status " ${runtime_namespace} "
92+ runtime_pod_logs
93+ fluid_pod_logs
94+ kubectl_resource
95+ archive
96+ }
97+
98+ collect ()
99+ {
100+ # ensure params
101+ fluid_name=${fluid_name:- " fluid" }
102+ fluid_namespace=${fluid_namespace:- " fluid-system" }
103+ runtime_name=${runtime_name:? " the name of runtime must be set" }
104+ runtime_namespace=${runtime_namespace:- " default" }
105+
106+ current_dir=$( pwd)
107+ timestamp=$( date +%s)
108+ diagnose_dir=" /tmp/diagnose_fluid_${timestamp} "
109+ mkdir -p " $diagnose_dir "
110+
111+ pd_collect
112+ }
113+
114+ main () {
115+ if [[ $# -eq 0 ]]; then
116+ print_usage
117+ exit 1
118+ fi
119+
120+ action=" help"
121+
122+ while [[ $# -gt 0 ]]; do
123+ case $1 in
124+ -h|--help|" -?" )
125+ print_usage
126+ exit 0;
127+ ;;
128+ collect|help)
129+ action=$1
130+ ;;
131+ -r|--name)
132+ runtime_name=$2
133+ shift
134+ ;;
135+ -n|--namespace)
136+ runtime_namespace=$2
137+ shift
138+ ;;
139+ --collect-path)
140+ collect_path=$2
141+ shift
142+ ;;
143+ * )
144+ echo " Error: unsupported option $1 " >&2
145+ print_usage
146+ exit 1
147+ ;;
148+ esac
149+ shift
150+ done
151+
152+ case ${action} in
153+ collect)
154+ collect
155+ ;;
156+ help)
157+ print_usage
158+ ;;
159+ esac
160+ }
161+
162+ main " $@ "
0 commit comments