From 9d6501adae8d36e4e23266e23f4823516c76177b Mon Sep 17 00:00:00 2001 From: Masaki Yatsu Date: Tue, 2 Dec 2025 10:31:16 +0900 Subject: [PATCH] feat(clickhouse): support retaining volumes on uninstall --- clickhouse/clickhouse.gomplate.yaml | 2 ++ clickhouse/justfile | 14 ++++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/clickhouse/clickhouse.gomplate.yaml b/clickhouse/clickhouse.gomplate.yaml index 411eb19..2470d0f 100644 --- a/clickhouse/clickhouse.gomplate.yaml +++ b/clickhouse/clickhouse.gomplate.yaml @@ -32,6 +32,7 @@ spec: templates: volumeClaimTemplates: - name: data-volume-template + reclaimPolicy: Retain spec: accessModes: - ReadWriteOnce @@ -39,6 +40,7 @@ spec: requests: storage: 50Gi - name: log-volume-template + reclaimPolicy: Retain spec: accessModes: - ReadWriteOnce diff --git a/clickhouse/justfile b/clickhouse/justfile index 58154e2..116cafb 100644 --- a/clickhouse/justfile +++ b/clickhouse/justfile @@ -137,8 +137,8 @@ setup-ingress host: kubectl apply -n ${CLICKHOUSE_NAMESPACE} -f clickhouse-ingress.yaml echo "ClickHouse Ingress configured successfully" -# Uninstall ClickHouse -uninstall: +# Uninstall ClickHouse (delete_volumes='false' to preserve PVCs and namespace) +uninstall delete-volumes='true': #!/bin/bash set -euo pipefail echo "Uninstalling ClickHouse..." @@ -146,7 +146,7 @@ uninstall: -n ${CLICKHOUSE_NAMESPACE} &>/dev/null; then echo "Deleting ClickHouseInstallation resources..." kubectl delete clickhouseinstallations.clickhouse.altinity.com --all \ - -n ${CLICKHOUSE_NAMESPACE} --timeout=60s --ignore-not-found || { + -n ${CLICKHOUSE_NAMESPACE} --timeout=90s --ignore-not-found || { echo "Graceful deletion timed out, forcing finalizer removal..." for chi in $(kubectl get clickhouseinstallations.clickhouse.altinity.com \ -n ${CLICKHOUSE_NAMESPACE} -o name 2>/dev/null); do @@ -158,7 +158,13 @@ uninstall: helm uninstall clickhouse-operator -n ${CLICKHOUSE_NAMESPACE} --wait --ignore-not-found just uninstall-zookeeper just delete-credentials-secret - just delete-namespace + if [ "{{ delete-volumes }}" = "true" ]; then + just delete-namespace + else + echo "Keeping namespace and PVCs for data preservation" + echo "PVCs in namespace '${CLICKHOUSE_NAMESPACE}':" + kubectl get pvc -n ${CLICKHOUSE_NAMESPACE} + fi echo "ClickHouse uninstalled successfully" # Get ClickHouse admin password