feat(backups): rename backups and add a description (#39)

Draft
MI
5d ago
+6862-272

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 Backup object is named styrmin-<backup id> and has the label styrmin.io/backup-id. The flows get the name from velero_backup_name() in services/backup/metadata.py.
  • Migration a2a102e37495 sets metadata.velero_backup_name on each existing backup whose name is not styrmin-<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 fragment changelog/39.changed.md records this.

Changes on each surface

  • GraphQL: the new mutation updateBackup(backupId, name, description): Backup, a description argument on createBackup, and the field Backup.description.
    • Errors: ALREADY_EXISTS, with existing_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.
  • SDK: BackupResource.update_backup(), and a description argument on create_backup().
  • CLI:
    • the new command styrminctl backups update <id> [--name] [--description];
    • create --description;
    • the description shown in get and list.
  • 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:

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) and BackupDetailsDialog.test.tsx (frontend).
  • E2E: test_backup_and_restore_lifecycle now 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 for test_infrahub_backup_restore.py, which never ran locally.
  • Known local failure: test_send_report_returns_false_when_the_connection_is_refused fails 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