Skip to content

Commit

Permalink
Add migration IDs when there is no plan available
Browse files Browse the repository at this point in the history
Adding migrations IDs based on the VM label. This will allow us to
gather the populator pod logs when there is no plan ID provided.

Signed-off-by: Liran Rotenberg <[email protected]>
  • Loading branch information
liranr23 authored and ahadas committed Sep 14, 2023
1 parent 0baafb2 commit 571f19e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
9 changes: 5 additions & 4 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 @@ -135,6 +131,11 @@ if [ ! -z "${vm_resources}" ]; then
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
24 changes: 23 additions & 1 deletion collection-scripts/targeted_logs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ for nsvm in ${target_vms[@]}; do
done

# Collect CDI/importer pod logs for imported DVs
for nsdv in ${target_dvs[@]} ${target_pvcs[@]}; do
for nsdv in ${target_dvs[@]}; do
IFS="," read ns dv <<< $nsdv
pod=$(oc get pods --no-headers -n $ns --selector cdi.kubevirt.io=importer -o go-template='{{range .items}}{{.metadata.name}}{{"\n"}}{{end}}' | grep $dv | head -1)

Expand All @@ -100,6 +100,28 @@ for nsdv in ${target_dvs[@]} ${target_pvcs[@]}; 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

pod=$(oc get pods --no-headers -n $ns --selector cdi.kubevirt.io=importer -o go-template='{{range .items}}{{.metadata.name}}{{"\n"}}{{end}}' | grep $pvc | head -1)
if [[ -z $pod ]]; then
echo "Importer Pod for $nspvc doesn't exist, skipping."
else
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
fi
done

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

0 comments on commit 571f19e

Please sign in to comment.