From 60d10e9e2773b21f2a7e06e59c4ff289d442f99c Mon Sep 17 00:00:00 2001 From: "Madhusudan.C.S" Date: Sun, 4 Jun 2017 13:07:32 -0700 Subject: [PATCH] Do not delete PVs with --all, instead delete them selectively. PV is a non-namespaced resource. Running `kubectl delete pv --all`, even with `--namespace` is going to delete all the PVs in the cluster. This is a dangerous operation and should not be deleted this way. Instead we now retrieve the PVs bound to the PVCs in the namespace we are deleteing and delete only those PVs. Fixes issue #46380. --- federation/cluster/common.sh | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/federation/cluster/common.sh b/federation/cluster/common.sh index 37fe14a6ec4..40e074f0012 100644 --- a/federation/cluster/common.sh +++ b/federation/cluster/common.sh @@ -414,8 +414,15 @@ function cleanup-federation-api-objects { echo "Cleaning Federation control plane objects" # Delete all resources with the federated-cluster label. $host_kubectl delete pods,svc,rc,deployment,secret -lapp=federated-cluster + + # Delete all PVs bound to PVCs in FEDERATION_NAMESPACE + pvs=$($host_kubectl get pvc --namespace=${FEDERATION_NAMESPACE} -o jsonpath='{.items[*].spec.volumeName}') + while $host_kubectl delete pv ${pvs} >/dev/null 2>&1; do + sleep 2 + done + # Delete all resources in FEDERATION_NAMESPACE. - $host_kubectl delete pvc,pv,pods,svc,rc,deployment,secret --namespace=${FEDERATION_NAMESPACE} --all + $host_kubectl delete pvc,pods,svc,rc,deployment,secret --namespace=${FEDERATION_NAMESPACE} --all $host_kubectl delete ns ${FEDERATION_NAMESPACE} # Poll until the namespace is completely gone.