Repository navigation
Add restic-based backup and restore for PVCs - #2
Merged
Merged
Conversation
Introduces three new CRDs and three reconcilers that add VolSync-style backup/restore for TopoLVM PVCs using restic against any S3-compatible object store: - BackupConfig (cluster-scoped singleton) — global S3 endpoint/bucket, credentials + restic password Secret refs, default schedule, retention, selector, and `keepSnapshotAfterBackup` toggle. - PVCBackup (namespaced, per PVC) — backup state machine with phases Idle → Snapshotting → Cloning → Moving → Cleanup → Synced|Failed, an in-process cron, and a manual `.spec.trigger` for on-demand runs. - Restore (namespaced) — provisions a fresh target PVC and mounts a restic mover Job against it. The target PVC is intentionally not owner-referenced so deleting the Restore never drops restored data. Each backup run creates a VolumeSnapshot, a temp PVC cloned from it, and a Job mounting the temp PVC read-only; restic pushes to `s3:<endpoint>/<bucket>/[<prefix>/]<namespace>/<pvc-name>`, giving one repository per source PVC. All children carry owner references, so GC handles cleanup on CR deletion; the reconciler also deletes them in the Cleanup phase at end of each run. The BackupConfig controller watches PVCs, applies selector + per-PVC `topolvm.io/backup*` annotation overrides, creates managed PVCBackup objects, and mirrors both user-authored Secrets into every namespace that has a managed PVC (user-authored PVCBackups are never touched). Wiring: `--enable-backup`, `--restic-image`, `--backup-mover-service- account`, `--controller-namespace` flags on topolvm-controller; new controller.backup.* Helm values block; CRD templates; ClusterRole additions for jobs/secrets/pods/log/volumesnapshots/backup CRDs. Testing: 14 pure-Go unit tests cover manifest shaping, owner refs, env composition, annotation merging, selector logic, and spec equality. A new e2e spec (`test/e2e/backup_test.go`, opt-in via BACKUP_ENABLED=1) walks the full PVC → backup → restore → verify loop. A new backup job in .github/workflows/e2e-k8s.yaml runs that spec with `--focus=backup` against Kubernetes 1.34.3 on same-repo events only (fork PRs cannot access the repo secrets). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> Signed-off-by: Dean Kamali <dean.kamali@gmail.com>
helm-docs picks up the three new controller.backup.* rows introduced by the prior commit. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> Signed-off-by: Dean Kamali <dean.kamali@gmail.com>
- Re-emit the 6 chart CRD templates with the trailing layout `make
manifests` produces: content, blank line, `{{ end }}`, newline. The
previous pattern (`{{ end }}` then trailing blank) diverged from the
Makefile's xargs-printf template and broke `make check-uncommitted`.
- Regenerate config/rbac/role.yaml across every package that carries
+kubebuilder:rbac markers. Earlier I only ran controller-gen against
internal/controller/... which dropped the `csidrivers` resource and
collapsed `logicalvolumes` into the wrong rule group.
No runtime behavior change; CI parity only.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Signed-off-by: Dean Kamali <dean.kamali@gmail.com>
TopoLVM's default StorageClass uses volumeBindingMode: WaitForFirstConsumer, meaning a PVC stays Pending until a Pod references it. Both the PVCBackup and Restore controllers were waiting for their PVCs to reach Bound before creating the mover/restore Job — a deadlock: the PVC never binds because no Pod exists, and the controller never creates the Pod because it's waiting on bind. The mover and restore Jobs are the *intended* first consumers. Create them eagerly; the scheduler picks a node when the Pod is scheduled, which triggers TopoLVM provisioning and binds the PVC. The e2e test had the same shape mistake: it waited for the source PVC to bind before creating the writer pod. Replaced with just waiting for the writer pod to reach Succeeded, which is an implicit (and correct) bind-and-provision check. This is why the first backup e2e run failed at `source PVC not bound: Pending` — the Eventually timed out at 120s because nothing was consuming the PVC. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> Signed-off-by: Dean Kamali <dean.kamali@gmail.com>
`make test` runs `gofmt -s -l` via the lint target; these three files were out of the canonical form: - import group ordering in internal/backup/manifests.go - const/field alignment in api/v1/restore_types.go - map literal alignment in internal/controller/backupconfig_controller_test.go No code behavior change. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> Signed-off-by: Dean Kamali <dean.kamali@gmail.com>
`generate-legacy-api` in the Makefile copies api/v1/* over api/legacy/v1/ verbatim. The prior commit ran gofmt -s on api/v1/restore_types.go but I forgot to propagate that same formatting to the legacy mirror, so check-uncommitted saw a drift on CI. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> Signed-off-by: Dean Kamali <dean.kamali@gmail.com>
The lint step in `make test` runs `gofmt -s -l .` across the entire repo. These two files had const-block alignment that diverged from gofmt's canonical form after my edits. No behavior change. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> Signed-off-by: Dean Kamali <dean.kamali@gmail.com>
Eight findings surfaced by CI's golangci-lint that local build didn't catch: - lll (max 120 chars): five long lines split across run.go, pkg/controller/backup_controllers.go, and test/e2e/backup_test.go. - unparam: removed unused `cfg backup.RuntimeConfig` parameter from PVCBackupReconciler.advanceMoving and .advanceCleanup — neither touched the config, only the CR status and child objects. - staticcheck QF1008: simplified pb.Status.LastSyncTime.Time.After(anchor) to pb.Status.LastSyncTime.After(anchor) — metav1.Time embeds time.Time so the selector is redundant. No behavior change. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> Signed-off-by: Dean Kamali <dean.kamali@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds VolSync-style backup and restore for TopoLVM PVCs, pushing to any S3-compatible object store via restic. One restic repository per source PVC, keyed by
<namespace>/<pvc-name>under an optional cluster-wide prefix.Three new CRDs:
BackupConfig(cluster-scoped singleton nameddefault) — global S3 endpoint/bucket, credentials + restic password Secret refs, default schedule, retention, PVC selector,keepSnapshotAfterBackuptoggle.PVCBackup(namespaced, per PVC) — backup state machine:Idle → Snapshotting → Cloning → Moving → Cleanup → Synced|Failed. In-process cron + manual.spec.triggerfor on-demand runs.Restore(namespaced) — provisions a fresh target PVC and runs a restic restore Job against it. The target PVC is intentionally not owner-referenced so deleting theRestorenever drops restored data.Each backup run creates a VolumeSnapshot, a temp PVC cloned from it, and a Job that mounts the temp PVC read-only at
/data. All children carry owner references, so GC handles cleanup on CR deletion; the reconciler also deletes them explicitly in the Cleanup phase.The BackupConfig controller watches PVCs, applies the selector + per-PVC
topolvm.io/backup*annotations, creates managedPVCBackupobjects, and mirrors both user-authored Secrets into every namespace that has a managed PVC. User-authoredPVCBackupobjects are never touched (keyed on the managed-by label).Opt-in via
--enable-backup/controller.backup.enabled=true. New flags:--restic-image(defaultrestic/restic:0.17.3),--backup-mover-service-account,--controller-namespace. CRDs, ClusterRole additions (jobs/secrets/pods/log/volumesnapshots/backup CRDs), and Helm values wired.Test plan
go test ./internal/backup/... ./internal/controller/...— all green.controller.backup.enabled=true— CRDs, RBAC, and flags all flow through.backup:e2e job (this PR) runs--focus=backupon Kubernetes 1.34.3 against the dedicated S3 bucket. Covers: write file → trigger backup → waitSynced→ delete source PVC → applyRestore→ waitSucceeded→ verify file contents on restored PVC.Risk notes
--enable-backup; the flag defaults off, so an operator-level upgrade with no value change is a no-op.POD_NAMESPACEis now unconditionally set on the controller Pod via downward API (previously only set when legacy/env was configured). This is a benign change — the controller already tolerated it being unset.github.event.pull_request.head.repo.full_name == github.repositorykeeps noise out of those runs.🤖 Generated with Claude Code