From 6e04c3c09d974197160331f816e5d4a13cd47011 Mon Sep 17 00:00:00 2001 From: Anton Novikov Date: Wed, 8 Jan 2025 18:17:59 +0100 Subject: [PATCH] Fix clickhouse-hook.sh to support multiple CH installations. --- bin/clickhouse-hook.sh | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/bin/clickhouse-hook.sh b/bin/clickhouse-hook.sh index f7ec0ce..a1b3231 100755 --- a/bin/clickhouse-hook.sh +++ b/bin/clickhouse-hook.sh @@ -7,31 +7,29 @@ NAMESPACE="${2:-clickhouse}" ACTION="${3}" LIMIT="${4:-180}" -COUNT=1 +function check_cr() { + local OUTPUT="${1}" -function watcher() { - if [[ "${STATUS}" != "${PHRASE}" && "${COUNT}" -le "${LIMIT}" ]]; then + if [[ "${OUTPUT}" != "true" && "${COUNT}" -le "${LIMIT}" ]]; then sleep 1 ((++COUNT)) elif [[ "${COUNT}" -gt "${LIMIT}" ]]; then >2& echo "Limit exceeded." exit 1 else - kubectl -n "${NAMESPACE}" get clickHouseinstallation 2>&1 + kubectl -n "${NAMESPACE}" get clickhouseinstallation "${RELEASE_NAME}" --ignore-not-found + exit 0 fi } +COUNT=1 if [[ "${ACTION}" == "delete" ]]; then - PHRASE="No resources found in ${NAMESPACE} namespace." while true; do - STATUS=$(kubectl -n "${NAMESPACE}" get clickHouseinstallation 2>&1) - watcher + check_cr "$(kubectl -n "${NAMESPACE}" get clickhouseinstallation "${RELEASE_NAME}" --ignore-not-found -o yaml | yq "length == 0")" done else - PHRASE="Completed" while true; do - STATUS=$(kubectl -n "${NAMESPACE}" get clickHouseinstallation | head -2 | grep "${RELEASE_NAME}" | awk '{print $4}') - watcher + check_cr "$(kubectl -n "${NAMESPACE}" get clickhouseinstallation "${RELEASE_NAME}" --ignore-not-found -o yaml | yq ".status.status == \"Completed\"")" done fi