- Aula 08: nginx-ingress TCP passthrough gitlab→gitea, comments
- Aula 09: add-client.sh API GitLab→Gitea
- Aula 11: node-bugado deployment image registry.kube.quest→gitea.kube.quest
- Aula 12: setup.sh/cleanup.sh API GitLab→Gitea, ArgoCD repoURL
- Aula 13: k8s manifests, benchmarks: registry.kube.quest→gitea.kube.quest,
gitlab-registry→gitea-registry, GITLAB_TOKEN→GITEA_TOKEN
- Aula 14: comments GitLab→Gitea
- README raiz: arquitetura, tabela, DNS
164 lines
5.5 KiB
Bash
Executable File
164 lines
5.5 KiB
Bash
Executable File
#!/bin/bash
|
|
# =============================================================================
|
|
# Aula 12 - Cleanup Victoria Metrics
|
|
# =============================================================================
|
|
#
|
|
# Remove Victoria Metrics stack via ArgoCD
|
|
#
|
|
# =============================================================================
|
|
|
|
set -e
|
|
|
|
# Cores para output
|
|
RED='\033[0;31m'
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
BLUE='\033[0;34m'
|
|
NC='\033[0m' # No Color
|
|
|
|
# Funções de log
|
|
log_info() { echo -e "${BLUE}[INFO]${NC} $1"; }
|
|
log_success() { echo -e "${GREEN}[OK]${NC} $1"; }
|
|
log_warn() { echo -e "${YELLOW}[WARN]${NC} $1"; }
|
|
log_error() { echo -e "${RED}[ERROR]${NC} $1"; }
|
|
|
|
# Diretório do script
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
ENV_FILE="${SCRIPT_DIR}/.env"
|
|
|
|
# Carregar configuração
|
|
if [[ -f "$ENV_FILE" ]]; then
|
|
source "$ENV_FILE"
|
|
fi
|
|
|
|
echo ""
|
|
echo "=========================================="
|
|
echo " Cleanup Victoria Metrics"
|
|
echo "=========================================="
|
|
echo ""
|
|
echo "Este script irá remover:"
|
|
echo " - ArgoCD Application 'monitoring'"
|
|
echo " - Todos os recursos no namespace 'monitoring'"
|
|
echo " - Secret do repositório no ArgoCD"
|
|
echo ""
|
|
echo "ATENÇÃO: Dados de métricas serão PERDIDOS!"
|
|
echo ""
|
|
read -p "Continuar? [y/N]: " CONFIRM
|
|
|
|
if [[ "$CONFIRM" != "y" && "$CONFIRM" != "Y" ]]; then
|
|
log_info "Cancelado pelo usuário"
|
|
exit 0
|
|
fi
|
|
|
|
# =============================================================================
|
|
# REMOVER ARGOCD APPLICATION
|
|
# =============================================================================
|
|
|
|
log_info "Removendo ArgoCD Application..."
|
|
|
|
if kubectl get application monitoring -n argocd &> /dev/null; then
|
|
# Remover finalizers para permitir deleção
|
|
kubectl patch application monitoring -n argocd \
|
|
--type json \
|
|
--patch='[{"op": "remove", "path": "/metadata/finalizers"}]' 2>/dev/null || true
|
|
|
|
kubectl delete application monitoring -n argocd --wait=false
|
|
log_success "ArgoCD Application removida"
|
|
else
|
|
log_info "ArgoCD Application já não existe"
|
|
fi
|
|
|
|
# Aguardar recursos serem deletados pelo ArgoCD
|
|
log_info "Aguardando ArgoCD deletar recursos..."
|
|
sleep 5
|
|
|
|
# =============================================================================
|
|
# REMOVER NAMESPACE
|
|
# =============================================================================
|
|
|
|
log_info "Removendo namespace 'monitoring'..."
|
|
|
|
if kubectl get namespace monitoring &> /dev/null; then
|
|
# Forçar remoção de recursos se necessário
|
|
kubectl delete all --all -n monitoring --timeout=60s 2>/dev/null || true
|
|
kubectl delete pvc --all -n monitoring --timeout=60s 2>/dev/null || true
|
|
kubectl delete configmap --all -n monitoring --timeout=60s 2>/dev/null || true
|
|
kubectl delete secret --all -n monitoring --timeout=60s 2>/dev/null || true
|
|
|
|
kubectl delete namespace monitoring --timeout=120s 2>/dev/null || {
|
|
log_warn "Timeout deletando namespace, forçando..."
|
|
kubectl get namespace monitoring -o json | \
|
|
jq '.spec.finalizers = []' | \
|
|
kubectl replace --raw "/api/v1/namespaces/monitoring/finalize" -f - 2>/dev/null || true
|
|
}
|
|
log_success "Namespace 'monitoring' removido"
|
|
else
|
|
log_info "Namespace 'monitoring' já não existe"
|
|
fi
|
|
|
|
# =============================================================================
|
|
# REMOVER SECRET DO REPOSITÓRIO
|
|
# =============================================================================
|
|
|
|
log_info "Removendo secret do repositório..."
|
|
|
|
if kubectl get secret factory-monitoring-repo -n argocd &> /dev/null; then
|
|
kubectl delete secret factory-monitoring-repo -n argocd
|
|
log_success "Secret do repositório removido"
|
|
else
|
|
log_info "Secret do repositório já não existe"
|
|
fi
|
|
|
|
# =============================================================================
|
|
# REMOVER REPOSITÓRIO GITEA (OPCIONAL)
|
|
# =============================================================================
|
|
|
|
if [[ -n "$GITEA_HOST" && -n "$GITEA_TOKEN" ]]; then
|
|
echo ""
|
|
read -p "Remover repositório 'factory/monitoring' do Gitea? [y/N]: " REMOVE_PROJECT
|
|
|
|
if [[ "$REMOVE_PROJECT" == "y" || "$REMOVE_PROJECT" == "Y" ]]; then
|
|
log_info "Removendo repositório do Gitea..."
|
|
|
|
DELETE_RESPONSE=$(curl -s -o /dev/null -w "%{http_code}" --request DELETE \
|
|
-H "Authorization: token ${GITEA_TOKEN}" \
|
|
"https://${GITEA_HOST}/api/v1/repos/factory/monitoring")
|
|
|
|
if [[ "$DELETE_RESPONSE" == "204" ]]; then
|
|
log_success "Repositório removido do Gitea"
|
|
else
|
|
log_info "Repositório não encontrado no Gitea (HTTP ${DELETE_RESPONSE})"
|
|
fi
|
|
fi
|
|
fi
|
|
|
|
# =============================================================================
|
|
# LIMPAR ARQUIVO .ENV
|
|
# =============================================================================
|
|
|
|
echo ""
|
|
read -p "Remover arquivo de configuração local (.env)? [y/N]: " REMOVE_ENV
|
|
|
|
if [[ "$REMOVE_ENV" == "y" || "$REMOVE_ENV" == "Y" ]]; then
|
|
rm -f "$ENV_FILE"
|
|
log_success "Arquivo .env removido"
|
|
fi
|
|
|
|
# =============================================================================
|
|
# FINALIZAÇÃO
|
|
# =============================================================================
|
|
|
|
echo ""
|
|
echo "=========================================="
|
|
echo " Cleanup Concluído!"
|
|
echo "=========================================="
|
|
echo ""
|
|
echo "Recursos removidos:"
|
|
echo " - ArgoCD Application 'monitoring'"
|
|
echo " - Namespace 'monitoring'"
|
|
echo " - Secret do repositório no ArgoCD"
|
|
echo ""
|
|
echo "Para reinstalar:"
|
|
echo " ./setup.sh"
|
|
echo ""
|