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

Handle missing VM resource gracefully #41

Merged
merged 1 commit into from
Feb 14, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 9 additions & 1 deletion collection-scripts/targeted_crs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ MIGRATION_NS=$1
dv_resources=()
plan_resources=()
vm_resources=()
present_vm_resources=()
target_ns=""
log_filter_query=""

Expand Down Expand Up @@ -114,6 +115,7 @@ if [ ! -z "${vm_resources}" ]; then
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")

# Store VM in list to allow virt-launcher pod logs gathering
echo "${target_ns},${target_vm_name},${target_vm_id}" >> /tmp/target_vms
Expand All @@ -133,12 +135,18 @@ if [ ! -z "${dv_resources}" ]; then
done
fi

# Show message in case of empty result
# Show message in case of empty result of requested/parsed resources
if [ -z $plan_resources ] && [ -z $vm_resources ] && [ -z $dv_resources ]; then
echo "ERROR: No resources matching the criteria were found. Try adjust NS, PLAN or VM env variables."
exit 1
fi

# Show message for zero valid VMs without Plan of resources actually existing in the cluster
if [ -z $plan_resources ] && [ -z $present_vm_resources ]; then
echo "ERROR: No existing VMs were found in the cluster."
exit 1
fi

# Store condition for logs filtering
echo "Condition for targeted logs filtering:"
echo "${log_filter_query:1}" | tee /tmp/targeted_logs_grep_query