Skip to content

Commit

Permalink
Merge pull request #185 from black-dragon74/add-pod-info
Browse files Browse the repository at this point in the history
Include pod metadata in must-gather output
  • Loading branch information
openshift-merge-bot[bot] authored Aug 20, 2024
2 parents f4cff39 + 2522273 commit 4dabb34
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 4dabb34

Please sign in to comment.