Added script to force delete everything remaining in namespace
All checks were successful
kustomization/cert-manager/3a682516 reconciliation succeeded
kustomization/kyverno/3a682516 reconciliation succeeded
kustomization/akri/3a682516 reconciliation succeeded
kustomization/rook-ceph/3a682516 reconciliation succeeded
kustomization/node-feature-discovery/3a682516 reconciliation succeeded
kustomization/node-feature-discovery-rules/3a682516 reconciliation succeeded
kustomization/velero/3a682516 reconciliation succeeded
kustomization/flux-system/3a682516 reconciliation succeeded
kustomization/kyverno-policies/3a682516 reconciliation succeeded
kustomization/letsencrypt/3a682516 reconciliation succeeded
kustomization/topolvm/3a682516 reconciliation succeeded
kustomization/rook-ceph-cluster/3a682516 reconciliation succeeded
kustomization/kube-vip/3a682516 reconciliation succeeded
kustomization/traefik/3a682516 reconciliation succeeded
kustomization/cnpg/3a682516 reconciliation succeeded
kustomization/authelia/3a682516 reconciliation succeeded
kustomization/traefik-middleware/3a682516 reconciliation succeeded
kustomization/lldap/3a682516 reconciliation succeeded
kustomization/apps/3a682516 reconciliation succeeded

This commit is contained in:
Dreaded_X 2025-04-24 14:18:45 +02:00
parent 5a027ea7e0
commit 53ce8d4343
Signed by: Dreaded_X
GPG Key ID: 5A0CBFE3C3377FAA

72
scripts/force_delete_ns.sh Executable file
View File

@ -0,0 +1,72 @@
#!/bin/bash
###############################################################################
# Remove all api-resources in namespace and then remove the namespace
#
# Query all api-resources in namespace, remove the finalizers and
# then remove the resource. Finally remove the finalizers on the Namespace and
# finally remove the namespace.
#
# Oracle Consulting Netherlands
#
# History
# -------
# 2024-05-11, M. van den Akker, Initial Creation
#
###############################################################################
export NS=$1
function count_apiresources() {
resource=$1
ROWS=$(kubectl get $resource -n $NS -o name |wc -l);
echo $ROWS
return $ROWS
}
function patch_apiresources(){
resource=$1
for resource_name in $(kubectl get $resource -n $NS -o name); do
echo "Patch $resource $resource_name"
kubectl -n $NS patch $resource_name -p '{"metadata":{"finalizers":null}}' --type=merge
done
}
function delete_apiresources(){
resource=$1
for resource_name in $(kubectl get $resource -n $NS -o name); do
echo "Delete $resource $resource_name"
kubectl -n $NS delete $resource_name --force
done
}
function patch_delete_apiresources(){
API_RESOURCE=$1
ROWS=$(count_apiresources $API_RESOURCE)
if [ $ROWS -gt 0 ]; then
echo Patch $ROWS occurrences of api-resource $API_RESOURCE for $NS to remove finalizers
patch_apiresources $API_RESOURCE
ROWS=$(count_apiresources $API_RESOURCE)
if [ $ROWS -gt 0 ]; then
echo Delete $ROWS occurrences of api-resource $API_RESOURCE for $NS
delete_apiresources $API_RESOURCE
else
echo No occurrences of api-resource $API_RESOURCE left.
fi
else
echo No occurrences of api-resource $API_RESOURCE found...
fi
}
for API_RESOURCE in $(kubectl api-resources --no-headers --verbs=list --namespaced -o name); do
patch_delete_apiresources $API_RESOURCE
done
echo Patch namespace $NS to clear metadata.finalizers
kubectl patch ns $NS -p '{"metadata":{"finalizers":null}}'
echo Patch namespace $NS to clear spec.finalizers
kubectl patch ns $NS -p '{"spec":{"finalizers":null}}'
echo Patch namespace $NS to clear metadata.annotations
kubectl patch ns $NS -p '{"metadata":{"annotations":null}}'
echo Force delete namespace $NS
kubectl delete ns $NS --grace-period=0 --force