Skip to content

Commit b6ac429

Browse files
androndoclaude
andcommitted
test(postgres): run the backup round-trip e2e in CI under TIA
Ungate postgres-2-backup-roundtrip: instead of an opt-in env flag it now runs whenever TIA selects the postgres suite (postgres changes, and every release cut), like the other chainsaw tests. The blocker was network placement, not capability: the S3 client is the barman-cloud sidecar inside the Postgres Pod, and the isolated e2e tenant's Cilium egress allowlist blocks it from tenant-root's seaweedfs — so the Test runs in tenant-root (same-tenant egress) against the in-cluster S3 endpoint, trusting its self-signed cert via the copied seaweedfs-system-ca-cert. This is exactly the recipe validated end to end on a real cluster. Also map examples/backups/<app>/ edits to that app's suite in hack/select-e2e.sh (the round-trip executes those scripts as its harness; previously such edits were silently ignored), with bats coverage for both the mapped and the no-suite case. Co-Authored-By: Claude Fable 5 <[email protected]> Signed-off-by: Andrey Kolkov <[email protected]>
1 parent 6c0b14b commit b6ac429

7 files changed

Lines changed: 58 additions & 34 deletions

File tree

‎examples/backups/postgres/30-postgres-target.yaml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
#
77
# This manifest is the reference for the same-namespace to-copy happy path:
88
# deploy it alongside pg-src and the restore leaves the source running. The
9-
# gated postgres backup e2e (hack/e2e-chainsaw/postgres, opt in with
10-
# POSTGRES_E2E_S3_ROUNDTRIP=1) drives exactly this flow via run-all.sh. The
9+
# postgres backup e2e (hack/e2e-chainsaw/postgres, postgres-2-backup-roundtrip)
10+
# drives exactly this flow via run-all.sh in CI. The
1111
# cross-tenant variant (target in tenant-test, source's seaweedfs in
1212
# tenant-root) is blocked by the per-tenant Cilium egress policy.
1313
---

‎examples/backups/postgres/40-restorejob-to-copy.yaml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
# untouched.
55
#
66
# The reference for the same-namespace happy path, and the final step the
7-
# gated postgres backup e2e (hack/e2e-chainsaw/postgres, opt in with
8-
# POSTGRES_E2E_S3_ROUNDTRIP=1) asserts via run-all.sh. The cross-tenant variant
7+
# postgres backup e2e (hack/e2e-chainsaw/postgres, postgres-2-backup-roundtrip)
8+
# asserts via run-all.sh in CI. The cross-tenant variant
99
# stays manual; see 30-postgres-target.yaml for the network-policy reason.
1010
---
1111
apiVersion: backups.cozystack.io/v1alpha1

‎examples/backups/postgres/README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@ NAMESPACE=tenant-root examples/backups/postgres/cleanup.sh
3434

3535
## Automated e2e
3636

37-
The Chainsaw suite at `hack/e2e-chainsaw/postgres/` drives this same `run-all.sh` as a second, opt-in test (`postgres-2-backup-roundtrip`). It is gated out of CI because kind has no reachable, CA-trusted S3 endpoint; run it on a real cluster with `POSTGRES_E2E_S3_ROUNDTRIP=1`.
37+
The Chainsaw suite at `hack/e2e-chainsaw/postgres/` drives this same `run-all.sh` as a second test (`postgres-2-backup-roundtrip`), selected by CI whenever the postgres app (or these scripts) change and on every release cut. It runs in `tenant-root` against the in-cluster seaweedfs endpoint — the isolated e2e tenant cannot reach it across the Cilium egress policy, and the external ingress endpoint is an unroutable placeholder in the sandbox.

‎examples/backups/postgres/run-all.sh‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# through S3 into the restored copy.
1414
#
1515
# Override NAMESPACE / endpoint / CA via the environment; see 00-helpers.sh.
16-
# hack/e2e-chainsaw/postgres/ drives this file behind POSTGRES_E2E_S3_ROUNDTRIP.
16+
# hack/e2e-chainsaw/postgres/ drives this file as postgres-2-backup-roundtrip.
1717
set -euo pipefail
1818

1919
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

‎hack/e2e-chainsaw/postgres/chainsaw-test.yaml‎

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -136,28 +136,22 @@ spec:
136136
# restored copy — the in-cluster witness that a barman-cloud plugin backup is
137137
# both taken and restorable end to end.
138138
#
139-
# GATED OUT OF CI (opt in with POSTGRES_E2E_S3_ROUNDTRIP=1). The backup path
140-
# cannot succeed in the kind e2e environment:
141-
# - the barman-cloud sidecar backs up to the bucket's EXTERNAL ingress
142-
# endpoint (from the BucketInfo Secret); in CI that is the s3.example.org
143-
# placeholder, which the source Postgres Pod can neither route to nor
144-
# TLS-validate;
145-
# - the in-cluster seaweedfs-s3.tenant-root:8333 endpoint serves HTTPS with a
146-
# self-signed cert — the ObjectStore CAN trust it (run-all.sh copies
147-
# seaweedfs-system-ca-cert into <app>-cnpg-backup-ca and wires endpointCA),
148-
# but the e2e tenant is created with isolated: true
149-
# (hack/e2e-install-cozystack.bats), so the Cilium tenant policy blocks the
150-
# source Pod from reaching tenant-root's seaweedfs.
151-
# The round-trip therefore only works against a reachable, CA-trusted S3
152-
# endpoint (a real cluster). Chainsaw v0.2.15 has no conditional Test-level
153-
# skip, so the gate is a plain in-script conditional that exits 0 in CI with the
154-
# skip reason in the log — the same file runs un-gated on a real cluster with
155-
# just the env var set.
139+
# Runs in tenant-root, not the default tenant-test: the S3 client here is the
140+
# barman-cloud sidecar INSIDE the Postgres Pod, and the e2e tenant is created
141+
# isolated (hack/e2e-install-cozystack.bats) — its Cilium egress allowlist
142+
# blocks a tenant-test Pod from reaching tenant-root's seaweedfs, while a
143+
# tenant-root Pod reaches it over same-tenant egress. The harness targets the
144+
# in-cluster endpoint (S3_ENDPOINT below) instead of the BucketInfo external
145+
# ingress URL, which in CI is an unroutable placeholder, and trusts its
146+
# self-signed cert by copying seaweedfs-system-ca-cert into the per-app
147+
# endpointCA Secret. (The bucket suite's mc checks lean on the same
148+
# tenant-root seaweedfs, just from the test runner via port-forward.)
156149
apiVersion: chainsaw.kyverno.io/v1alpha1
157150
kind: Test
158151
metadata:
159152
name: postgres-2-backup-roundtrip
160153
spec:
154+
namespace: tenant-root
161155
skipDelete: true
162156
catch:
163157
- events: {}
@@ -186,26 +180,26 @@ spec:
186180
steps:
187181
- name: run
188182
try:
183+
# The 25m budget is the whole documented flow: bucket provisioning, a
184+
# 2-replica source Postgres, the plugin base backup to S3, an empty target
185+
# app, and the purge + re-bootstrap restore (convention 6: justified
186+
# in-line). run-all.sh fails fast on terminal BackupJob/RestoreJob phases
187+
# and stalled HelmReleases rather than polling out the budget.
189188
- script:
190189
timeout: 25m
191190
content: |
192191
set -eu
193-
if [ "${POSTGRES_E2E_S3_ROUNDTRIP:-0}" != "1" ]; then
194-
echo "# S3 backup/restore round-trip gated out of CI: no reachable,"
195-
echo "# CA-trusted S3 endpoint in kind (see comment in this file). Set"
196-
echo "# POSTGRES_E2E_S3_ROUNDTRIP=1 on a real cluster to run it."
197-
exit 0
198-
fi
199192
cd ../../..
200193
[ -x examples/backups/postgres/run-all.sh ] || { echo "postgres backup example scripts not found at examples/backups/postgres" >&2; exit 1; }
201-
NAMESPACE="$NAMESPACE" examples/backups/postgres/run-all.sh
194+
NAMESPACE="$NAMESPACE" S3_ENDPOINT="https://seaweedfs-s3.tenant-root:8333" \
195+
examples/backups/postgres/run-all.sh
202196
check:
203197
($error == null): true
204198
finally:
205-
# Idempotent — a no-op when the round-trip was gated out. Resumes the
206-
# driver-suspended HelmReleases before deleting the RestoreJob so the apps
207-
# are not stranded, then removes every resource the harness created
208-
# (chainsaw did not apply them, so they are not part of automatic cleanup).
199+
# Resumes the driver-suspended HelmReleases before deleting the RestoreJob
200+
# so the apps are not stranded, then removes every resource the harness
201+
# created (chainsaw did not apply them, so they are not part of automatic
202+
# cleanup).
209203
- description: backup-flow cleanup
210204
script:
211205
timeout: 8m

‎hack/select-e2e.sh‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,18 @@ while IFS= read -r file; do
9191
selected_apps="$selected_apps $app"
9292
trigger_any=1
9393
continue ;;
94+
examples/backups/*/*)
95+
# The etcd and postgres backup round-trip tests execute the example
96+
# scripts under examples/backups/<app>/ as their harness, so an edit
97+
# there must run that app's suite. A dir with no matching suite is a
98+
# docs-only demo and stays ignored (adding it to selected_apps would
99+
# empty the final intersection and trip the full-suite safety net).
100+
app=$(echo "$file" | sed -nE 's,^examples/backups/([^/]+)/.*,\1,p')
101+
if echo "$all_apps" | grep -Fxq "$app"; then
102+
selected_apps="$selected_apps $app"
103+
trigger_any=1
104+
fi
105+
continue ;;
94106
esac
95107

96108
# 3. Full-suite trigger

‎hack/select-e2e_test.bats‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,3 +152,21 @@
152152
output=$(hack/select-e2e.sh "$tmp/diff" "$tmp/sources")
153153
[ "$(echo "$output" | wc -w)" -gt 5 ]
154154
}
155+
156+
@test "backup example harness edit selects its app suite" {
157+
tmp=$(mktemp -d)
158+
trap 'rm -rf "$tmp"' EXIT
159+
cp -r packages/core/platform/sources "$tmp/sources"
160+
echo "examples/backups/postgres/run-all.sh" > "$tmp/diff"
161+
output=$(hack/select-e2e.sh "$tmp/diff" "$tmp/sources")
162+
[ "$output" = "postgres" ]
163+
}
164+
165+
@test "backup example without a matching suite selects nothing" {
166+
tmp=$(mktemp -d)
167+
trap 'rm -rf "$tmp"' EXIT
168+
cp -r packages/core/platform/sources "$tmp/sources"
169+
echo "examples/backups/no-such-app/run.sh" > "$tmp/diff"
170+
output=$(hack/select-e2e.sh "$tmp/diff" "$tmp/sources") || true
171+
[ -z "$output" ]
172+
}

0 commit comments

Comments
 (0)