Skip to content

Instantly share code, notes, and snippets.

@ialidzhikov
Created August 8, 2023 09:42
Show Gist options
  • Select an option

  • Save ialidzhikov/5fad661e5ad00f36c4650c01699fae35 to your computer and use it in GitHub Desktop.

Select an option

Save ialidzhikov/5fad661e5ad00f36c4650c01699fae35 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
set -o errexit
set -o nounset
set -o pipefail
[[ -z "$1" ]] && echo "no resource group passed" && exit 1
RESOURCE_GROUP="$1"
PVS=$(kubectl get pv -o json | jq -r '.items[] | select(.status.phase=="Failed") | .metadata.name')
FOUND_PVS_COUNT=0
NOT_FOUND_PVS_COUNT=0
for PV in $PVS; do
sleep 1s
echo "> Checking $PV"
DISK_NAME=$(kubectl get pv $PV -o json | jq -r '.spec.azureDisk.diskName')
echo "Disk name - $DISK_NAME"
if az disk show -g "$RESOURCE_GROUP" --name "$DISK_NAME"; then
((FOUND_PVS_COUNT++))
echo "Disk found!"
else
NOT_FOUND_PVS_COUNT=$((NOT_FOUND_PVS_COUNT+1))
echo Disk NOT found!
fi
done
echo "-----"
echo "Found PVs - $FOUND_PVS_COUNT"
echo "NOT found PVs - $NOT_FOUND_PVS_COUNT"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment