Skip to content

Instantly share code, notes, and snippets.

@fl64
Created November 22, 2023 20:50
Show Gist options
  • Save fl64/3fb9187bcd2025cc3593bbad70fbc950 to your computer and use it in GitHub Desktop.
Save fl64/3fb9187bcd2025cc3593bbad70fbc950 to your computer and use it in GitHub Desktop.
get vms and it's linstor nodes
ns=tfprod
vms=$(kubectl -n ${ns} get pods -l vm.kubevirt.io/name -o json | jq '.items[] | select(.status.phase=="Running") | { ns: .metadata.namespace, name: .metadata.name, node: .spec.nodeName, claims: [.spec.volumes[] | select(.persistentVolumeClaim!=null) | .persistentVolumeClaim.claimName] }' -cr)
for vm in ${vms}; do
echo ${vm} | jq '. | {ns,name,node}' -c
pvcs=$(echo ${vm} | jq .claims[] -r)
for pvc in ${pvcs}; do
volume_name=$(kubectl -n ${ns} get pvc ${pvc} -o json | jq .spec.volumeName -r)
echo "${pvc} / ${volume_name}"
kubectl exec -n d8-linstor deploy/linstor-controller -- linstor r l -r ${volume_name}
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment