Spaces:
Paused
Paused
set -e | |
# Yuga Planner Helm Cleanup Script | |
# This script removes the Helm release and all associated resources | |
echo "π§Ή Cleaning up Yuga Planner Helm deployment..." | |
# Check if helm is available | |
if ! command -v helm &> /dev/null; then | |
echo "β Error: helm is required but not installed." | |
echo "π‘ Install Helm from: https://helm.sh/docs/intro/install/" | |
exit 1 | |
fi | |
# Configuration (same defaults as deploy script) | |
RELEASE_NAME="${HELM_RELEASE_NAME:-yuga-planner}" | |
# Get current namespace, fallback to default if not set | |
CURRENT_NAMESPACE=$(kubectl config view --minify --output 'jsonpath={..namespace}' 2>/dev/null || echo "default") | |
NAMESPACE="${HELM_NAMESPACE:-$CURRENT_NAMESPACE}" | |
echo "π¦ Helm Release: $RELEASE_NAME" | |
echo "π·οΈ Namespace: $NAMESPACE" | |
# Check if the release exists | |
if ! helm list -n "$NAMESPACE" | grep -q "^$RELEASE_NAME"; then | |
echo "βΉοΈ Helm release '$RELEASE_NAME' not found in namespace '$NAMESPACE'." | |
echo "β Nothing to clean up." | |
exit 0 | |
fi | |
# Show release information | |
echo "π Found Helm release:" | |
helm list -n "$NAMESPACE" | grep "^$RELEASE_NAME" || true | |
echo "" | |
echo "π Release details:" | |
helm status "$RELEASE_NAME" -n "$NAMESPACE" || true | |
# Confirm deletion | |
echo "" | |
read -p "β Are you sure you want to uninstall the Helm release '$RELEASE_NAME'? (y/N): " -n 1 -r | |
echo | |
if [[ ! $REPLY =~ ^[Yy]$ ]]; then | |
echo "β Cleanup cancelled." | |
exit 0 | |
fi | |
echo "ποΈ Uninstalling Helm release..." | |
helm uninstall "$RELEASE_NAME" -n "$NAMESPACE" | |
echo "β Helm release uninstalled successfully!" | |
# Check if namespace should be cleaned up (optional) | |
if [ "$NAMESPACE" != "default" ]; then | |
echo "" | |
echo "π€ The namespace '$NAMESPACE' still exists." | |
read -p "β Do you want to delete the namespace '$NAMESPACE' as well? (y/N): " -n 1 -r | |
echo | |
if [[ $REPLY =~ ^[Yy]$ ]]; then | |
# Check if namespace has other resources | |
OTHER_RESOURCES=$(kubectl get all -n "$NAMESPACE" --ignore-not-found=true 2>/dev/null | grep -v "^NAME" | wc -l) | |
if [ "$OTHER_RESOURCES" -gt 0 ]; then | |
echo "β οΈ Warning: Namespace '$NAMESPACE' contains other resources." | |
kubectl get all -n "$NAMESPACE" 2>/dev/null || true | |
read -p "β Are you sure you want to delete the entire namespace? (y/N): " -n 1 -r | |
echo | |
if [[ $REPLY =~ ^[Yy]$ ]]; then | |
kubectl delete namespace "$NAMESPACE" | |
echo "β Namespace '$NAMESPACE' deleted." | |
else | |
echo "βΉοΈ Namespace '$NAMESPACE' preserved." | |
fi | |
else | |
kubectl delete namespace "$NAMESPACE" | |
echo "β Empty namespace '$NAMESPACE' deleted." | |
fi | |
else | |
echo "βΉοΈ Namespace '$NAMESPACE' preserved." | |
fi | |
fi | |
echo "" | |
echo "π Useful commands to verify cleanup:" | |
echo " β’ List remaining releases: helm list -A" | |
echo " β’ Check for remaining resources: kubectl get all -l app.kubernetes.io/instance=$RELEASE_NAME -A" | |