mirror of
https://github.com/cozystack/cozystack.git
synced 2026-11-21 20:23:39 +09:00
Reworks the never-merged backup-mariadb-e2e branch onto the modern Chainsaw approach (docs/agents/e2e-testing.md). The bats port that branch carried (hack/e2e-apps/backup-mariadb.bats) is dropped — the whole hack/e2e-apps/*.bats app suite has been replaced by hack/e2e-chainsaw/, and the mariadb strategy controller + example manifests it depended on have since landed on main independently. Only the e2e coverage was still missing. Convert examples/backups/mariadb/ from static numbered YAML into the same executable harness the other backup demos use (00-helpers.sh, run-all.sh, cleanup.sh), keeping the numbered manifests as the human-readable flow that run-all.sh drives — so the documented flow and the automated test can never drift. run-all.sh provisions a Bucket, derives the two per-app Secrets the strategy references from BucketInfo + the seaweedfs CA, deploys a source MariaDB with a sentinel row, fires an ad-hoc BackupJob, restores to a copy with a to-copy RestoreJob, and asserts the sentinel round-tripped through S3 into the copy while the source is left untouched. Add a second Chainsaw Test (mariadb-2-backup-roundtrip) to hack/e2e-chainsaw/mariadb/ that drives run-all.sh + cleanup.sh, mirroring postgres-2-backup-roundtrip: runs in tenant-root (the isolated e2e tenant cannot reach tenant-root's seaweedfs across the Cilium egress policy), skipDelete since the harness (not Chainsaw) owns the resources, fail-fast on terminal BackupJob/RestoreJob phases, and scoped catch diagnostics. Cleanup also prunes the operator-side k8s.mariadb.com Backup/Restore CRs the Cozystack jobs own only by label. Assisted-By: Claude <noreply@anthropic.com> Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Signed-off-by: Andrey Kolkov <androndo@gmail.com>
52 lines
2.7 KiB
Bash
Executable File
52 lines
2.7 KiB
Bash
Executable File
#!/bin/bash
|
|
# Best-effort teardown of everything the demo creates. Idempotent;
|
|
# missing resources are skipped silently.
|
|
set -euo pipefail
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
source "$SCRIPT_DIR/00-helpers.sh"
|
|
|
|
print_header "Cleanup"
|
|
|
|
log_substep "Deleting RestoreJob..."
|
|
kubectl -n "$NAMESPACE" delete restorejob.backups.cozystack.io "$RESTOREJOB_TOCOPY_NAME" --ignore-not-found
|
|
|
|
log_substep "Deleting Plan + BackupJob + derived Backup artefacts..."
|
|
kubectl -n "$NAMESPACE" delete plan.backups.cozystack.io "$PLAN_NAME" --ignore-not-found
|
|
kubectl -n "$NAMESPACE" delete backupjob.backups.cozystack.io "$BACKUPJOB_NAME" --ignore-not-found
|
|
# Only the Backups of THIS demo's apps — never `--all`: on a shared cluster the
|
|
# namespace can hold Backup artefacts of other applications and flows.
|
|
for b in $(kubectl -n "$NAMESPACE" get backups.backups.cozystack.io \
|
|
-o jsonpath='{range .items[*]}{.metadata.name} {.spec.applicationRef.name}{"\n"}{end}' 2>/dev/null |
|
|
awk -v src="$MARIADB_SRC_NAME" -v tgt="$MARIADB_TARGET_NAME" '$2 == src || $2 == tgt {print $1}'); do
|
|
kubectl -n "$NAMESPACE" delete backups.backups.cozystack.io "$b" --ignore-not-found
|
|
done
|
|
|
|
# The Cozystack BackupJob/RestoreJob own their operator-side k8s.mariadb.com
|
|
# Backup/Restore CRs only by the OwningJob labels (not OwnerReferences), so
|
|
# deleting the Cozystack jobs does not cascade to them. Left behind, a stale
|
|
# operator-side Backup would be reused by findMariaDBBackupForJob on the next
|
|
# run against a bucket path that no longer exists. Prune them by owner.
|
|
log_substep "Deleting operator-side k8s.mariadb.com Backup/Restore CRs..."
|
|
for owner in "$BACKUPJOB_NAME" "$RESTOREJOB_TOCOPY_NAME"; do
|
|
kubectl -n "$NAMESPACE" delete backups.k8s.mariadb.com,restores.k8s.mariadb.com \
|
|
-l "backups.cozystack.io/owned-by.BackupJobName=${owner}" --ignore-not-found
|
|
done
|
|
|
|
log_substep "Deleting MariaDB apps..."
|
|
kubectl -n "$NAMESPACE" delete mariadb.apps.cozystack.io "$MARIADB_SRC_NAME" "$MARIADB_TARGET_NAME" --ignore-not-found
|
|
|
|
log_substep "Deleting per-app backup Secrets..."
|
|
kubectl -n "$NAMESPACE" delete secret \
|
|
"${MARIADB_SRC_NAME}-mariadb-backup-creds" "${MARIADB_SRC_NAME}-mariadb-backup-ca" \
|
|
"${MARIADB_TARGET_NAME}-mariadb-backup-creds" "${MARIADB_TARGET_NAME}-mariadb-backup-ca" --ignore-not-found
|
|
|
|
log_substep "Deleting Bucket..."
|
|
kubectl -n "$NAMESPACE" delete bucket.apps.cozystack.io "$BUCKET_NAME" --ignore-not-found
|
|
|
|
log_substep "Deleting BackupClass + MariaDB strategy (cluster-scoped)..."
|
|
kubectl delete backupclass.backups.cozystack.io "$BACKUPCLASS_NAME" --ignore-not-found
|
|
kubectl delete mariadb.strategy.backups.cozystack.io "$STRATEGY_NAME" --ignore-not-found
|
|
|
|
log_success "Cleanup complete."
|