Skip to content

Commit

Permalink
Merge pull request #77 from fmount/18.0.0-proposed
Browse files Browse the repository at this point in the history
[18.0.0 proposed] - Do not try to get logs from non existent pods
  • Loading branch information
openshift-merge-bot[bot] authored Sep 23, 2024
2 parents 1baaaaa + 2e44c8f commit b5d0af4
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions collection-scripts/gather_ctlplane_resources
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,28 @@ function gather_ctlplane_resources {
run_bg /usr/bin/oc -n "${NS}" get pvc '>' "${NAMESPACE_PATH}/${NS}/pvc.log"
run_bg /usr/bin/oc -n "${NS}" get network-attachment-definitions -o yaml '>' "${NAMESPACE_PATH}/${NS}/nad.log"

# We make a single request to get lines in the form <pod> <container> <crash_status>
data=$(oc -n "$NS" get pod -o go-template='{{range $indexp,$pod := .items}}{{range $index,$element := $pod.status.containerStatuses}}{{printf "%s %s" $pod.metadata.name $element.name}} {{ if ne $element.lastState.terminated nil }}{{ printf "%s" $element.lastState.terminated }}{{ end }}{{ printf "\n"}}{{end}}{{end}}')
while read -r pod container crash_status; do
echo "Dump logs for ${container} from ${pod} pod";
# We make a single request to get lines in the form <pod> <container> <previous_log>
# mark pods that are in Pending state (they won't have
# a status.containerStatuses field) with a null container name
data=$(oc -n "${NS}" get pods -o json | jq -r '
.items[] |
.metadata.name as $pod |
.status.containerStatuses[]? // null |
"\($pod) \(.name) \(.lastState | if .terminated then true else false end)"
')
while read -r pod container previous; do
pod_dir="${NAMESPACE_PATH}/${NS}/pods/${pod}"
log_dir="${pod_dir}/logs"
if [ ! -d "$log_dir" ]; then
mkdir -p "$log_dir"
# describe pod
run_bg oc -n "$NS" describe pod "$pod" '>' "${pod_dir}/${pod}-describe"
fi
run_bg oc -n "$NS" logs "$pod" -c "$container" '>' "${log_dir}/${container}.log"
if [[ -n "$crash_status" ]]; then
if [ -n "${container}" ] && [ "${container}" != "null" ]; then
echo "Dump logs for ${container} from ${pod} pod";
run_bg oc -n "$NS" logs "$pod" -c "$container" '>' "${log_dir}/${container}.log"
fi
if [[ "$previous" == true ]]; then
run_bg oc -n "$NS" logs "$pod" -c "$container" --previous '>' "${log_dir}/${container}-previous.log";
fi
done <<< "$data"
Expand Down

0 comments on commit b5d0af4

Please sign in to comment.