Repository navigation
feat: gate backups on repository health from the last check - #4
Open
Svilen-Stefanov wants to merge 1 commit into
Open
Svilen-Stefanov wants to merge 1 commit into
Svilen-Stefanov wants to merge 1 commit into
Conversation
The Backup controller reads the repository's last finished Check and its Snapshots before starting a backup Job, records the result in a new RepositoryHealthy condition, exports it as a Prometheus metric, and skips the backup when the last check failed and skipOnFailedCheck (or the --global-skip-backup-on-failed-check operator flag) is set. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
CodeBoarding reviewStatus: 7 changed components See the full change in CodeBoarding. graph LR
n_Operator_Controllers["Operator Controllers"]
n_Restic_Execution_Client["Restic Execution Client"]
n_Kubernetes_API_Schemas["Kubernetes API Schemas"]
n_Command_Line_Entrypoints["Command-Line Entrypoints"]
n_Restore_Utilities_and_Helpers["Restore Utilities and Helpers"]
n_Operator_Controllers -- "checks repository health and lists pods via" --> n_Restic_Execution_Client
n_Operator_Controllers -- "reconciles and updates status of" --> n_Kubernetes_API_Schemas
n_Restic_Execution_Client -- "utilizes string generator from" --> n_Operator_Controllers
n_Restic_Execution_Client -- "streams archives through" --> n_Restore_Utilities_and_Helpers
n_Restic_Execution_Client -- "reads check and snapshot schemas from" --> n_Kubernetes_API_Schemas
n_Command_Line_Entrypoints -- "registers controllers in" --> n_Operator_Controllers
n_Command_Line_Entrypoints -- "invokes restic commands on" --> n_Restic_Execution_Client
n_Command_Line_Entrypoints -- "invokes restore helpers from" --> n_Restore_Utilities_and_Helpers
classDef added fill:#1f883d,stroke:#0b5d23,color:#ffffff;
classDef modified fill:#bf8700,stroke:#7d4e00,color:#ffffff;
classDef deleted fill:#cf222e,stroke:#82071e,color:#ffffff,stroke-dasharray:5 3;
class n_Operator_Controllers,n_Restic_Execution_Client,n_Kubernetes_API_Schemas,n_Command_Line_Entrypoints modified;
linkStyle 4 stroke:#0b5d23,stroke-width:2px;
linkStyle 0,1 stroke:#7d4e00,stroke-width:2px;
|
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
Gate backups on the health of their repository. Before the Backup controller starts a backup Job, it reads the last finished
Checkof the repository and the repository'sSnapshotresources, records the result on theBackup, and exports it as a metric. When the last check failed, a backup can opt in to being skipped instead of writing more data into a repository that restic reported as damaged.Changes
Read repository health on the restic side
ReadRepositoryHealthinrestic/kubernetes, next to the snapshot sync that already owns theSnapshotresources.CheckandSnapshotresources, keeps the ones for the backup's repository, and returns the last finished check, the snapshot count, and when the newest snapshot was taken.API: condition, reasons, and an opt-in field
RepositoryHealthycondition onBackupwith reasonsLastCheckSucceeded,LastCheckFailed, andNoCheckFound. The message names the check, when it finished, and the snapshot summary.skipOnFailedCheckfield onBackupSpec, also available inSchedulebackups. A skipped backup completes with reasonRepositoryUnhealthyand starts no Job.CheckList.LatestFinished,Check.FinishedAt,Check.RepositoryOrDefault, andSnapshotList.Latest.BackupandScheduleCRDs.Gate in the Backup controller
Provisionbefore taking the repository lock, so a skipped backup never waits for a lock or creates PreBackupPods.--global-skip-backup-on-failed-check(BACKUP_GLOBAL_SKIP_BACKUP_ON_FAILED_CHECK) that enables skipping for all backups.Metrics
k8up_backup_repository_healthy{namespace}: 1 if the last finished check succeeded, 0 if it failed.k8up_backups_skipped_unhealthy_repository_total{namespace}: backups skipped because of a failed check.Docs
Testing
api/v1: latest finished check, finish time of running and failed checks, repository fallback to the global repository, latest snapshot.restic/kubernetes: health with no resources, a failed check after a successful one, checks and snapshots of other repositories ignored, and backend-less checks against the global repository; message formatting.operator/backupcontroller: no check, succeeded check, failed check without opt-in, and skips throughskipOnFailedCheckand through the global flag, checked on the stored status.Local validation:
go build ./...andgo vet ./...passed.go vet -tags integrationon the touched packages passed.go test ./api/... ./restic/... ./operator/... ./cmd/...passed.🤖 Generated with Claude Code