forked from NVIDIA/gpu-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmust-gather.sh
executable file
·256 lines (201 loc) · 6.93 KB
/
must-gather.sh
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
#!/usr/bin/env bash
set -o nounset
set -x
K=kubectl
if ! $K version > /dev/null; then
K=oc
if ! $K version > /dev/null; then
echo "FATAL: neither 'kubectl' nor 'oc' appear to be working properly. Exiting ..."
exit 1
fi
fi
if [[ "$0" == "/usr/bin/gather" ]]; then
echo "Running as must-gather plugin image"
export ARTIFACT_DIR=/must-gather
else
if [ -z "${ARTIFACT_DIR:-}" ]; then
export ARTIFACT_DIR="/tmp/nvidia-gpu-operator_$(date +%Y%m%d_%H%M)"
fi
echo "Using ARTIFACT_DIR=$ARTIFACT_DIR"
fi
mkdir -p "$ARTIFACT_DIR"
echo
exec 1> >(tee $ARTIFACT_DIR/must-gather.log)
exec 2> $ARTIFACT_DIR/must-gather.stderr.log
if [[ "$0" == "/usr/bin/gather" ]]; then
echo "NVIDIA GPU Operator" > $ARTIFACT_DIR/version
echo "${VERSION:-N/A}" >> $ARTIFACT_DIR/version
fi
ocp_cluster=$($K get clusterversion/version --ignore-not-found -oname || true)
if [[ "$ocp_cluster" ]]; then
echo "Running in OpenShift."
echo "Get the cluster version"
$K get clusterversion/version -oyaml > $ARTIFACT_DIR/openshift_version.yaml
fi
echo "Get the operator namespaces"
OPERATOR_POD_NAME=$($K get pods -lapp=gpu-operator -oname -A)
if [ -z "$OPERATOR_POD_NAME" ]; then
echo "FATAL: could not find the GPU Operator Pod ..."
exit 1
fi
OPERATOR_NAMESPACE=$($K get pods -lapp=gpu-operator -A -ojsonpath={.items[].metadata.namespace} --ignore-not-found)
echo "Using '$OPERATOR_NAMESPACE' as operator namespace"
echo ""
echo "#"
echo "# ClusterPolicy"
echo "#"
echo
CLUSTER_POLICY_NAME=$($K get clusterpolicy -oname)
if [[ "$CLUSTER_POLICY_NAME" ]]; then
echo "Get $CLUSTER_POLICY_NAME"
$K get -oyaml $CLUSTER_POLICY_NAME > $ARTIFACT_DIR/cluster_policy.yaml
else
echo "Mark the ClusterPolicy as missing"
touch $ARTIFACT_DIR/cluster_policy.missing
fi
echo
echo "#"
echo "# Nodes and machines"
echo "#"
echo
if [ "$ocp_cluster" ]; then
echo "Get all the machines"
$K get machines -A > $ARTIFACT_DIR/all_machines.list
fi
echo "Get the labels of the nodes with NVIDIA PCI cards"
GPU_PCI_LABELS=(feature.node.kubernetes.io/pci-10de.present feature.node.kubernetes.io/pci-0302_10de.present feature.node.kubernetes.io/pci-0300_10de.present)
gpu_pci_nodes=""
for label in ${GPU_PCI_LABELS[@]}; do
gpu_pci_nodes="$gpu_pci_nodes $($K get nodes -l$label -oname)"
done
if [ -z "$gpu_pci_nodes" ]; then
echo "FATAL: could not find nodes with NVIDIA PCI labels"
exit 0
fi
for node in $(echo "$gpu_pci_nodes"); do
echo "$node" | cut -d/ -f2 >> $ARTIFACT_DIR/gpu_nodes.labels
$K get $node '-ojsonpath={.metadata.labels}' \
| sed 's|,|,- |g' \
| tr ',' '\n' \
| sed 's/{"/- /' \
| tr : = \
| sed 's/"//g' \
| sed 's/}/\n/' \
>> $ARTIFACT_DIR/gpu_nodes.labels
echo "" >> $ARTIFACT_DIR/gpu_nodes.labels
done
echo "Get the GPU nodes (status)"
$K get nodes -l nvidia.com/gpu.present=true -o wide > $ARTIFACT_DIR/gpu_nodes.status
echo "Get the GPU nodes (description)"
$K describe nodes -l nvidia.com/gpu.present=true > $ARTIFACT_DIR/gpu_nodes.descr
echo ""
echo "#"
echo "# Operator Pod"
echo "#"
echo
echo "Get the GPU Operator Pod (status)"
$K get $OPERATOR_POD_NAME \
-owide \
-n $OPERATOR_NAMESPACE \
> $ARTIFACT_DIR/gpu_operator_pod.status
echo "Get the GPU Operator Pod (yaml)"
$K get $OPERATOR_POD_NAME \
-oyaml \
-n $OPERATOR_NAMESPACE \
> $ARTIFACT_DIR/gpu_operator_pod.yaml
echo "Get the GPU Operator Pod logs"
$K logs $OPERATOR_POD_NAME \
-n $OPERATOR_NAMESPACE \
> "$ARTIFACT_DIR/gpu_operator_pod.log"
$K logs $OPERATOR_POD_NAME \
-n $OPERATOR_NAMESPACE \
--previous \
> "$ARTIFACT_DIR/gpu_operator_pod.previous.log"
echo ""
echo "#"
echo "# Operand Pods"
echo "#"
echo ""
echo "Get the Pods in $OPERATOR_NAMESPACE (status)"
$K get pods -owide \
-n $OPERATOR_NAMESPACE \
> $ARTIFACT_DIR/gpu_operand_pods.status
echo "Get the Pods in $OPERATOR_NAMESPACE (yaml)"
$K get pods -oyaml \
-n $OPERATOR_NAMESPACE \
> $ARTIFACT_DIR/gpu_operand_pods.yaml
echo "Get the GPU Operator Pods Images"
$K get pods -n $OPERATOR_NAMESPACE \
-o=jsonpath='{range .items[*]}{"\n"}{.metadata.name}{":\t"}{range .spec.containers[*]}{.image}{" "}{end}{end}' \
> $ARTIFACT_DIR/gpu_operand_pod_images.txt
echo "Get the description and logs of the GPU Operator Pods"
for pod in $($K get pods -n $OPERATOR_NAMESPACE -oname);
do
if ! $K get $pod -n $OPERATOR_NAMESPACE -ojsonpath={.metadata.labels} | egrep --quiet '(nvidia|gpu)'; then
echo "Skipping $pod, not a NVIDA/GPU Pod ..."
continue
fi
pod_name=$(echo "$pod" | cut -d/ -f2)
if [ $pod == $OPERATOR_POD_NAME ]; then
echo "Skipping operator pod $pod_name ..."
continue
fi
$K logs $pod \
-n $OPERATOR_NAMESPACE \
--all-containers --prefix \
> $ARTIFACT_DIR/gpu_operand_pod_$pod_name.log
$K logs $pod \
-n $OPERATOR_NAMESPACE \
--all-containers --prefix \
--previous \
> $ARTIFACT_DIR/gpu_operand_pod_$pod_name.previous.log
$K describe $pod \
-n $OPERATOR_NAMESPACE \
> $ARTIFACT_DIR/gpu_operand_pod_$pod_name.descr
done
echo ""
echo "#"
echo "# Operand DaemonSets"
echo "#"
echo ""
echo "Get the DaemonSets in $OPERATOR_NAMESPACE (status)"
$K get ds \
-n $OPERATOR_NAMESPACE \
> $ARTIFACT_DIR/gpu_operand_ds.status
echo "Get the DaemonSets in $OPERATOR_NAMESPACE (yaml)"
$K get ds -oyaml \
-n $OPERATOR_NAMESPACE \
> $ARTIFACT_DIR/gpu_operand_ds.yaml
echo "Get the description of the GPU Operator DaemonSets"
for ds in $($K get ds -n $OPERATOR_NAMESPACE -oname);
do
if ! $K get $ds -n $OPERATOR_NAMESPACE -ojsonpath={.metadata.labels} | egrep --quiet '(nvidia|gpu)'; then
echo "Skipping $ds, not a NVIDA/GPU DaemonSet ..."
continue
fi
$K describe $ds \
-n $OPERATOR_NAMESPACE \
> $ARTIFACT_DIR/gpu_operand_ds_$(echo "$ds" | cut -d/ -f2).descr
done
echo ""
echo "#"
echo "# nvidia-bug-report.sh"
echo "#"
echo ""
for pod in $($K get pods -lopenshift.driver-toolkit -oname -n $OPERATOR_NAMESPACE; $K get pods -lapp=nvidia-driver-daemonset -oname -n $OPERATOR_NAMESPACE; $K get pods -lapp=nvidia-vgpu-manager-daemonset -oname -n $OPERATOR_NAMESPACE);
do
pod_nodename=$($K get $pod -ojsonpath={.spec.nodeName} -n $OPERATOR_NAMESPACE)
echo "Saving nvidia-bug-report from ${pod_nodename} ..."
$K exec -n $OPERATOR_NAMESPACE $pod -- bash -c 'cd /tmp && nvidia-bug-report.sh' >&2 || \
(echo "Failed to collect nvidia-bug-report from ${pod_nodename}" && continue)
$K cp $OPERATOR_NAMESPACE/$(basename $pod):/tmp/nvidia-bug-report.log.gz /tmp/nvidia-bug-report.log.gz || \
(echo "Failed to save nvidia-bug-report from ${pod_nodename}" && continue)
mv /tmp/nvidia-bug-report.log.gz $ARTIFACT_DIR/nvidia-bug-report_${pod_nodename}.log.gz
done
echo ""
echo "#"
echo "# All done!"
if [[ "$0" != "/usr/bin/gather" ]]; then
echo "# Logs saved into ${ARTIFACT_DIR}."
fi
echo "#"