Created
October 30, 2024 16:53
-
-
Save pavelanni/7a6c9dcca0b18c088264bec2160b3b58 to your computer and use it in GitHub Desktop.
Remove finalizers from PVCs and Secrets
This file contains hidden or 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 | |
namespace=$1 | |
if [ -z "$namespace" ]; then | |
echo "Usage: $0 <namespace>" | |
exit 1 | |
fi | |
# Check if kubectl is available | |
if ! command -v kubectl &>/dev/null; then | |
echo "kubectl not found" | |
exit 1 | |
fi | |
# Check if jq is available | |
if ! command -v jq &>/dev/null; then | |
echo "jq not found" | |
exit 1 | |
fi | |
# Function to remove finalizers | |
remove_finalizers() { | |
resource_type=$1 | |
resource_name=$2 | |
echo "Removing finalizers from $resource_type: $resource_name" | |
kubectl patch $resource_type $resource_name -n $namespace \ | |
--type=json \ | |
-p='[{"op": "remove", "path": "/metadata/finalizers"}]' 2>/dev/null | |
} | |
# Process PVCs | |
echo "Processing PVCs..." | |
# Get all PVCs with finalizers | |
pvcs=$(kubectl get pvc -n $namespace -o json | jq -r '.items[] | select(.metadata.finalizers) | .metadata.name') | |
for pvc in $pvcs; do | |
remove_finalizers pvc $pvc | |
done | |
# Process Secrets | |
echo "Processing Secrets..." | |
# Get all Secrets with finalizers | |
secrets=$(kubectl get secrets -n $namespace -o json | jq -r '.items[] | select(.metadata.finalizers) | .metadata.name') | |
for secret in $secrets; do | |
remove_finalizers secret $secret | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment