Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[18.0.0 proposed] - Do not try to get logs from non existent pods #77

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading