Created
June 19, 2019 12:23
-
-
Save rcbop/81563363d9be2417653212fa2f6550ed to your computer and use it in GitHub Desktop.
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 | |
INSTANCE_PREFIX=${INSTANCE_PREFIX:?'provide the damn naming prefix of the instances'} | |
PROJECT=${PROJECT:?'provide the damn gcp project'} | |
IFS=$'\n' | |
declare -a disks_to_remove | |
for uid in $(oc get pvc --all-namespaces -o jsonpath='{range .items[*]}{@.metadata.uid}{"\n"}'); do | |
IFS=$'\n' | |
for disk in $(gcloud --project $PROJECT compute disks list --filter="name~$uid" --format="csv[no-heading](name,zone)"); do | |
disk_name=$(echo $disk | awk -F',' '{ print $1 }') | |
zone=$(echo $disk | awk -F ',' '{ print $2 }') | |
IFS=$'\n' | |
for instance in $(gcloud --project "${PROJECT}" compute disks describe "${disk_name}" --zone "${zone}" --format="value(users.basename())"); do | |
if grep $CLUSTER_PREFIX <<< "$instance"; then | |
echo ">>> DISK $disk_name USED BY CLUSTER $CLUSTER_PREFIX" | |
disks_to_remove+=($disk_name) | |
fi | |
done | |
done | |
done | |
echo "${disks_to_remove[*]}"% |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment