Created
April 2, 2021 12:12
-
-
Save Thearas/e5811723026e0792538c90c442e1af13 to your computer and use it in GitHub Desktop.
Cleanup dangling PVCs which were created by tidb-operator
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 | |
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