Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions deploy-scripts/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,16 @@ INSTALL_API=true
INSTALL_SENTINEL=true
INSTALL_ADAPTER=true

# Uninstall Options (only used when --action uninstall)
# DELETE_K8S_RESOURCES: Delete Kubernetes resources (Helm releases + namespace)
DELETE_K8S_RESOURCES=false

# DELETE_CLOUD_RESOURCES: Delete GCP Pub/Sub topics and subscriptions
DELETE_CLOUD_RESOURCES=false

# DELETE_ALL: Delete everything (k8s + cloud resources) - overrides individual flags
DELETE_ALL=false

# Execution Options
DRY_RUN=false
VERBOSE=false
107 changes: 98 additions & 9 deletions deploy-scripts/deploy-clm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ INSTALL_API="${INSTALL_API:-true}"
INSTALL_SENTINEL="${INSTALL_SENTINEL:-true}"
INSTALL_ADAPTER="${INSTALL_ADAPTER:-true}"

# Uninstall options
DELETE_K8S_RESOURCES="${DELETE_K8S_RESOURCES:-false}"
DELETE_CLOUD_RESOURCES="${DELETE_CLOUD_RESOURCES:-false}"
DELETE_ALL="${DELETE_ALL:-false}"

# ============================================================================
# Load Library Modules
# ============================================================================
Expand All @@ -100,6 +105,7 @@ source "${SCRIPT_DIR}/lib/helm.sh"
source "${SCRIPT_DIR}/lib/api.sh"
source "${SCRIPT_DIR}/lib/sentinel.sh"
source "${SCRIPT_DIR}/lib/adapter.sh"
source "${SCRIPT_DIR}/lib/gcp.sh"

# ============================================================================
# Usage and Argument Parsing
Expand Down Expand Up @@ -145,6 +151,11 @@ OPTIONAL FLAGS:
--release-prefix <prefix> Release name prefix (default: hyperfleet)
Components will be named: <prefix>-api, <prefix>-sentinel, <prefix>-adapter

# Uninstall Options (only for --action uninstall)
--delete-k8s-resources Delete Kubernetes resources (Helm releases + namespace)
--delete-cloud-resources Delete GCP Pub/Sub topics and subscriptions
--all Delete everything (k8s resources + cloud resources)

# Execution Options
--dry-run Print commands without executing
--verbose Enable verbose logging
Expand Down Expand Up @@ -178,6 +189,20 @@ EXAMPLES:
# Dry-run uninstallation
${0##*/} --action uninstall --namespace hyperfleet-e2e --dry-run --verbose

# Delete Kubernetes resources (Helm releases + namespace)
${0##*/} --action uninstall --namespace hyperfleet-e2e --delete-k8s-resources

# Delete GCP Pub/Sub resources (topics and subscriptions)
${0##*/} --action uninstall --namespace hyperfleet-e2e --delete-cloud-resources

# Complete cleanup: delete everything (k8s + cloud resources)
${0##*/} --action uninstall --namespace hyperfleet-e2e --all

# Or explicitly specify both
${0##*/} --action uninstall --namespace hyperfleet-e2e \\
--delete-k8s-resources \\
--delete-cloud-resources

# Install with custom image repositories
${0##*/} --action install \\
--api-image-repo myregistry.io/hyperfleet-api \\
Expand Down Expand Up @@ -258,6 +283,20 @@ parse_arguments() {
RELEASE_PREFIX="$2"
shift 2
;;
--delete-k8s-resources)
DELETE_K8S_RESOURCES=true
shift
;;
--delete-cloud-resources)
DELETE_CLOUD_RESOURCES=true
shift
;;
--all)
DELETE_ALL=true
DELETE_K8S_RESOURCES=true
DELETE_CLOUD_RESOURCES=true
shift
;;
--dry-run)
DRY_RUN=true
shift
Expand Down Expand Up @@ -395,24 +434,74 @@ perform_uninstall() {
check_dependencies || exit 1
validate_kubectl_context || exit 1

# Uninstall components in reverse order: Adapter -> Sentinel -> API
if [[ "${INSTALL_ADAPTER}" == "true" ]]; then
uninstall_adapters
fi
# Display uninstall configuration
log_info "Uninstall Configuration:"
log_info " Delete K8s Resources (including namespace): ${DELETE_K8S_RESOURCES}"
log_info " Delete Cloud Resources: ${DELETE_CLOUD_RESOURCES}"

if [[ "${INSTALL_SENTINEL}" == "true" ]]; then
uninstall_sentinel
local uninstall_errors=0

# Uninstall Kubernetes resources (in reverse order: Adapter -> Sentinel -> API)
if [[ "${DELETE_K8S_RESOURCES}" == "true" ]]; then
log_section "Uninstalling Kubernetes Resources"

if [[ "${INSTALL_ADAPTER}" == "true" ]]; then
if ! uninstall_adapters; then
((uninstall_errors++))
fi
fi

if [[ "${INSTALL_SENTINEL}" == "true" ]]; then
if ! uninstall_sentinel; then
((uninstall_errors++))
fi
fi

if [[ "${INSTALL_API}" == "true" ]]; then
if ! uninstall_api; then
log_warning "Failed to uninstall API"
((uninstall_errors++))
fi
fi

# Delete namespace (this will remove any remaining k8s resources)
if ! delete_namespace "${NAMESPACE}"; then
log_warning "Failed to delete namespace"
((uninstall_errors++))
fi
else
log_info "Skipping Kubernetes resource deletion (use --delete-k8s-resources to enable)"
fi

if [[ "${INSTALL_API}" == "true" ]]; then
uninstall_api || log_warning "Failed to uninstall API"
# Delete GCP resources (topics and subscriptions)
if [[ "${DELETE_CLOUD_RESOURCES}" == "true" ]]; then
log_section "Deleting Cloud Provider Resources"
if ! cleanup_gcp_resources "${NAMESPACE}"; then
log_warning "Some GCP resources failed to delete"
((uninstall_errors++))
fi
else
log_info "Skipping cloud resource deletion (use --delete-cloud-resources to enable)"
fi

# Final status
log_section "Uninstallation Complete"

if [[ "${DRY_RUN}" == "false" ]]; then
log_success "All components uninstalled successfully!"
# Show summary of what was deleted
echo
log_info "Summary:"
[[ "${DELETE_K8S_RESOURCES}" == "true" ]] && log_info " ✓ K8s resources and namespace"
[[ "${DELETE_CLOUD_RESOURCES}" == "true" ]] && log_info " ✓ Cloud resources"

echo
if [[ ${uninstall_errors} -eq 0 ]]; then
log_success "Uninstallation completed successfully!"
else
log_error "Uninstallation completed with ${uninstall_errors} error(s)"
log_error "Please check the logs above for details"
exit 1
fi
else
log_info "[DRY-RUN] Uninstallation simulation complete"
fi
Expand Down
33 changes: 33 additions & 0 deletions deploy-scripts/lib/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -183,3 +183,36 @@ verify_pod_health() {
kubectl get pods -n "${namespace}" -l "${selector}"
return 1
}

# ============================================================================
# Namespace Management
# ============================================================================

delete_namespace() {
local namespace="$1"

log_section "Deleting Namespace"

# Check if namespace exists
if ! kubectl get namespace "${namespace}" &> /dev/null; then
log_warning "Namespace '${namespace}' does not exist"
return 0
fi

if [[ "${DRY_RUN}" == "true" ]]; then
log_info "[DRY-RUN] Would delete namespace: ${namespace}"
return 0
fi

log_info "Deleting namespace: ${namespace}"
log_warning "This will remove all resources in the namespace"

if kubectl delete namespace "${namespace}" --wait --timeout=5m; then
log_success "Namespace '${namespace}' deleted successfully"
return 0
else
log_error "Failed to delete namespace '${namespace}'"
log_info "You may need to manually remove finalizers or check for stuck resources"
return 1
fi
}
Loading