Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Cleanup dangling PVCs which were created by tidb-operator
#!/bin/bash
set -xuo pipefail
IFS='
'
pvc2tcs=( $(kubectl get pvc -l app.kubernetes.io/managed-by=tidb-operator,app.kubernetes.io/name=tidb-cluster -o jsonpath="{range .items[*]}{.metadata.name}{' '}{.metadata.labels.app\.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}"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment