feat(backups): rename backups and add a description (#39)
Part of #39.
Summary
Operators who keep several backups of one deployment cannot tell which backup was taken before a migration and which is a known-good copy, so they can restore the wrong one (#39). This pull request lets operators set a name and a description when they create a backup, and change both later. Both can be changed in the web UI, the GraphQL API, the SDK and styrminctl.
Not decided yet: issue #39 also asks for a name template for scheduled backups. This pull request does not add it, because no code creates backups from a schedule today. Either a follow-up issue is filed, or the author of #39 agrees to close the issue without it. A draft of the follow-up is in the implementation report, section 3.
Velero objects named after the backup id
The maintainer comment on #39 notes that the backup and restore flows named the Velero Backup object after backup.name. A rename would therefore break restores, and ADR-073 requires names built from the id.
- Every new Velero
Backupobject is namedstyrmin-<backup id>and has the labelstyrmin.io/backup-id. The flows get the name fromvelero_backup_name()inservices/backup/metadata.py. - Migration
a2a102e37495setsmetadata.velero_backup_nameon each existing backup whose name is notstyrmin-<id>. Those backups keep using the Velero object that an earlier version created. - The downgrade writes that stored name back into
name. It refuses to run, and changes nothing, if this would make two names equal. - After a downgrade, backups that were created with a custom name after the upgrade, or renamed after it, cannot be restored by the older code. The migration docstring states this limit.
Breaking changes to backup names
- Backup names must be unique for each deployment instance. Before this change, a name had to be unique across all backups. The database enforces this with the unique index
ix_backup_instance_id_name. - Scripts that find a Velero backup by its Styrmin name must use
styrmin-<backup id>for backups created after this change. The changelog fragmentchangelog/39.changed.mdrecords this.
Changes on each surface
- GraphQL: the new mutation
updateBackup(backupId, name, description): Backup, adescriptionargument oncreateBackup, and the fieldBackup.description.- Errors:
ALREADY_EXISTS, withexisting_backup_id, for a name already used in the instance;VALIDATION_ERROR;NOT_FOUND. - A name has 1 to 255 characters after trimming and no control characters.
- A description has at most 2,000 characters. An empty description clears it.
- Errors:
- SDK:
BackupResource.update_backup(), and adescriptionargument oncreate_backup(). - CLI:
- the new command
styrminctl backups update <id> [--name] [--description]; create --description;- the description shown in
getandlist.
- the new command
- Web UI: Create Backup opens a dialog with optional Name and Description fields. Pressing Enter in the empty dialog creates the backup with the default name.
- Each backup row shows the description and has an Edit action.
- Any user can expand a long description.
- The Restore Backup dialog shows the description.
- Documentation:
backups-and-restores.md;- the
backupssection ofstyrminctl.md; - a Backup entry in
CONTEXT.md; dev/knowledge/backend/backup-restore.md.
Tests
- Unit tests: the migration (PostgreSQL and SQLite), the service (including two writes of the same name at the same moment), the repository, the flows, and old custom-named backups.
- Propagation test:
backend/tests/functional/graphql/test_backup_update_propagation.py. - SDK, CLI and frontend tests: in
test_backups.py(SDK and CLI) andBackupDetailsDialog.test.tsx(frontend). - E2E:
test_backup_and_restore_lifecyclenow creates a backup with a name and a description. It renames the backup and checks the name and label of its Velero object. It then restores from the renamed backup.- The test passed locally in both variants, and
test_restore_lifecycle_transitions[ui-chromium]passed too (evidence). - These runs predate the last three commits (
ba3cc1f3,d6f19907,13f53acc), which came from the review. The local machine does not have enough memory for more E2E runs, so this pull request relies on CI for them, and fortest_infrahub_backup_restore.py, which never ran locally.
- The test passed locally in both variants, and
- Known local failure:
test_send_report_returns_false_when_the_connection_is_refusedfails on the author's machine, because a refused connection takes about 8 seconds there against a 2-second limit. This pull request does not change telemetry code.
Details
- Spec
- Plan
- Implementation report, which lists the review findings that were fixed and the ones still deferred.