fix(backups): wait for an idle ClickHouse backup sidecar before starting

The sidecar refuses a new operation with 423 while another one is in
progress, but the strategy only waited for the API to answer, and went
on to start its operation even when it never did. An operation already
running in the sidecar therefore failed the attempt within seconds.

Poll the action log until nothing is in progress, and fail the Pod
instead of proceeding when the sidecar stays busy or unreachable, so
the failure names the cause rather than surfacing as a 423 or a
connection error from the operation itself.

Assisted-by: LLM
Signed-off-by: Alexey Artamonov <aleksei.artamonov@aenix.io>
(cherry picked from commit a25db5aeb6)
Signed-off-by: Myasnikov Daniil <myasnikovdaniil2001@gmail.com>
This commit is contained in:
Alexey Artamonov authored and Myasnikov Daniil committed 2026-11-25 10:15:38 +00:00
1 parent 84a5f9ee64
commit 8b76529539
1 file changed
+12 -1
@@ -58,10 +58,21 @@ spec:
# text/template's missing-key marker, when a controller that
# predates archive names renders this template during an upgrade.
archive="{{ printf `{{ .ArchiveName | default "" }}` }}"
# The sidecar answers 423 to a new operation while any other is
# in progress, so starting before it is idle burns the attempt.
idle=
for _ in $(seq 1 60); do
if curl -fsS ${auth} --max-time 2 "${api}/backup/status" >/dev/null 2>&1; then break; fi
if actions=$(curl -fsS ${auth} --max-time 5 "${api}/backup/actions") \
&& [ "$(printf '%s\n' "${actions}" | jq -rs '[.[] | select(.status == "in progress")] | length')" = 0 ]; then
idle=1
break
fi
sleep 5
done
if [ -z "${idle}" ]; then
echo "clickhouse-backup sidecar at ${api} did not become idle" >&2
exit 1
fi
if [ "{{ printf "{{ .Mode }}" }}" = "backup" ]; then
prefix="clickhouse-{{ printf "{{ .Release.Name }}" }}-"
# Only that older controller leaves the name empty, and it