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

Backport to 2.5.2 #61

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
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
26 changes: 17 additions & 9 deletions collection-scripts/targeted_crs
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,6 @@ if [ ! -z $PLAN ]; then
plan_resources+=("$PLAN")
vm_resources+=($(echo $plan_data | jq -r '.status.migration.vms[] .name'))
target_ns=$(echo $plan_data | jq -r '.spec.targetNamespace')
migration_ids=$(echo $plan_data | jq -r '.status.migration.history[].migration .uid')
log_filter_query="$log_filter_query|$migration_ids"
# Store the migration id to allow populator pod logs gathering
echo "${migration_ids}" >> /tmp/migrations
fi
fi

Expand Down Expand Up @@ -123,18 +119,30 @@ if [ ! -z "${vm_resources}" ]; then

# Gather VMs PersistentVolumeClaims
for pvc_name in $(echo $vm_data | jq -r '.spec.template.spec.volumes[] .persistentVolumeClaim.claimName'); do
log_filter_query="$log_filter_query|$pvc_name"
dump_resource "persistentvolumeclaim" $pvc_name $target_ns

# Store PVC in list to allow populator pod logs gathering
echo "${target_ns},${pvc_name}" >> /tmp/pvcs
# In order to gather the scratch PVCs in warm migrations
for pvc in $(/usr/bin/oc get pvc -n ${target_ns} -o json | jq -c '.items | .[]'); do
if [ $(echo $pvc | jq -r '.spec.volumeName') != $pvc_name ]; then
continue
fi
name=$(echo $pvc | jq -r 'metadata.name')
log_filter_query="$log_filter_query|name"
dump_resource "persistentvolumeclaim" name $target_ns

# Store PVC in list to allow populator pod logs gathering
echo "${target_ns},${name}" >> /tmp/pvcs
done
done

target_vm_id=($(echo $vm_data | jq -r '.metadata.labels.vmID'))
log_filter_query="$log_filter_query|$target_vm_name"
dump_resource "virtualmachine" $target_vm_name $target_ns
present_vm_resources+=("$target_vm_name")

migration_id=($(echo $vm_data | jq -r '.metadata.labels.migration'))
log_filter_query="$log_filter_query|$migration_id"
# Store the migration id to allow populator pod logs gathering
echo ${migration_id} >> /tmp/migrations

# Gather VM hook jobs if present
for job_name in $(/usr/bin/oc get jobs --no-headers -n $MIGRATION_NS --selector vmID=$target_vm_id -o go-template='{{range .items}}{{.metadata.name}}{{"\n"}}{{end}}'); do
dump_resource "job" $job_name $MIGRATION_NS
Expand Down
25 changes: 25 additions & 0 deletions collection-scripts/targeted_logs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ namespaces=$1
targeted_query="$(cat /tmp/targeted_logs_grep_query)"
target_vms="$(touch /tmp/target_vms; cat /tmp/target_vms)"
target_dvs="$(touch /tmp/dvs; cat /tmp/dvs)"
target_pvcs="$(touch /tmp/pvcs; cat /tmp/pvcs)"
target_job_pods="$(touch /tmp/job_pods; cat /tmp/job_pods)"
target_migrations="$(touch /tmp/migrations; cat /tmp/migrations)"

Expand Down Expand Up @@ -99,6 +100,30 @@ for nsdv in ${target_dvs[@]}; do
fi
done

# Collect CDI/importer pod logs for imported PVCs
for nspvc in ${target_pvcs[@]}; do
IFS="," read ns pvc <<< $nspvc

pvc_yaml=$(cat "/must-gather/namespaces/${ns}/crs/persistentvolumeclaim/${pvc}.yaml")
has_cdi=$(echo $pvc_yaml | grep "app: containerized-data-importer")
if [[ -z $has_cdi ]]; then
continue
fi

pods=$(oc get pods --no-headers -n $ns --selector cdi.kubevirt.io=importer -o go-template='{{range .items}}{{.metadata.name}}{{"\n"}}{{end}}' | grep $pvc)
if [[ -z $pods ]]; then
echo "Importer Pod for $nspvc doesn't exist, skipping."
else
for pod in ${pods[@]}; do
object_collection_path="/must-gather/namespaces/${ns}/logs/${pod}"
mkdir -p ${object_collection_path}
echo "[ns=${ns}][pod=${pod}] Collecting CDI Importer Pod logs..."
/usr/bin/oc logs --all-containers --namespace ${ns} ${pod} &> "${object_collection_path}/current.log" &
pwait $max_parallelism
done
fi
done

# Collect migration hook jobs logs
for nsjobpod in ${target_job_pods[@]}; do
IFS="," read ns job_pod <<< $nsjobpod
Expand Down