diff --git a/collection-scripts/common.sh b/collection-scripts/common.sh index 62312ff..dcd77db 100755 --- a/collection-scripts/common.sh +++ b/collection-scripts/common.sh @@ -13,3 +13,33 @@ function check_command { fi } +get_log_collection_args() { + # validation of MUST_GATHER_SINCE and MUST_GATHER_SINCE_TIME is done by the + # caller (oc adm must-gather) so it's safe to use the values as they are. + log_collection_args="" + + if [ -n "${MUST_GATHER_SINCE:-}" ]; then + log_collection_args=--since="${MUST_GATHER_SINCE}" + fi + if [ -n "${MUST_GATHER_SINCE_TIME:-}" ]; then + log_collection_args=--since-time="${MUST_GATHER_SINCE_TIME}" + fi + + # oc adm node-logs `--since` parameter is not the same as oc adm inspect `--since`. + # it takes a simplified duration in the form of '(+|-)[0-9]+(s|m|h|d)' or + # an ISO formatted time. since MUST_GATHER_SINCE and MUST_GATHER_SINCE_TIME + # are formatted differently, we re-format them so they can be used + # transparently by node-logs invocations. + node_log_collection_args="" + + if [ -n "${MUST_GATHER_SINCE:-}" ]; then + since=$(echo "${MUST_GATHER_SINCE:-}" | sed 's/\([0-9]*[dhms]\).*/\1/') + node_log_collection_args=--since="-${since}" + fi + if [ -n "${MUST_GATHER_SINCE_TIME:-}" ]; then + iso_time=$(echo "${MUST_GATHER_SINCE_TIME}" | sed 's/T/ /; s/Z//') + node_log_collection_args=--since="${iso_time}" + fi + export log_collection_args + export node_log_collection_args +} diff --git a/collection-scripts/gather_apiservices b/collection-scripts/gather_apiservices index 5b0467f..480c4b4 100755 --- a/collection-scripts/gather_apiservices +++ b/collection-scripts/gather_apiservices @@ -3,6 +3,7 @@ DIR_NAME=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) source "${DIR_NAME}/common.sh" check_command +get_log_collection_args # Resource list resources=$(/usr/bin/oc get apiservices | grep kubevirt.io | awk '{ print $1 }') diff --git a/collection-scripts/gather_cdi b/collection-scripts/gather_cdi index c7ba370..cddfe88 100755 --- a/collection-scripts/gather_cdi +++ b/collection-scripts/gather_cdi @@ -3,6 +3,7 @@ DIR_NAME=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) source "${DIR_NAME}/common.sh" check_command +get_log_collection_args function gather_cdi_pod() { line=$1 @@ -13,7 +14,7 @@ function gather_cdi_pod() { pod_collection_path="${BASE_COLLECTION_PATH}/namespaces/${ns}/${pod}" mkdir -p "${pod_collection_path}" - oc adm inspect --dest-dir "${BASE_COLLECTION_PATH}" -n "${ns}" "pod/${pod}" + oc adm inspect ${log_collection_args} --dest-dir "${BASE_COLLECTION_PATH}" -n "${ns}" "pod/${pod}" oc logs "${pod}" -n "${ns}" > "${pod_collection_path}/${pod}.log" } @@ -26,7 +27,7 @@ function gather_pvc() { pvc_collection_path="${BASE_COLLECTION_PATH}/namespaces/${ns}/core/persistentvolumeclaims" mkdir -p "$pvc_collection_path" - /usr/bin/oc adm inspect --dest-dir "${BASE_COLLECTION_PATH}" -n "${ns}" "pvc/${pvc}" + /usr/bin/oc adm inspect ${log_collection_args} --dest-dir "${BASE_COLLECTION_PATH}" -n "${ns}" "pvc/${pvc}" oc describe pvc "${pvc}" -n "${ns}" > "${pvc_collection_path}/${pvc}_describe.txt" } diff --git a/collection-scripts/gather_crds b/collection-scripts/gather_crds index ac180bf..72ebd28 100755 --- a/collection-scripts/gather_crds +++ b/collection-scripts/gather_crds @@ -3,11 +3,12 @@ DIR_NAME=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) source "${DIR_NAME}/common.sh" check_command +get_log_collection_args # Resource list CRDS=$(/usr/bin/oc get crd | grep kubevirt.io | awk '{print $1}') # Run the collection of crds using must-gather -echo "${CRDS[@]}" | tr ' ' '\n' | xargs -t -I{} -P "${PROS}" --max-args=1 sh -c '/usr/bin/oc adm inspect crd --dest-dir ${BASE_COLLECTION_PATH} $1' -- {} +echo "${CRDS[@]}" | tr ' ' '\n' | xargs -t -I{} -P "${PROS}" --max-args=1 sh -c '/usr/bin/oc adm inspect ${log_collection_args} crd --dest-dir ${BASE_COLLECTION_PATH} $1' -- {} exit 0 diff --git a/collection-scripts/gather_crs b/collection-scripts/gather_crs index 772aace..11b5708 100755 --- a/collection-scripts/gather_crs +++ b/collection-scripts/gather_crs @@ -3,6 +3,7 @@ DIR_NAME=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) source "${DIR_NAME}/common.sh" check_command +get_log_collection_args function get_cr() { ocobject=$(echo "$2" | awk -F_ '{print $1}') diff --git a/collection-scripts/gather_hco b/collection-scripts/gather_hco index 83bec1f..9b832e3 100755 --- a/collection-scripts/gather_hco +++ b/collection-scripts/gather_hco @@ -3,6 +3,7 @@ DIR_NAME=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) source "${DIR_NAME}/common.sh" check_command +get_log_collection_args IFS=$'\n' diff --git a/collection-scripts/gather_images b/collection-scripts/gather_images index ba76540..735f2f1 100755 --- a/collection-scripts/gather_images +++ b/collection-scripts/gather_images @@ -3,6 +3,7 @@ DIR_NAME=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) source "${DIR_NAME}/common.sh" check_command +get_log_collection_args # Workaround for: https://github.com/openshift/must-gather/issues/122 diff --git a/collection-scripts/gather_instancetypes b/collection-scripts/gather_instancetypes index 268286c..a9485ec 100755 --- a/collection-scripts/gather_instancetypes +++ b/collection-scripts/gather_instancetypes @@ -3,17 +3,18 @@ DIR_NAME=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) source "${DIR_NAME}/common.sh" check_command +get_log_collection_args resources=(virtualmachineinstancetype virtualmachineclusterinstancetype virtualmachinepreference virtualmachineclusterpreference) -echo "${resources[@]}" | tr ' ' '\n' | xargs -t -I{} -P "${PROS}" --max-args=1 sh -c 'echo "inspecting $1" && oc adm inspect --dest-dir ${BASE_COLLECTION_PATH} --all-namespaces $1' -- {} +echo "${resources[@]}" | tr ' ' '\n' | xargs -t -I{} -P "${PROS}" --max-args=1 sh -c 'echo "inspecting $1" && oc adm inspect ${log_collection_args} --dest-dir ${BASE_COLLECTION_PATH} --all-namespaces $1' -- {} function gather_controller_revision() { oc_project=$(echo "$1" | awk -F_ '{print $1}') revision_name=$(echo "$1" | awk -F_ '{print $2}') echo "inspecting ${revision_name} controller revision" - /usr/bin/oc adm inspect --dest-dir "${BASE_COLLECTION_PATH}" -n "${oc_project}" controllerrevision "${revision_name}" + /usr/bin/oc adm inspect ${log_collection_args} --dest-dir "${BASE_COLLECTION_PATH}" -n "${oc_project}" controllerrevision "${revision_name}" } export -f gather_controller_revision diff --git a/collection-scripts/gather_nodes b/collection-scripts/gather_nodes index fffbca8..b1730f8 100755 --- a/collection-scripts/gather_nodes +++ b/collection-scripts/gather_nodes @@ -3,6 +3,7 @@ DIR_NAME=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) source "${DIR_NAME}/common.sh" check_command +get_log_collection_args MANIFEST_PATH=${MANIFEST_PATH:-"/etc"} @@ -111,7 +112,7 @@ echo "${pods[@]}" | tr ' ' '\n' | xargs -t -I{} -P "${PROS}" --max-args=1 sh -c # Collect journal logs for specified units for all nodes nodes=$(oc get nodes --no-headers -o custom-columns=':metadata.name') -echo "${nodes[@]}" | tr ' ' '\n' | xargs -t -I{} -P "${PROS}" --max-args=1 sh -c 'mkdir -p $2; oc adm node-logs $1 -u NetworkManager > $2/${1}_logs_NetworkManager' -- {} "${NODES_PATH}"/{} +echo "${nodes[@]}" | tr ' ' '\n' | xargs -t -I{} -P "${PROS}" --max-args=1 sh -c 'mkdir -p $2; oc adm node-logs ${node_log_collection_args} $1 -u NetworkManager > $2/${1}_logs_NetworkManager' -- {} "${NODES_PATH}"/{} oc delete -f "${DAEMONSET_MANIFEST}" oc delete -f "${CRD_MANIFEST}" diff --git a/collection-scripts/gather_ns b/collection-scripts/gather_ns index f76509f..4f79eda 100755 --- a/collection-scripts/gather_ns +++ b/collection-scripts/gather_ns @@ -2,7 +2,8 @@ DIR_NAME=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) source "${DIR_NAME}/common.sh" -check_command +#check_command +get_log_collection_args namespaces=() # KubeVirt HCO related namespaces @@ -23,4 +24,4 @@ namespaces+=(openshift-virtualization-os-images) resources+=(cdi) # Run the collection of namespaces using must-gather -echo "${namespaces[@]}" | tr ' ' '\n' | xargs -t -I{} -P "${PROS}" --max-args=1 sh -c 'echo inspecting namespace $1 && oc adm inspect --dest-dir "${BASE_COLLECTION_PATH}" namespace $1' -- {} +echo "${namespaces[@]}" | tr ' ' '\n' | xargs -t -I{} -P "${PROS}" --max-args=1 sh -c 'echo inspecting namespace $1 && oc adm inspect ${log_collection_args} --dest-dir "${BASE_COLLECTION_PATH}" namespace $1' -- {} diff --git a/collection-scripts/gather_resources b/collection-scripts/gather_resources index f10dee8..080f6d5 100755 --- a/collection-scripts/gather_resources +++ b/collection-scripts/gather_resources @@ -3,6 +3,7 @@ DIR_NAME=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) source "${DIR_NAME}/common.sh" check_command +get_log_collection_args # Resource list resources=() @@ -25,4 +26,4 @@ resources+=(machines) "${DIR_NAME}"/version # Run the collection of resources using must-gather -echo "${resources[@]}" | tr ' ' '\n' | xargs -t -I{} -P "${PROS}" --max-args=1 sh -c 'echo "inspecting $1" && oc adm inspect --dest-dir ${BASE_COLLECTION_PATH} --all-namespaces $1' -- {} +echo "${resources[@]}" | tr ' ' '\n' | xargs -t -I{} -P "${PROS}" --max-args=1 sh -c 'echo "inspecting $1" && oc adm inspect ${log_collection_args} --dest-dir ${BASE_COLLECTION_PATH} --all-namespaces $1' -- {} diff --git a/collection-scripts/gather_ssp b/collection-scripts/gather_ssp index fa16f95..d90a02f 100755 --- a/collection-scripts/gather_ssp +++ b/collection-scripts/gather_ssp @@ -3,6 +3,7 @@ DIR_NAME=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) source "${DIR_NAME}/common.sh" check_command +get_log_collection_args # we expect the KubeVirt templates to be deployed only in the `opneshift` namespace. But if this turns out not to be true, we need to know. namespaces=$(/usr/bin/oc get templates --all-namespaces -l 'template.kubevirt.io/type=base' -o jsonpath='{range .items[*]}{.metadata.namespace}{"\n"}{end}' | uniq) diff --git a/collection-scripts/gather_virtualization b/collection-scripts/gather_virtualization index ef8c973..c8fb06d 100755 --- a/collection-scripts/gather_virtualization +++ b/collection-scripts/gather_virtualization @@ -3,6 +3,7 @@ DIR_NAME=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) source "${DIR_NAME}/common.sh" check_command +get_log_collection_args VIRTUALIZATION_PATH="${BASE_COLLECTION_PATH}/virtualization" mkdir -p "${VIRTUALIZATION_PATH}" diff --git a/collection-scripts/gather_virtualmachines b/collection-scripts/gather_virtualmachines index d399793..333fa53 100755 --- a/collection-scripts/gather_virtualmachines +++ b/collection-scripts/gather_virtualmachines @@ -3,6 +3,7 @@ DIR_NAME=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) source "${DIR_NAME}/common.sh" check_command +get_log_collection_args vmConvertor diff --git a/collection-scripts/gather_vms_details b/collection-scripts/gather_vms_details index b4db517..954a37c 100755 --- a/collection-scripts/gather_vms_details +++ b/collection-scripts/gather_vms_details @@ -3,6 +3,7 @@ DIR_NAME=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) source "${DIR_NAME}/common.sh" check_command +get_log_collection_args export QEMULOGPATH_1="/var/log/libvirt/qemu/" export QEMULOGPATH_2="/var/run/libvirt/qemu/log/" @@ -16,8 +17,8 @@ function gather_vm_info() { vm_collection_path="${BASE_COLLECTION_PATH}/namespaces/${ocproject}/vms/${vmname}" mkdir -p "${vm_collection_path}" - /usr/bin/oc adm inspect --dest-dir "${BASE_COLLECTION_PATH}" -n "${ocproject}" pod "$ocvm" - /usr/bin/oc adm inspect --dest-dir "${BASE_COLLECTION_PATH}" -n "${ocproject}" virtualmachineinstances "${vmname}" + /usr/bin/oc adm inspect ${log_collection_args} --dest-dir "${BASE_COLLECTION_PATH}" -n "${ocproject}" pod "$ocvm" + /usr/bin/oc adm inspect ${log_collection_args} --dest-dir "${BASE_COLLECTION_PATH}" -n "${ocproject}" virtualmachineinstances "${vmname}" # VM : capabilities /usr/bin/oc exec "${ocvm}" -n "${ocproject}" -c compute -- virsh -r capabilities > "${vm_collection_path}/${ocvm}.capabilities.xml" diff --git a/collection-scripts/gather_vms_namespaces b/collection-scripts/gather_vms_namespaces index 3d4bf8d..d33e82c 100755 --- a/collection-scripts/gather_vms_namespaces +++ b/collection-scripts/gather_vms_namespaces @@ -3,6 +3,7 @@ DIR_NAME=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) source "${DIR_NAME}/common.sh" check_command +get_log_collection_args if [[ -n $NS ]]; then namespaces="${NS}" @@ -11,6 +12,6 @@ else fi # Run the collection of namespaces using must-gather -echo "${namespaces[@]}" | tr ' ' '\n' | xargs -t -I{} -P "${PROS}" --max-args=1 sh -c 'echo "inspecting namespace $1" && /usr/bin/oc adm inspect --dest-dir ${BASE_COLLECTION_PATH} namespace $1' -- {} +echo "${namespaces[@]}" | tr ' ' '\n' | xargs -t -I{} -P "${PROS}" --max-args=1 sh -c 'echo "inspecting namespace $1" && /usr/bin/oc adm inspect ${log_collection_args} --dest-dir ${BASE_COLLECTION_PATH} namespace $1' -- {} exit 0 diff --git a/collection-scripts/gather_webhooks b/collection-scripts/gather_webhooks index a3113b8..3cb12b3 100755 --- a/collection-scripts/gather_webhooks +++ b/collection-scripts/gather_webhooks @@ -3,6 +3,7 @@ DIR_NAME=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) source "${DIR_NAME}/common.sh" check_command +get_log_collection_args function gather_validating_wh() { webhooks_collection_path=${BASE_COLLECTION_PATH}/webhooks/validating/${1} diff --git a/collection-scripts/logs.sh b/collection-scripts/logs.sh index 8cd065b..31e50e2 100755 --- a/collection-scripts/logs.sh +++ b/collection-scripts/logs.sh @@ -3,6 +3,7 @@ DIR_NAME=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) source "${DIR_NAME}/common.sh" check_command +get_log_collection_args NAMESPACE_FILE=/var/run/secrets/kubernetes.io/serviceaccount/namespace