Skip to content

Commit

Permalink
Include pod metadata in must-gather output
Browse files Browse the repository at this point in the history
This PR adds support of fetching the pod metadata
using the kubernetes API.

An additional pod-metadata.json file is created in the
report with the dump of entire metadata for the pod.

A much simpler debug log stating the image version being
used is printed to the console as well.

Signed-off-by: Niraj Yadav <[email protected]>
  • Loading branch information
black-dragon74 authored and openshift-cherrypick-robot committed Aug 20, 2024
1 parent 4ad8cfa commit 868d81e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
3 changes: 3 additions & 0 deletions collection-scripts/gather
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ START_TIME=$(date +%r)
start=$(date +%s)
dbglog "collection started at: ${START_TIME}"

# Print and export must-gather pod details
export_pod_image_details

if [ -n "${LOG_FILTER_ARGS:-}" ]; then
dbglog "Logs will be filtered using: ${LOG_FILTER_ARGS}"
fi
Expand Down
27 changes: 27 additions & 0 deletions collection-scripts/utils.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env bash
# shellcheck disable=SC2155

#
# Please Note:
Expand Down Expand Up @@ -79,7 +80,33 @@ parse_since_time() {
fi
}

# export_pod_image_details fetches the pod metadata
# using kubernetes API
function export_pod_image_details() {
# We do not override the hostname in odf-mg, hence hostname = pod name
local POD_NAME=$(hostname)

# Kubernetes API token and endpoints
local API_URL="https://kubernetes.default.svc"
local NAMESPACE=$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace)
local TOKEN=$(cat /var/run/secrets/kubernetes.io/serviceaccount/token)

# Get pod metadata
local POD_METADATA=$(curl -s --cacert /var/run/secrets/kubernetes.io/serviceaccount/ca.crt \
-H "Authorization: Bearer $TOKEN" \
"$API_URL/api/v1/namespaces/$NAMESPACE/pods/$POD_NAME")

# Extract image details
local IMAGE=$(echo "$POD_METADATA" | awk -F'"' '/"image":/ {print $4; exit}')

# Also save the pod metadata to a file
echo "$POD_METADATA" >"${BASE_COLLECTION_PATH}"/pod-metadata.json

dbglog "must-gather is using image: $IMAGE"
}

# Export the functions so that the file needs to be sourced only once
export -f dbglog
export -f dbglogf
export -f parse_since_time
export -f export_pod_image_details

0 comments on commit 868d81e

Please sign in to comment.