Skip to content

Commit

Permalink
Merge pull request #74 from cescgina/allow_skipping_pending_pods
Browse files Browse the repository at this point in the history
Skip collecting logs from pods if they are pending
  • Loading branch information
openshift-merge-bot[bot] authored Aug 8, 2024
2 parents 47577d6 + 6ddcf8a commit f7744c2
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions collection-scripts/gather_ctlplane_resources
Original file line number Diff line number Diff line change
Expand Up @@ -62,22 +62,26 @@ function gather_ctlplane_resources {
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> <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[] |
.status.containerStatuses[]? // null |
"\($pod) \(.name) \(.lastState | if .terminated then true else false end)"
')
while read -r pod container previous; do
echo "Dump logs for ${container} from ${pod} pod";
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 "${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
Expand Down

0 comments on commit f7744c2

Please sign in to comment.