Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Cleanup dangling PVCs which were created by tidb-operator
set -xuo pipefail
pvc2tcs=( $(kubectl get pvc -l, -o jsonpath="{range .items[*]}{}{' '}{\.kubernetes\.io/instance}{'\n'}{end}") )
echo "Cleanup all dangling PVCs created by tidb-operator."
for pvc2tc in "${pvc2tcs[@]}"; do
pvc=$(echo "${pvc2tc}" | awk -F ' ' '{print $1}')
tc=$(echo "${pvc2tc}" | awk -F ' ' '{print $2}')
kubectl get tc "${tc}" >/dev/null || kubectl delete pvc "${pvc}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment