Skip to content
This repository has been archived by the owner on Apr 17, 2024. It is now read-only.

Commit

Permalink
Merge pull request #3 from koor-tech/tar_info_dump
Browse files Browse the repository at this point in the history
  • Loading branch information
galexrt authored Jun 24, 2022
2 parents 0c1b158 + 053be82 commit b850a85
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ Usage : `sh gather-logs.sh <-hd>`
* `-d` : Optional command line argument to crank up the debug logging for rook-ceph cluster.
* `-n CLUSTER_NAMESPACE`: Optional command line argument to set the rook-ceph cluster namespace.
* `-o OPERATOR_NAMESPACE`: Optional command line argument to set the rook-ceph-operator namespace.
* `-t` - Disable tar-ing the collected info to the current working dir.

The script creates a temp directory on the system prefixed with `gather-logs-`.
34 changes: 29 additions & 5 deletions gather-info.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ gatherKubernetesPodLogs() {

for p in $(kubectl -n "${CLUSTER_NAMESPACE}" get pods -o jsonpath='{.items[*].metadata.name}'); do
for c in $(kubectl -n "${CLUSTER_NAMESPACE}" get pod "${p}" -o jsonpath='{.spec.containers[*].name}'); do
echo "BEGIN logs from pod: ${p} ${c}"
echo "gather-info: BEGIN logs from pod: ${p} ${c}"
kubectl -n "${CLUSTER_NAMESPACE}" logs -c "${c}" "${p}" > "logs/${p}-${c}"
echo "END logs from pod: ${p} ${c}"
echo "gather-info: END logs from pod: ${p} ${c}"
done
done
}
Expand Down Expand Up @@ -62,6 +62,13 @@ gatherCephCommands() {
kubectl -n "${CLUSTER_NAMESPACE}" exec -it deploy/rook-ceph-tools -- ceph time-sync-status > ceph-commands/ceph_time_sync_status
}

packInfo() {
TAR_FILE="${CWD}/$(date +"%s-%Y-%m-%D")-koor-gather-info.tar.gz"

tar cfvz "${TAR_FILE}" "${INFO_TMP_DIR}"
echo "gather-info: Info dump tar available at: ${TAR_FILE}"
}

enableDebugLog() {
kubectl -n "${OPERATOR_NAMESPACE}" patch configmaps/rook-ceph-operator-config \
--type merge \
Expand All @@ -75,20 +82,24 @@ showHelp() {
echo " -d - Set Rook Ceph Operator and CSI log level to debug/trace."
echo " -n NAMESPACE - Rook Ceph Cluster namespace, default: 'rook-ceph' (CLUSTER_NAMESPACE)."
echo " -o NAMESPACE - If the operator is run separately from the cluster, specify the namespace (OPERATOR_NAMESPACE)."
echo " -t - Disable tar-ing the collected info to the current working dir."
}

LOGS_TMP_DIR="$(mktemp -d -t gather-logs-XXXXXXXXXX)"
# Save current working dir so we can later create the tar file there
CWD="$(pwd)"

cd "${LOGS_TMP_DIR}" || { echo "Failed to cd to ${LOGS_TMP_DIR} dir."; exit 1; }
INFO_TMP_DIR="$(mktemp -d -t gather-logs-XXXXXXXXXX)"
cd "${INFO_TMP_DIR}" || { echo "gather-info: Failed to cd to ${INFO_TMP_DIR} dir."; exit 1; }

# Flag Parsing BEGIN
# Reset getopts index
OPTIND=1

# Initialize settings
enable_debug_log=0
enable_pack_info=1

while getopts "h?dno:" opt; do
while getopts "h?dnot:" opt; do
case "$opt" in
h|\?)
showHelp
Expand All @@ -103,6 +114,9 @@ while getopts "h?dno:" opt; do
o)
OPERATOR_NAMESPACE="${OPTARG}"
;;
t)
enable_pack_info=0
;;
esac
done

Expand All @@ -114,10 +128,20 @@ shift $(( OPTIND - 1 ))
# Set the operator namespace to the cluster namespace if it is still empty after the flag parsing
[ -z "${OPERATOR_NAMESPACE}" ] && OPERATOR_NAMESPACE="${CLUSTER_NAMESPACE}"

echo "gather-info: Starting at $(date +%s) ..."

if [ ${enable_debug_log} = 1 ]; then
enableDebugLog
fi

gatherKubernetesPodLogs
gatherKubernetesObjects
gatherCephCommands

if [ ${enable_pack_info} = 1 ]; then
packInfo
else
echo "gather-info: Skipped tar packing of info dump."
fi

echo "gather-info: Starting at $(date +%s) ..."

0 comments on commit b850a85

Please sign in to comment.