Skip to content

Instantly share code, notes, and snippets.

@rcbop
Created June 19, 2019 12:23
Show Gist options
  • Save rcbop/81563363d9be2417653212fa2f6550ed to your computer and use it in GitHub Desktop.
Save rcbop/81563363d9be2417653212fa2f6550ed to your computer and use it in GitHub Desktop.
#!/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