Created
September 19, 2023 16:36
-
-
Save tiraboschi/9952551c4f1aeeb4f6bf6a93664cb077 to your computer and use it in GitHub Desktop.
Gather VM logs for the KubeVirt hypershift provider
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
NAME=$1 | |
if [[ -z "${NAME}" ]] | |
then | |
echo "Please specify the name of the guest cluster." | |
exit 1 | |
fi | |
HSNS=clusters | |
VMNS="${HSNS}"-"${NAME}" | |
REPLICAS=$(oc get NodePool -n "${HSNS}" "${NAME}" -o=jsonpath='{.spec.replicas}') | |
PLATFORMTYPE=$(oc get NodePool -n "${HSNS}" "${NAME}" -o=jsonpath='{.spec.platform.type}') | |
INFRAID=$(oc get HostedCluster -n "${HSNS}" "${NAME}" -o=jsonpath='{.spec.infraID}') | |
if [[ "${PLATFORMTYPE}" != "KubeVirt" ]]; then | |
echo "This tool is designed for the KubeVirt provider." | |
exit 1 | |
fi | |
if [[ "${PLATFORMTYPE}" != "KubeVirt" ]]; then | |
echo "This tool is designed for the KubeVirt provider." | |
exit 1 | |
fi | |
if ! which tmux >/dev/null 2>&1; | |
then | |
echo "this tool requires tmux, please install it." | |
exit 1 | |
fi | |
VMNAMES=() | |
while [[ ${#VMNAMES[@]} < ${REPLICAS} ]]; do | |
for VMNAME in $(oc get vmi -n "${VMNS}" -l hypershift.openshift.io/infra-id="${INFRAID}" -o name 2>/dev/null); do | |
SVMNAME=${VMNAME/virtualmachineinstance.kubevirt.io\//} | |
if ! [[ " ${VNMANES[*]} " =~ ${SVMNAME} ]]; then | |
VMNAMES+=("${SVMNAME}") | |
tmux new-session -s "${SVMNAME}" -d "virtctl console -n ${VMNS} ${SVMNAME} | tee -a ${VMNS}_${SVMNAME}.log" | |
echo "logs for VM ${SVMNAME} will be appended to ${VMNS}_${SVMNAME}.log" | |
fi | |
done | |
sleep 0.1 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment