-
Notifications
You must be signed in to change notification settings - Fork 69
Description
It would be good to collect the logs locally from where you ran the hpe-logcollector.sh instead of having to go to each node in the cluster so make sure customer is providing all the necessary logs from the start ensuring a faster resolution. Created an example for collecting the node logs:
./local_copy.sh
Collecting newest archive from hpe-csi-node-266tz ...
-> /var/log/hpe-storage-logs-ocp-w-2.lab.ocp.lan-20260112_152015.tar.gz -> saving as ./hpe-storage-logs-ocp-w-2.lab.ocp.lan-20260112_152015.tar.gz
Collecting newest archive from hpe-csi-node-tk7fh ...
-> /var/log/hpe-storage-logs-ocp-w-1.lab.ocp.lan-20260112_152018.tar.gz -> saving as ./hpe-storage-logs-ocp-w-1.lab.ocp.lan-20260112_152018.tar.gz
[root@ocp-svc ~]# ll hpe-storage-logs-ocp-w-*
-rw-r--r-- 1 root root 2.5M Jan 12 11:20 hpe-storage-logs-ocp-w-1.lab.ocp.lan-20260112_152018.tar.gz
-rw-r--r-- 1 root root 3.5M Jan 12 11:20 hpe-storage-logs-ocp-w-2.lab.ocp.lan-20260112_152015.tar.gz
#!/bin/bash
set -euo pipefail
NS=hpe-storage
CONTAINER=hpe-csi-driver
kubectl get pods -n "$NS" -l app=hpe-csi-node \
-o jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}' \
| while read -r POD; do
echo "Collecting newest archive from ${POD} ..."
# Find the newest matching tarball inside the pod and print its path and basename
read -r REMOTE_PATH REMOTE_BASE <<EOF
$(kubectl exec -n "$NS" "$POD" -c "$CONTAINER" -- /bin/bash -c '
ARCHIVE=$(ls -t /var/log/hpe-storage*.tar.gz 2>/dev/null | head -1)
if [ -z "$ARCHIVE" ]; then
echo "NOARCHIVE NOARCHIVE"; exit 0
fi
echo "$ARCHIVE $(basename "$ARCHIVE")"
')
EOF
if [ "$REMOTE_PATH" = "NOARCHIVE" ]; then
echo " No archive found in ${POD}"
continue
fi
echo " -> $REMOTE_PATH -> saving as ./$REMOTE_BASE"
kubectl exec -n "$NS" "$POD" -c "$CONTAINER" -- /bin/bash -c "cat '$REMOTE_PATH'" > "$REMOTE_BASE"
done