-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathuninstall.sh
More file actions
executable file
·549 lines (460 loc) · 17.3 KB
/
Copy pathuninstall.sh
File metadata and controls
executable file
·549 lines (460 loc) · 17.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
#!/usr/bin/env bash
#############################################################################
# AIOStack Uninstaller
#
# A safe and interactive uninstallation script for AIOStack Kubernetes
# application that guides users through the complete removal process.
#
# Usage:
# ./uninstall.sh # Interactive mode
# ./uninstall.sh --help # Show help
# ./uninstall.sh -v # Verbose mode
# ./uninstall.sh --force # Skip confirmations (dangerous!)
#
# Requirements:
# - Helm 3.x
# - kubectl configured with cluster access
#
# Author: Aurva (https://aurva.io)
# License: Apache 2.0
#############################################################################
set -euo pipefail
# Script version
VERSION="1.0.3"
# Configuration
VERBOSE="${VERBOSE:-false}"
FORCE="${FORCE:-false}"
NAMESPACE=""
RELEASE_NAME=""
DELETE_NAMESPACE="false"
REMOVE_HELM_REPO="false"
# Color codes for output (Green, White, Red theme)
RED='\033[0;31m'
GREEN='\033[0;32m'
BRIGHT_GREEN='\033[1;32m'
WHITE='\033[0;37m'
BOLD='\033[1m'
NC='\033[0m' # No Color
#############################################################################
# Helper Functions
#############################################################################
# Print colored output
print_color() {
local color=$1
shift
echo -e "${color}$*${NC}"
}
# Print success message
print_success() {
print_color "$GREEN" "✓ $*"
}
# Print error message
print_error() {
print_color "$RED" "✗ $*"
}
# Print warning message
print_warning() {
print_color "$BRIGHT_GREEN" "⚠ $*"
}
# Print info message
print_info() {
print_color "$WHITE" "ℹ $*"
}
# Print verbose message (only if verbose mode is enabled)
print_verbose() {
if [[ "$VERBOSE" == "true" ]]; then
print_color "$WHITE" "[VERBOSE] $*"
fi
}
# Prompt user with default value
prompt() {
local prompt_message=$1
local default_value=$2
local user_input
if [[ -n "$default_value" ]]; then
read -r -p "$(echo -e "${BRIGHT_GREEN}${prompt_message} [${default_value}]:${NC} ")" user_input < /dev/tty
echo "${user_input:-$default_value}"
else
read -r -p "$(echo -e "${BRIGHT_GREEN}${prompt_message}:${NC} ")" user_input < /dev/tty
echo "$user_input"
fi
}
# Ask yes/no question
ask_yes_no() {
local prompt_message=$1
local default_value=${2:-"n"}
local response
if [[ "$FORCE" == "true" ]]; then
print_verbose "Force mode: answering 'yes' to: ${prompt_message}"
return 0
fi
if [[ "$default_value" == "y" ]]; then
read -r -p "$(echo -e "${BRIGHT_GREEN}${prompt_message} [Y/n]:${NC} ")" response < /dev/tty
response=${response:-y}
else
read -r -p "$(echo -e "${BRIGHT_GREEN}${prompt_message} [y/N]:${NC} ")" response < /dev/tty
response=${response:-n}
fi
[[ "$response" =~ ^[Yy]$ ]]
}
# Print banner
print_banner() {
clear
print_color "$BOLD$BRIGHT_GREEN" "
█████╗ ██╗ ██╗██████╗ ██╗ ██╗ █████╗
██╔══██╗██║ ██║██╔══██╗██║ ██║██╔══██╗
███████║██║ ██║██████╔╝██║ ██║███████║
██╔══██║██║ ██║██╔══██╗╚██╗ ██╔╝██╔══██║
██║ ██║╚██████╔╝██║ ██║ ╚████╔╝ ██║ ██║
╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝ ╚═══╝ ╚═╝ ╚═╝
"
print_color "$BOLD" " ─────────────────────────────────────────────────"
print_color "$BOLD$WHITE" " AIOStack · Uninstaller · v${VERSION}"
print_color "$WHITE" " Safe removal of all AIOStack components"
print_color "$BOLD" " ─────────────────────────────────────────────────"
echo ""
print_warning "This will remove AIOStack from your cluster"
echo ""
}
# Show help
show_help() {
cat << EOF
AIOStack Uninstaller v${VERSION}
USAGE:
$0 [OPTIONS]
OPTIONS:
-h, --help Show this help message
-v, --verbose Enable verbose output
-f, --force Skip all confirmations (use with caution!)
--version Show version information
EXAMPLES:
# Interactive uninstallation (recommended)
$0
# Verbose mode for debugging
$0 --verbose
# Force mode (dangerous - no confirmations!)
$0 --force
WHAT GETS REMOVED:
- Helm release (deployment, pods, services, etc.)
- Optionally: Kubernetes namespace
- Optionally: Helm repository
WHAT IS PRESERVED:
- Configuration files on local system
- Data in Aurva cloud dashboard
REQUIREMENTS:
- Helm 3.x installed
- kubectl configured with cluster access
SUPPORT:
- Documentation: https://aurva.ai/docs/home
- Issues: https://github.com/aurva-io/ai-observability-stack/issues
- Email: support@aurva.io
EOF
exit 0
}
#############################################################################
# Core Functions
#############################################################################
# Check prerequisites
check_prerequisites() {
print_info "Checking prerequisites..."
echo ""
local all_checks_passed=true
# Check Helm
if command -v helm &> /dev/null; then
local helm_version
helm_version=$(helm version --short 2>/dev/null | grep -oE 'v[0-9]+\.[0-9]+\.[0-9]+' | head -1)
print_success "Helm is installed: ${helm_version}"
print_verbose "Helm path: $(which helm)"
else
print_error "Helm is not installed"
all_checks_passed=false
fi
# Check kubectl
if command -v kubectl &> /dev/null; then
local kubectl_version
kubectl_version=$(kubectl version --client --short 2>/dev/null | grep -oE 'v[0-9]+\.[0-9]+\.[0-9]+' || echo "unknown")
print_success "kubectl is installed: ${kubectl_version}"
print_verbose "kubectl path: $(which kubectl)"
else
print_error "kubectl is not installed"
all_checks_passed=false
fi
# Check cluster connectivity
if command -v kubectl &> /dev/null; then
if kubectl cluster-info &> /dev/null; then
local context
context=$(kubectl config current-context 2>/dev/null || echo "unknown")
print_success "Connected to cluster: ${context}"
print_verbose "Cluster info: $(kubectl cluster-info | head -1)"
else
print_error "Cannot connect to Kubernetes cluster"
all_checks_passed=false
fi
fi
if [[ "$all_checks_passed" == "false" ]]; then
echo ""
print_error "Prerequisites check failed"
exit 1
fi
echo ""
}
# Find AIOStack installations
find_installations() {
print_info "Searching for AIOStack installations..."
echo ""
# Get all helm releases across all namespaces
local releases
releases=$(helm list --all-namespaces -o json 2>/dev/null | \
grep -E '"name"|"namespace"|"chart"' | \
grep -B1 -A1 "aiostack" || echo "")
if [[ -z "$releases" ]]; then
print_warning "No AIOStack installations found"
echo ""
print_info "If you believe this is incorrect, you can:"
print_info " - Check specific namespace: helm list -n <namespace>"
print_info " - List all releases: helm list --all-namespaces"
exit 0
fi
# List all AIOStack releases
print_success "Found AIOStack installation(s):"
echo ""
helm list --all-namespaces | head -1 # Header
helm list --all-namespaces | grep aiostack
echo ""
}
# Select installation to remove
select_installation() {
# Get list of AIOStack releases
local releases
releases=$(helm list --all-namespaces -o json 2>/dev/null | \
jq -r '.[] | select(.chart | contains("aiostack")) | "\(.name)|\(.namespace)"' 2>/dev/null || echo "")
if [[ -z "$releases" ]]; then
print_error "No AIOStack installations found to remove"
exit 1
fi
# Count installations
local count
count=$(echo "$releases" | wc -l | tr -d '[:space:]')
if [[ "$count" -eq 1 ]]; then
# Only one installation found
RELEASE_NAME=$(echo "$releases" | cut -d'|' -f1)
NAMESPACE=$(echo "$releases" | cut -d'|' -f2)
print_info "Found installation: ${RELEASE_NAME} in namespace ${NAMESPACE}"
else
# Multiple installations found
print_info "Found ${count} AIOStack installation(s)"
echo ""
# If force mode, error out
if [[ "$FORCE" == "true" ]]; then
print_error "Force mode cannot be used with multiple installations"
print_info "Please specify namespace manually or run in interactive mode"
exit 1
fi
# Interactive selection
echo "Please select which installation to remove:"
echo ""
local i=1
while IFS='|' read -r name ns; do
echo " ${i}) ${name} (namespace: ${ns})"
i=$((i + 1))
done <<< "$releases"
echo ""
local selection
selection=$(prompt "Enter selection number" "1")
RELEASE_NAME=$(echo "$releases" | sed -n "${selection}p" | cut -d'|' -f1)
NAMESPACE=$(echo "$releases" | sed -n "${selection}p" | cut -d'|' -f2)
fi
print_verbose "Selected release: ${RELEASE_NAME}"
print_verbose "Selected namespace: ${NAMESPACE}"
}
# Show what will be removed
show_removal_plan() {
print_color "$BOLD$BRIGHT_GREEN" "Removal Plan:"
echo ""
print_color "$BOLD" "The following will be removed:"
echo ""
# Show helm release info
print_info "Helm Release: ${RELEASE_NAME}"
print_info "Namespace: ${NAMESPACE}"
echo ""
# Get resource counts
print_info "Resources to be removed:"
local pods services deployments daemonsets
pods=$(kubectl get pods -n "$NAMESPACE" -l "app.kubernetes.io/instance=${RELEASE_NAME}" --no-headers 2>/dev/null | wc -l | tr -d '[:space:]')
services=$(kubectl get svc -n "$NAMESPACE" -l "app.kubernetes.io/instance=${RELEASE_NAME}" --no-headers 2>/dev/null | wc -l | tr -d '[:space:]')
deployments=$(kubectl get deployments -n "$NAMESPACE" -l "app.kubernetes.io/instance=${RELEASE_NAME}" --no-headers 2>/dev/null | wc -l | tr -d '[:space:]')
daemonsets=$(kubectl get daemonsets -n "$NAMESPACE" -l "app.kubernetes.io/instance=${RELEASE_NAME}" --no-headers 2>/dev/null | wc -l | tr -d '[:space:]')
echo " - Pods: ${pods}"
echo " - Services: ${services}"
echo " - Deployments: ${deployments}"
echo " - DaemonSets: ${daemonsets}"
echo ""
# Show current pods
if [[ "$pods" -gt 0 ]]; then
print_info "Current pods:"
kubectl get pods -n "$NAMESPACE" -l "app.kubernetes.io/instance=${RELEASE_NAME}" 2>/dev/null | head -10
echo ""
fi
# Ask about namespace deletion
if ask_yes_no "Also delete namespace '${NAMESPACE}'?" "n"; then
DELETE_NAMESPACE="true"
print_warning "Namespace '${NAMESPACE}' will be deleted (including ALL resources in it)"
echo ""
fi
# Ask about helm repo removal
if helm repo list 2>/dev/null | grep -q "aiostack"; then
if ask_yes_no "Remove Aurva Helm repository?" "n"; then
REMOVE_HELM_REPO="true"
fi
fi
echo ""
print_color "$BOLD" "Summary:"
echo " Release to remove: ${RELEASE_NAME}"
echo " Namespace: ${NAMESPACE}"
echo " Delete namespace: ${DELETE_NAMESPACE}"
echo " Remove Helm repo: ${REMOVE_HELM_REPO}"
echo ""
}
# Perform uninstallation
perform_uninstall() {
print_color "$BOLD$BRIGHT_GREEN" "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
print_color "$BOLD$BRIGHT_GREEN" "Starting Uninstallation"
print_color "$BOLD$BRIGHT_GREEN" "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
# Final confirmation
if ! ask_yes_no "Are you sure you want to proceed?" "n"; then
print_info "Uninstallation cancelled"
exit 0
fi
echo ""
print_info "Removing Helm release: ${RELEASE_NAME}..."
if helm uninstall "$RELEASE_NAME" -n "$NAMESPACE" 2>&1; then
print_success "Helm release removed successfully"
else
print_error "Failed to remove Helm release"
print_info "You can try manually: helm uninstall ${RELEASE_NAME} -n ${NAMESPACE}"
exit 1
fi
# Wait a moment for resources to be cleaned up
echo ""
print_info "Waiting for resources to be cleaned up..."
sleep 5
# Check if resources are gone
local remaining_pods
remaining_pods=$(kubectl get pods -n "$NAMESPACE" -l "app.kubernetes.io/instance=${RELEASE_NAME}" --no-headers 2>/dev/null | wc -l | tr -d '[:space:]')
if [[ "$remaining_pods" -gt 0 ]]; then
print_warning "${remaining_pods} pod(s) still terminating..."
print_info "This is normal. They will be removed shortly."
else
print_success "All pods have been removed"
fi
# Delete namespace if requested
if [[ "$DELETE_NAMESPACE" == "true" ]]; then
echo ""
print_warning "Deleting namespace: ${NAMESPACE}..."
if kubectl delete namespace "$NAMESPACE" 2>&1; then
print_success "Namespace deleted successfully"
else
print_error "Failed to delete namespace"
print_info "You can try manually: kubectl delete namespace ${NAMESPACE}"
fi
fi
# Remove helm repo if requested
if [[ "$REMOVE_HELM_REPO" == "true" ]]; then
echo ""
print_info "Removing Helm repository..."
if helm repo remove aiostack 2>&1; then
print_success "Helm repository removed successfully"
else
print_warning "Failed to remove Helm repository (may not exist)"
fi
fi
}
# Show completion message
show_completion() {
echo ""
print_color "$BOLD$BRIGHT_GREEN" "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
print_color "$BOLD$BRIGHT_GREEN" "Uninstallation Complete!"
print_color "$BOLD$BRIGHT_GREEN" "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
print_success "AIOStack has been removed from your cluster"
echo ""
print_info "What was removed:"
echo " ✓ Helm release: ${RELEASE_NAME}"
if [[ "$DELETE_NAMESPACE" == "true" ]]; then
echo " ✓ Namespace: ${NAMESPACE}"
fi
if [[ "$REMOVE_HELM_REPO" == "true" ]]; then
echo " ✓ Helm repository: aiostack"
fi
echo ""
print_info "What is preserved:"
echo " • Your data on Aurva dashboard (app.aurva.ai)"
echo " • Configuration files on this machine"
if [[ "$DELETE_NAMESPACE" != "true" ]]; then
echo " • Namespace: ${NAMESPACE}"
fi
echo ""
print_info "To reinstall AIOStack:"
echo " ./install.sh"
echo ""
print_info "Need help?"
echo " • Documentation: https://aurva.ai/docs/home"
echo " • Support: support@aurva.io"
echo ""
# Farewell poem
print_color "$BRIGHT_GREEN" " Though you leave, we understand,"
print_color "$BRIGHT_GREEN" " Every journey has its end."
print_color "$BRIGHT_GREEN" " We're sad to see you go today,"
print_color "$BRIGHT_GREEN" " But hope you'll come back our way!"
echo ""
print_color "$WHITE" " — The Aurva AIOStack Team"
echo ""
}
#############################################################################
# Main
#############################################################################
main() {
# Parse command line arguments
while [[ $# -gt 0 ]]; do
case $1 in
-h|--help)
show_help
;;
-v|--verbose)
VERBOSE="true"
shift
;;
-f|--force)
FORCE="true"
print_warning "Force mode enabled - confirmations will be skipped!"
shift
;;
--version)
echo "AIOStack Uninstaller v${VERSION}"
exit 0
;;
*)
print_error "Unknown option: $1"
echo "Use --help for usage information"
exit 1
;;
esac
done
# Show banner
print_banner
# Check prerequisites
check_prerequisites
# Find installations
find_installations
# Select installation to remove
select_installation
# Show what will be removed and get confirmation
show_removal_plan
# Perform uninstallation
perform_uninstall
# Show completion message
show_completion
}
# Run main function
main "$@"