fixing control plane backup too
All checks were successful
Check scripts syntax / check-scripts-syntax (push) Successful in 2s
Test Kubernetes backup scripts / test-automated-nfs-backup (push) Successful in 3s
Test Kubernetes backup scripts / test-k3s-control-plane-config-backup (push) Successful in 4s

This commit is contained in:
2026-07-22 08:38:47 -03:00
parent cafbb01200
commit 0f7c56d7eb
3 changed files with 43 additions and 32 deletions

View File

@@ -172,13 +172,21 @@ EOF
set -Eeuo pipefail
url=""
body=""
for ((i = 1; i <= $#; i++)); do
if [[ "${!i}" == "POST" ]]; then
next=$((i + 1))
url="${!next}"
fi
case "${!i}" in
POST|-d)
next=$((i + 1))
if [[ "${!i}" == "POST" ]]; then
url="${!next}"
else
body="${!next}"
fi
;;
esac
done
printf '%s\n' "$url" >> "${TMPD}/curl_trace.log"
body="${body//$'\n'/ }"
printf '%s %s\n' "$url" "$body" >> "${TMPD}/curl_trace.log"
[[ ! -f "${TMPD}/fail_curl" ]]
EOF
@@ -219,8 +227,8 @@ run_backup() {
CURL_BIN="${TMPD}/bin/curl" \
FLOCK_BIN="${TMPD}/bin/flock" \
DATE_BIN="${TMPD}/bin/date" \
NOTIFY_SUCCESS_URL="http://example.invalid/success" \
NOTIFY_FAILURE_URL="http://example.invalid/failure" \
NOTIFY_SUCCESS_URL="http://example.invalid/api/v2/notifications/backup" \
NOTIFY_FAILURE_URL="http://example.invalid/api/v2/notifications/error" \
PATH="${TMPD}/bin:${PATH}" \
TMPD="$TMPD" \
FAKE_REMOTE_ROOT="$remote_root" \
@@ -312,7 +320,10 @@ assert "retention keeps the standalone unrelated.zip sentinel" path_exists "${su
assert "retention keeps unrelated legacy .7z backups" path_exists "${success_remote}/k8s-backup_2026-07-01.7z"
assert "retention keeps unrelated zip backups" path_exists "${success_remote}/other-prefix_2026-07-01.zip"
assert "local temporary archive state is removed" directory_is_empty "$success_local_tmp"
assert "successful backup sends a success notification" file_contains "${TMPD}/curl_trace.log" "http://example.invalid/success"
assert "successful backup sends a v2 backup notification" file_contains "${TMPD}/curl_trace.log" "http://example.invalid/api/v2/notifications/backup"
assert "successful backup sends its archive size in bytes" file_contains "${TMPD}/curl_trace.log" '"sizeBytes":'
assert "successful backup sends its elapsed duration" file_contains "${TMPD}/curl_trace.log" '"durationSeconds":'
assert "successful backup sends the v2 notification source" file_contains "${TMPD}/curl_trace.log" '"source": "K3s control-plane config backup"'
# A configured source path ending in server/db/.. must be rejected before zip is
# invoked, rather than recursively archiving server/db and its sibling socket.
@@ -398,8 +409,10 @@ assert "upload failure exits non-zero" is_nonzero "$failure_exit_code"
assert "upload failure does not publish a final archive" path_does_not_exist "${failure_remote}/k3s-control-plane-config_2026-07-21_12-00-00.zip"
assert "upload failure removes the remote temporary archive" directory_is_empty "$failure_remote"
assert "upload failure removes local temporary state" directory_is_empty "$failure_local_tmp"
assert "upload failure attempts exactly one error notification" file_line_count_is "${TMPD}/curl_trace.log" "http://example.invalid/failure" 1
assert "upload failure does not send a success notification" file_lacks "${TMPD}/curl_trace.log" "http://example.invalid/success"
assert "upload failure attempts exactly one v2 error notification" file_line_count_is "${TMPD}/curl_trace.log" "http://example.invalid/api/v2/notifications/error" 1
assert "upload failure marks the notification as critical" file_contains "${TMPD}/curl_trace.log" '"severity": "critical"'
assert "upload failure includes the v2 error code" file_contains "${TMPD}/curl_trace.log" '"errorCode": "K3S_CONTROL_PLANE_BACKUP_FAILED"'
assert "upload failure does not send a v2 backup notification" file_lacks "${TMPD}/curl_trace.log" "http://example.invalid/api/v2/notifications/backup"
assert "failure log does not disclose fixture source paths" file_lacks "${failure_dir}/run.log" "$failure_fixture"
# A notification error is non-fatal after a completed backup.