Skip to content

Commit

Permalink
use must-gather since and since time env vars on inspect cmds
Browse files Browse the repository at this point in the history
see: openshift/must-gather#400

TODO: double check when --since got introduced on oc adm inspect
to understand if it's safe to get this also to older releases.

Signed-off-by: Simone Tiraboschi <stirabos@redhat.com>
  • Loading branch information
tiraboschi committed Apr 11, 2024
1 parent f8fa812 commit 681d2d2
Show file tree
Hide file tree
Showing 18 changed files with 66 additions and 12 deletions.
32 changes: 32 additions & 0 deletions collection-scripts/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,35 @@ 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
# shellcheck disable=SC2001
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
# shellcheck disable=SC2001
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
}
1 change: 1 addition & 0 deletions collection-scripts/gather_apiservices
Original file line number Diff line number Diff line change
Expand Up @@ -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 }')
Expand Down
7 changes: 5 additions & 2 deletions collection-scripts/gather_cdi
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -13,7 +14,8 @@ 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}"
# shellcheck disable=SC2086
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"
}

Expand All @@ -26,7 +28,8 @@ 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}"
# shellcheck disable=SC2086
/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"
}

Expand Down
3 changes: 2 additions & 1 deletion collection-scripts/gather_crds
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions collection-scripts/gather_crs
Original file line number Diff line number Diff line change
Expand Up @@ -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}')
Expand Down
1 change: 1 addition & 0 deletions collection-scripts/gather_hco
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
1 change: 1 addition & 0 deletions collection-scripts/gather_images
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 4 additions & 2 deletions collection-scripts/gather_instancetypes
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@
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}"
# shellcheck disable=SC2086
/usr/bin/oc adm inspect ${log_collection_args} --dest-dir "${BASE_COLLECTION_PATH}" -n "${oc_project}" controllerrevision "${revision_name}"
}

export -f gather_controller_revision
Expand Down
3 changes: 2 additions & 1 deletion collection-scripts/gather_nodes
Original file line number Diff line number Diff line change
Expand Up @@ -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"}

Expand Down Expand Up @@ -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}"
5 changes: 3 additions & 2 deletions collection-scripts/gather_ns
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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' -- {}
3 changes: 2 additions & 1 deletion collection-scripts/gather_resources
Original file line number Diff line number Diff line change
Expand Up @@ -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=()
Expand All @@ -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' -- {}
1 change: 1 addition & 0 deletions collection-scripts/gather_ssp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions collection-scripts/gather_virtualization
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
1 change: 1 addition & 0 deletions collection-scripts/gather_virtualmachines
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 5 additions & 2 deletions collection-scripts/gather_vms_details
Original file line number Diff line number Diff line change
Expand Up @@ -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/"
Expand All @@ -16,8 +17,10 @@ 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}"
# shellcheck disable=SC2086
/usr/bin/oc adm inspect ${log_collection_args} --dest-dir "${BASE_COLLECTION_PATH}" -n "${ocproject}" pod "$ocvm"
# shellcheck disable=SC2086
/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"
Expand Down
3 changes: 2 additions & 1 deletion collection-scripts/gather_vms_namespaces
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand All @@ -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
1 change: 1 addition & 0 deletions collection-scripts/gather_webhooks
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
1 change: 1 addition & 0 deletions collection-scripts/logs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 681d2d2

Please sign in to comment.