From 680d69b662bfd91fbd3f87ddce840b148375870f Mon Sep 17 00:00:00 2001 From: Paul Payne Date: Sun, 8 Jun 2025 09:44:39 -0700 Subject: [PATCH] Add wild-app-delete script for deleting Wild-Cloud apps and resources --- bin/wild-app-delete | 104 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100755 bin/wild-app-delete diff --git a/bin/wild-app-delete b/bin/wild-app-delete new file mode 100755 index 0000000..3f435db --- /dev/null +++ b/bin/wild-app-delete @@ -0,0 +1,104 @@ +#!/bin/bash + +set -e +set -o pipefail + +FORCE=false + +# Parse arguments +while [[ $# -gt 0 ]]; do + case $1 in + --force) + FORCE=true + shift + ;; + --dry-run) + DRY_RUN="--dry-run=client" + shift + ;; + -h|--help) + echo "Usage: $0 [--force] [--dry-run]" + echo "" + echo "Delete a Wild-Cloud app and all its resources." + echo "" + echo "Options:" + echo " --force Skip confirmation prompts" + echo " --dry-run Show what would be deleted without actually deleting" + echo " -h, --help Show this help message" + echo "" + echo "This will delete:" + echo " - App deployment, services, and other Kubernetes resources" + echo " - App secrets from the app's namespace" + echo " - App namespace (if empty after resource deletion)" + echo " - Local app configuration files from apps/" + exit 0 + ;; + -*) + echo "Unknown option $1" + echo "Usage: $0 [--force] [--dry-run]" + exit 1 + ;; + *) + if [ -z "${APP_NAME}" ]; then + APP_NAME="$1" + else + echo "Too many arguments" + echo "Usage: $0 [--force] [--dry-run]" + exit 1 + fi + shift + ;; + esac +done + +if [ -z "${APP_NAME}" ]; then + echo "Usage: $0 [--force] [--dry-run]" + exit 1 +fi + +if [ ! -d "apps/${APP_NAME}" ]; then + echo "Error: App directory 'apps/${APP_NAME}' not found" + exit 1 +fi + +# Confirmation prompt (unless --force or --dry-run) +if [ "${FORCE}" != true ] && [ "${DRY_RUN:-}" != "--dry-run=client" ]; then + echo "WARNING: This will delete all resources for app '${APP_NAME}'" + echo "This includes:" + echo " - Kubernetes deployments, services, secrets, and other resources" + echo " - App namespace (if empty after deletion)" + echo " - Local configuration files in apps/${APP_NAME}/" + echo "" + read -p "Are you sure you want to delete app '${APP_NAME}'? (y/N): " -n 1 -r + echo + if [[ ! $REPLY =~ ^[Yy]$ ]]; then + echo "Deletion cancelled" + exit 1 + fi +fi + +echo "Deleting app '${APP_NAME}'" + +# Step 1: Delete namespace (this will delete ALL resources including deployments, services, secrets, jobs, PVCs, etc.) +echo "Deleting namespace and all remaining resources..." +kubectl delete namespace "${APP_NAME}" ${DRY_RUN:-} --ignore-not-found=true + +# Wait for namespace deletion to complete +if [ "${DRY_RUN:-}" != "--dry-run=client" ]; then + echo "Waiting for namespace deletion to complete..." + kubectl wait --for=delete namespace "${APP_NAME}" --timeout=60s || true +fi + +# Step 2: Delete local app configuration files +echo "Deleting local app configuration..." +if [ "${DRY_RUN:-}" = "--dry-run=client" ]; then + echo "DRY RUN: Would delete directory 'apps/${APP_NAME}/'" +else + rm -rf "apps/${APP_NAME}/" + echo "Deleted local configuration directory: apps/${APP_NAME}/" +fi + +echo "App '${APP_NAME}' deletion complete!" +echo "" +echo "Note: Dependency apps (if any) were not deleted." +echo "If you want to delete dependencies, run wild-app-delete for each dependency separately." \ No newline at end of file