Skip to content

Commit b89b237

Browse files
Ginacursoragent
authored andcommitted
fix(rabbitmq): accept DP_TARGET_RELATIVE_PATH on volume-populator restore
KB12 AsDataSource prepareData injects DP_TARGET_RELATIVE_PATH (= pod archive stem) but may omit DP_TARGET_POD_NAME. Fall back so restore can locate <pod>.tar.zst without legacy annotation paths. Evidence: r18 kb-populate restore exit "DP_TARGET_POD_NAME is required". Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 872207a commit b89b237

2 files changed

Lines changed: 61 additions & 1 deletion

File tree

addons/rabbitmq/dataprotection/restore.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
set -Eeuo pipefail
33

44
DATA_DIR="${DATA_DIR:-/var/lib/rabbitmq}"
5-
TARGET_POD_NAME="${DP_TARGET_POD_NAME:?DP_TARGET_POD_NAME is required}"
5+
# Backup jobs inject DP_TARGET_POD_NAME. Volume-populator AsDataSource prepareData
6+
# may only inject DP_TARGET_RELATIVE_PATH (= pod identity / archive stem). Prefer
7+
# POD_NAME when present; otherwise accept RELATIVE_PATH so KB12 dataSource restore works.
8+
TARGET_POD_NAME="${DP_TARGET_POD_NAME:-${DP_TARGET_RELATIVE_PATH:?DP_TARGET_POD_NAME or DP_TARGET_RELATIVE_PATH is required}}"
69
ARCHIVE_NAME="${TARGET_POD_NAME}.tar.zst"
710

811
[ -n "${DP_DATASAFED_BIN_PATH:-}" ] && export PATH="${PATH}:${DP_DATASAFED_BIN_PATH}"

addons/rabbitmq/scripts-ut-spec/backup_restore_contract_spec.sh

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,63 @@ DATASAFED
143143
The stdout should include "restore prepareData completed"
144144
End
145145

146+
It "falls back to DP_TARGET_RELATIVE_PATH when volume-populator omits DP_TARGET_POD_NAME"
147+
When call bash -c '
148+
set -Eeuo pipefail
149+
restore_script="$1"
150+
tmp_dir="$(mktemp -d)"
151+
trap "rm -rf \"${tmp_dir}\"" EXIT
152+
data_dir="${tmp_dir}/data"
153+
bin_dir="${tmp_dir}/bin"
154+
payload_dir="${tmp_dir}/payload"
155+
mkdir -p "${data_dir}" "${bin_dir}" "${payload_dir}"
156+
printf "restored-via-relative\n" > "${payload_dir}/restored.txt"
157+
tar -cf "${tmp_dir}/payload.tar" -C "${payload_dir}" .
158+
cat > "${bin_dir}/datasafed" <<'"'"'DATASAFED'"'"'
159+
#!/bin/bash
160+
set -e
161+
case "$1" in
162+
list)
163+
# Archive key matches the relative path / pod identity injected by volume populator.
164+
printf "%s\n" "${DP_TARGET_RELATIVE_PATH}.tar.zst"
165+
;;
166+
pull)
167+
cat "${FAKE_ARCHIVE_PATH}"
168+
;;
169+
*)
170+
echo "unexpected datasafed command: $*" >&2
171+
exit 1
172+
;;
173+
esac
174+
DATASAFED
175+
printf "#!/bin/bash\nexit 0\n" > "${bin_dir}/chown"
176+
chmod +x "${bin_dir}/datasafed"
177+
chmod +x "${bin_dir}/chown"
178+
unset DP_TARGET_POD_NAME || true
179+
PATH="${bin_dir}:${PATH}" \
180+
DATA_DIR="${data_dir}" \
181+
DP_TARGET_RELATIVE_PATH="rmq-br-5400-rabbitmq-2" \
182+
DP_BACKUP_BASE_PATH="/backup/base" \
183+
FAKE_ARCHIVE_PATH="${tmp_dir}/payload.tar" \
184+
bash "${restore_script}"
185+
test -f "${data_dir}/restored.txt"
186+
test ! -f "${data_dir}/.kb-data-protection"
187+
' _ "${restore_script}"
188+
The status should be success
189+
The stdout should include "restore prepareData completed"
190+
End
191+
192+
It "fails closed when neither DP_TARGET_POD_NAME nor DP_TARGET_RELATIVE_PATH is set"
193+
When call bash -c '
194+
set -Eeuo pipefail
195+
restore_script="$1"
196+
unset DP_TARGET_POD_NAME DP_TARGET_RELATIVE_PATH || true
197+
DATA_DIR="$(mktemp -d)" DP_BACKUP_BASE_PATH="/backup/base" bash "${restore_script}"
198+
' _ "${restore_script}"
199+
The status should be failure
200+
The stderr should include "DP_TARGET_POD_NAME or DP_TARGET_RELATIVE_PATH is required"
201+
End
202+
146203
It "reconciles the restored system account idempotently after RabbitMQ is ready"
147204
When call grep -E "await_startup|ensure_system_user|change_password|add_user|set_user_tags|set_permissions" "${post_restore_script}"
148205
The status should be success

0 commit comments

Comments
 (0)