collect-logs.sh 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #!/usr/bin/env bash
  2. set -x
  3. # User parameters
  4. : "${CLUSTER_NAMESPACE:="rook-ceph"}"
  5. : "${OPERATOR_NAMESPACE:="$CLUSTER_NAMESPACE"}"
  6. : "${KUBE_SYSTEM_NAMESPACE:="kube-system"}"
  7. : "${LOG_DIR:="test"}"
  8. LOG_DIR="${LOG_DIR%/}" # remove trailing slash if necessary
  9. mkdir -p "${LOG_DIR}"
  10. CEPH_CMD="kubectl -n ${CLUSTER_NAMESPACE} exec deploy/rook-ceph-tools -- ceph --connect-timeout 10"
  11. $CEPH_CMD -s >"${LOG_DIR}"/ceph-status.txt
  12. $CEPH_CMD osd dump >"${LOG_DIR}"/ceph-osd-dump.txt
  13. $CEPH_CMD report >"${LOG_DIR}"/ceph-report.txt
  14. NAMESPACES=("$CLUSTER_NAMESPACE")
  15. if [[ "$OPERATOR_NAMESPACE" != "$CLUSTER_NAMESPACE" ]]; then
  16. NAMESPACES+=("$OPERATOR_NAMESPACE")
  17. fi
  18. # Add kube-system namespace for multus test only as we need to debug network in multus test
  19. if [ "$1" == "canary-multus" ]; then
  20. NAMESPACES+=("$KUBE_SYSTEM_NAMESPACE")
  21. fi
  22. for NAMESPACE in "${NAMESPACES[@]}"; do
  23. # each namespace is a sub-directory for easier debugging
  24. NS_DIR="${LOG_DIR}"/namespace-"${NAMESPACE}"
  25. mkdir "${NS_DIR}"
  26. # describe every one of the k8s resources in the namespace which rook commonly uses
  27. for KIND in 'pod' 'deployment' 'job' 'daemonset' 'cm'; do
  28. kubectl -n "$NAMESPACE" get "$KIND" -o wide >"${NS_DIR}"/"$KIND"-list.txt
  29. for resource in $(kubectl -n "$NAMESPACE" get "$KIND" -o jsonpath='{.items[*].metadata.name}'); do
  30. kubectl -n "$NAMESPACE" describe "$KIND" "$resource" >"${NS_DIR}"/"$KIND"-describe--"$resource".txt
  31. # collect logs for pods along the way
  32. if [[ "$KIND" == 'pod' ]]; then
  33. kubectl -n "$NAMESPACE" logs --all-containers "$resource" >"${NS_DIR}"/logs--"$resource".txt
  34. fi
  35. done
  36. done
  37. # secret need `-oyaml` to read the content instead of `describe` since secrets `describe` will be encrypted.
  38. # so keeping it in a different block.
  39. for secret in $(kubectl -n "$NAMESPACE" get secrets -o jsonpath='{.items[*].metadata.name}'); do
  40. kubectl -n "$NAMESPACE" get -o yaml secret "$secret" >"${NS_DIR}"/secret-describe--"$secret".txt
  41. done
  42. # describe every one of the custom resources in the namespace since all should be rook-related and
  43. # they aren't captured by 'kubectl get all'
  44. for CRD in $(kubectl get crds -o jsonpath='{.items[*].metadata.name}'); do
  45. for resource in $(kubectl -n "$NAMESPACE" get "$CRD" -o jsonpath='{.items[*].metadata.name}'); do
  46. crd_main_type="${CRD%%.*}" # e.g., for cephclusters.ceph.rook.io, only use 'cephclusters'
  47. kubectl -n "$NAMESPACE" get -o yaml "$CRD" "$resource" >"${NS_DIR}"/"$crd_main_type"-describe--"$resource".txt
  48. done
  49. done
  50. # do simple 'get all' calls for resources we don't often want to look at
  51. kubectl get all -n "$NAMESPACE" -o wide >"${NS_DIR}"/all-wide.txt
  52. kubectl get all -n "$NAMESPACE" -o yaml >"${NS_DIR}"/all-yaml.txt
  53. done
  54. sudo lsblk | sudo tee -a "${LOG_DIR}"/lsblk.txt
  55. journalctl -o short-precise --dmesg >"${LOG_DIR}"/dmesg.txt
  56. journalctl >"${LOG_DIR}"/journalctl.txt