improved cleanup script
@@ -25,6 +25,12 @@ source hack/config.sh
echo "Cleaning up ..."
+# Delete KubeVirt CR
+set +e
+_kubectl -n ${namespace} delete kv kubevirt
+set -e
+sleep 5
+
# Remove finalizers from all running vmis, to not block the cleanup
_kubectl get vmis --all-namespaces -o=custom-columns=NAME:.metadata.name,NAMESPACE:.metadata.namespace,FINALIZERS:.metadata.finalizers --no-headers | grep foregroundDeleteVirtualMachine | while read p; do
arr=($p)
@@ -37,43 +43,48 @@ done
namespaces=(default ${namespace} ${cdi_namespace})
labels=("operator.kubevirt.io" "kubevirt.io" "cdi.kubevirt.io")
+# Namespaced resources
for i in ${namespaces[@]}; do
for label in ${labels[@]}; do
_kubectl -n ${i} delete deployment -l ${label}
_kubectl -n ${i} delete ds -l ${label}
_kubectl -n ${i} delete rs -l ${label}
_kubectl -n ${i} delete pods -l ${label}
- _kubectl -n ${i} delete validatingwebhookconfiguration -l ${label}
_kubectl -n ${i} delete services -l ${label}
_kubectl -n ${i} delete pvc -l ${label}
- _kubectl -n ${i} delete pv -l ${label}
- _kubectl -n ${i} delete clusterrolebinding -l ${label}
_kubectl -n ${i} delete rolebinding -l ${label}
_kubectl -n ${i} delete roles -l ${label}
- _kubectl -n ${i} delete clusterroles -l ${label}
_kubectl -n ${i} delete serviceaccounts -l ${label}
_kubectl -n ${i} delete configmaps -l ${label}
_kubectl -n ${i} delete secrets -l ${label}
- _kubectl -n ${i} delete customresourcedefinitions -l ${label}
+ done
+done
+
+# Not namespaced resources
+for label in ${labels[@]}; do
+ _kubectl delete validatingwebhookconfiguration -l ${label}
+ _kubectl delete pv -l ${label}
+ _kubectl delete clusterrolebinding -l ${label}
+ _kubectl delete clusterroles -l ${label}
+ _kubectl delete customresourcedefinitions -l ${label}
if [[ "$KUBEVIRT_PROVIDER" =~ os-* ]]; then
- _kubectl -n ${i} delete scc -l ${label}
+ _kubectl delete scc -l ${label}
fi
# W/A for https://github.com/kubernetes/kubernetes/issues/65818
if [[ "$KUBEVIRT_PROVIDER" =~ .*.10..* ]]; then
# k8s version 1.10.* does not have --wait parameter
- _kubectl -n ${i} delete apiservices -l ${label}
+ _kubectl delete apiservices -l ${label}
else
- _kubectl -n ${i} delete apiservices -l ${label} --wait=false
+ _kubectl delete apiservices -l ${label} --wait=false
fi
- _kubectl -n ${i} get apiservices -l ${label} -o=custom-columns=NAME:.metadata.name,FINALIZERS:.metadata.finalizers --no-headers | grep foregroundDeletion | while read p; do
+ _kubectl get apiservices -l ${label} -o=custom-columns=NAME:.metadata.name,FINALIZERS:.metadata.finalizers --no-headers | grep foregroundDeletion | while read p; do
arr=($p)
name="${arr[0]}"
_kubectl -n ${i} patch apiservices $name --type=json -p '[{ "op": "remove", "path": "/metadata/finalizers" }]'
done
done
-done
if [ -n "$(_kubectl get ns | grep "${namespace} ")" ]; then
echo "Clean ${namespace} namespace"
