diff --git a/collection-scripts/gather_ctlplane_resources b/collection-scripts/gather_ctlplane_resources index 5407365..bac6e8c 100755 --- a/collection-scripts/gather_ctlplane_resources +++ b/collection-scripts/gather_ctlplane_resources @@ -61,10 +61,16 @@ 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 - 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 + # 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 @@ -72,8 +78,11 @@ function gather_ctlplane_resources { # 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"