|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Default to gathering 72h of logs unless specified as var |
| 4 | +logs_since="${logs_since:-72h}" |
| 5 | +request_timeout="${request_timeout:-0s}" |
| 6 | +max_parallelism=10 |
| 7 | +unset KUBECONFIG |
| 8 | + |
| 9 | +clusterID=$(oc get clusterversion -o jsonpath='{.items[].spec.clusterID}' | cut -c -8) |
| 10 | +namespaces=() |
| 11 | +for ns in $(oc get dataprotectionapplications.oadp.openshift.io --all-namespaces --no-headers | awk '{print $1}') |
| 12 | + do |
| 13 | + echo "[namespace=${ns}] Detected OADP operator installation" |
| 14 | + namespaces+=(${ns}) |
| 15 | + done |
| 16 | +# Collect all resources in OADP operator namespaces with must-gather |
| 17 | +for ns in ${namespaces[@]}; do |
| 18 | + echo "[namespace=${ns}] Running oc adm inspect" |
| 19 | + /usr/bin/oc adm inspect --dest-dir must-gather/clusters/${clusterID} --all-namespaces ns/${ns} & |
| 20 | +done |
| 21 | + |
| 22 | +# Collect the logs" |
| 23 | +for ns in ${namespaces[@]}; do |
| 24 | + echo "[cluster=${clusterID}] Gathering logs for namespace ${ns}]" |
| 25 | + /usr/bin/gather_logs_pods ${clusterID} ${ns} ${logs_since} ${max_parallelism} & |
| 26 | +done |
| 27 | + |
| 28 | +# Collect the DPA CR |
| 29 | +for ns in ${namespaces[@]}; do |
| 30 | + for dpa in $(oc get dpa --namespace ${ns} --no-headers | awk '{print $1}'); do |
| 31 | + mkdir -p "/must-gather/clusters/${clusterID}/namespaces/${ns}/oadp.openshift.io/dpa-${dpa}" |
| 32 | + oc get dpa ${dpa} -o yaml --namespace ${ns} &> "/must-gather/clusters/${clusterID}/namespaces/${ns}/oadp.openshift.io/dpa-${dpa}/${dpa}.yml" & |
| 33 | + pwait $max_parallelism |
| 34 | + done |
| 35 | +done |
| 36 | + |
| 37 | +# Waits for gather_crs, gather_logs, gather_metrics running in background |
| 38 | +echo "Waiting for background gather tasks to finish" |
| 39 | +wait |
| 40 | + |
| 41 | +# If running essential-only must-gather, delete duplicated logs collected by oc adm inspect |
| 42 | +if [ -z "$essential_only" ]; then |
| 43 | + echo "Full must-gather was requested. Keeping full log payload from oc adm inspect" |
| 44 | +else |
| 45 | + echo "Essential-only must-gather was requested. Removing duplicate pod logs from oc adm inspect to reduce must-gather size" |
| 46 | + find /must-gather/clusters/*/namespaces/*/pods/ -name '*.log' -delete |
| 47 | +fi |
| 48 | + |
| 49 | +echo "Waiting for copy phase..." |
| 50 | +exit 0 |
0 commit comments