ci: fix pvc clean-up on non deletable namespaces (#2994)

* Only delete namespace if its deletable
  * For "default" namespace, delete all resources in that namespace
  * For "kube-system" namespace, delete all PVCs in that namespace
* Don't abort terminate action if PVC deletion fails

---------

Signed-off-by: Daniel Weiße <dw@edgeless.systems>
This commit is contained in:
Daniel Weiße 2024-03-19 14:53:58 +01:00 committed by GitHub
parent dc86a30988
commit 0da6f0d014
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -24,6 +24,7 @@ runs:
- name: Delete persistent volumes - name: Delete persistent volumes
if: inputs.kubeconfig != '' if: inputs.kubeconfig != ''
shell: bash shell: bash
continue-on-error: true
env: env:
KUBECONFIG: ${{ inputs.kubeconfig }} KUBECONFIG: ${{ inputs.kubeconfig }}
PV_DELETION_TIMEOUT: "120" # 2 minutes timeout for pv deletion PV_DELETION_TIMEOUT: "120" # 2 minutes timeout for pv deletion
@ -34,6 +35,14 @@ runs:
# Scrap namespaces that contain PVCs # Scrap namespaces that contain PVCs
for namespace in `kubectl get namespace --no-headers=true -o custom-columns=":metadata.name"`; do for namespace in `kubectl get namespace --no-headers=true -o custom-columns=":metadata.name"`; do
if [[ `kubectl get pvc -n $namespace --no-headers=true -o custom-columns=":metadata.name" | wc -l` -gt 0 ]]; then if [[ `kubectl get pvc -n $namespace --no-headers=true -o custom-columns=":metadata.name" | wc -l` -gt 0 ]]; then
if [[ "${namespace}" == "default" ]]; then
kubectl delete all --all --namespace "default" --wait
continue
fi
if [[ "${namespace}" == "kube-system" ]]; then
kubectl delete pvc --all --namespace "kube-system" --wait
continue
fi
kubectl delete namespace $namespace --wait kubectl delete namespace $namespace --wait
fi fi
done done