Created
September 26, 2025 16:06
-
-
Save ParadoxGuitarist/208afa07f4bf71623d49dcf51049aead to your computer and use it in GitHub Desktop.
Get Disk and Node Info for Longhorn Backing Image Objects.
This file contains hidden or 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 | |
# LICENSE: MIT Author: Brian Monroe | |
# This script needs an argument - Prompt for the backingImage object. | |
if [[ -z "$1" ]]; then | |
echo "The first argument (\$1) is empty or unset. You need to provide the name of a backingImage object. Here's a list:" | |
echo "kubectl get backingImages -A" | |
kubectl get backingImages -A | |
exit 1 | |
fi | |
DISKUUIDS=$(kubectl get backingImage $1 -n longhorn-system -ojson | jq -r '.spec.diskFileSpecMap | keys[]') | |
for UUID in $DISKUUIDS; do | |
# Get the Longhorn disk name based off the UUID. | |
DISKNAME=$(kubectl get node.longhorn.io -n longhorn-system -oyaml |grep -B10 $UUID |grep diskName | awk '{print $2}') | |
# Get the node on the disk based off the UUID. | |
NODENAME=$(kubectl get node.longhorn.io -n longhorn-system -oyaml |grep -B10 $UUID |grep node | sed -E 's/^.*on node (\w+).*$/\1/gm') | |
echo "Backing image $1 is on disk $DISKNAME on node $NODENAME" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment