longhorn-manager
longhorn-manager copied to clipboard
feat(backup): multiple backup stores support
Support multiple backup stores to create, delete and update them.
Remove the default backup target instead using Default flag in BackupTarget CR spec.
Adding a flag ReadOnly in BackupTarget CR spec prevent backups from being created and storing on this remote backup target.
And provide HTTP endpoints to create, delete, update and list secrets.
Ref: longhorn/longhorn#5411
This pull request is now in conflicts. Could you fix it @mantissahz? 🙏
This pull request is now in conflicts. Could you fix it @mantissahz? 🙏
Is this ready for review?
Is this ready for review?
@innobead Yes, but LEP https://github.com/longhorn/longhorn/pull/6630 is still in review.
Hi @mantissahz , I have reviewed the PR, PTAL, thanks!
BTW, do we have upgrade plan for the new backup CRD changes
I think we need to modify the backup CRDs when user upgrades from previous version to this version
so the CRDs will have fields like backupTargetName,..., etc.
cc @mantissahz
BTW, do we have upgrade plan for the new backup CRD changes
@ChanYiLin, I have added the upgrade path parts for multiple backup targets but it still has one problem I need to fix. I will have an update soon. Thanks for your review.
I think if we can make sure system backup and csi backup can support specifying backupTarget instead of using default
Then we can remove the default concept and the handling logic and prevent race condition of updating status
cc @innobead @derekbit @james-munson
This pull request is now in conflicts. Could you fix it @mantissahz? 🙏
This pull request is now in conflicts. Could you fix it @mantissahz? 🙏
This pull request is now in conflict. Could you fix it @mantissahz? 🙏
This pull request is now in conflict. Could you fix it @mantissahz? 🙏
@mantissahz ready for review?
[!NOTE]
Reviews paused
Use the following commands to manage reviews:
@coderabbitai resumeto resume automatic reviews.@coderabbitai reviewto trigger a single review.
Walkthrough
The pull request introduces extensive modifications to the Longhorn backup management system, enhancing functionalities related to backup targets and backups. Key updates include new methods for creating, retrieving, updating, and deleting backup targets, as well as improved error handling and logging. Additionally, the API is updated to support new fields in various data structures, facilitating better management of backup resources. The changes also extend to the webhook components, adding validators and mutators for backup targets and backups, thereby improving the overall robustness and usability of the backup management system.
Changes
| File Path | Change Summary |
|---|---|
| api/backup.go | Added methods for backup target management (Get, Create, Update, Delete) and listing backups; improved error handling. |
| api/backupbackingimage.go | Updated BackupBackingImageCreate to accept structured input; enhanced error handling. |
| api/model.go | Added new fields to Volume, BackupVolume, BackupBackingImage, Backup, and updated schemas for backup targets. |
| api/router.go | Introduced new routes for backup targets and a WebSocket stream handler for real-time updates. |
| api/snapshot.go | Modified SnapshotBackup method to specify backup target during snapshot backup. |
| api/volume.go | Updated VolumeGet to retrieve volume by name; improved response handling. |
| app/recurring_job.go | Added getBackupVolume method; updated doRecurringBackup to use this method. |
| client/generated_backup.go | Added BackupTargetName field to Backup struct. |
| client/generated_backup_target.go | Added Name field to BackupTarget struct. |
| client/generated_backup_volume.go | Added BackupTargetName and VolumeName fields to BackupVolume struct. |
| client/generated_volume.go | Added BackupTargetName field to Volume struct. |
| controller/backing_image_data_source_controller.go | Updated generateBackingImageDataSourcePodManifest for dynamic backup target retrieval. |
| controller/backup_backing_image_controller.go | Enhanced backup target retrieval logic and error handling. |
| controller/backup_controller.go | Added methods for retrieving backup targets; improved reconciliation logic. |
| controller/backup_target_controller.go | Introduced BackupStoreTimer type for managing multiple backup targets; updated sync methods. |
| controller/backup_volume_controller.go | Updated backup target handling and deletion logic; refined backup volume operations. |
| controller/controller_test.go | Added TestBackupTargetName constant for testing. |
| controller/engine_controller.go | Modified restoreBackup to use correct backup volume; improved error handling. |
| controller/setting_controller.go | Removed BackupStoreTimer and simplified syncBackupTarget method. |
| controller/system_backup_controller.go | Enhanced backup creation processes for volumes and backing images. |
| controller/uninstall_controller.go | Improved deleteBackupTargets method for proper annotations during uninstallation. |
| controller/utils.go | Added isBackupTargetAvailable function; modified existing cleanup checks. |
| controller/volume_controller.go | Enhanced volume creation and restoration processes with backup target handling. |
| controller/volume_controller_test.go | Expanded test cases for backup volume scenarios. |
| csi/controller_server.go | Added getBackupVolume method for improved backup volume retrieval. |
| datastore/kubernetes.go | Added methods for managing AWS IAM Role annotations related to backup targets. |
| datastore/longhorn.go | Enhanced backup management with new methods for listing and validating backup targets. |
| engineapi/backup_backing_image.go | Updated BackupBackingImageMonitor to include backing image name handling. |
| engineapi/types.go | Added BackupTargetName and VolumeName fields to BackupVolume struct; added BackupTargetName to Backup struct. |
| k8s/crds.yaml | Upgraded CRDs and introduced new fields for backup target management. |
| k8s/pkg/apis/longhorn/v1beta2/backingimagedatasource.go | Added DataSourceTypeRestoreParameterBackupTargetName constant. |
| k8s/pkg/apis/longhorn/v1beta2/backup.go | Added BackupTarget field to BackupStatus struct. |
| k8s/pkg/apis/longhorn/v1beta2/backupbackingimage.go | Updated BackupBackingImageSpec with new fields for backing image and backup target. |
| k8s/pkg/apis/longhorn/v1beta2/backupvolume.go | Added BackupTargetName and VolumeName fields to BackupVolumeSpec. |
| k8s/pkg/apis/longhorn/v1beta2/volume.go | Added BackupTargetName field to VolumeSpec. |
| manager/backupbackingimage.go | Updated RestoreBackupBackingImage and CreateBackupBackingImage methods for new parameters. |
| manager/engine.go | Enhanced backup target management with new methods for creating, updating, and deleting backup targets. |
| manager/volume.go | Updated restoreBackingImage and Create methods to include backup target name handling. |
| types/types.go | Added new constants and functions related to backup targets and volumes. |
| upgrade/util/util.go | Corrected RandomIDLenth constant to RandomIDLength. |
| upgrade/upgrade.go | Added upgrade path handling for versions below v1.8.0. |
| webhook/resources/backingimage/mutator.go | Enhanced Create method for backup target name retrieval and error handling. |
| webhook/resources/backup/mutator.go | Improved Create method to handle BackupTargetName and error reporting. |
| webhook/resources/backup/validator.go | Updated validation logic for backup creation requests. |
| webhook/resources/backupbackingimage/mutator.go | Enhanced Create method for backup backing images with improved error handling. |
| webhook/resources/backuptarget/mutator.go | Introduced mutator for managing backup targets in Kubernetes admission webhook context. |
| webhook/resources/backuptarget/validator.go | Implemented validation logic for backup target resources. |
| webhook/resources/backupvolume/mutator.go | Enhanced backup volume management during updates. |
| webhook/resources/volume/mutator.go | Improved handling of BackupTargetName during volume creation and updates. |
| webhook/resources/volume/validator.go | Added validateBackupTarget method to ensure backup target validity. |
| webhook/server/mutation.go | Updated to include mutator for backup targets in the webhook server. |
| webhook/server/validation.go | Added validators for backup and backup target resources in the webhook server. |
| util/util.go | Corrected constant name from RandomIDLenth to RandomIDLength. |
Possibly related PRs
- #3038: The changes in this PR enhance the backup deletion process, which is related to the main PR's focus on backup target management and error handling in backup operations.
- #3246: This PR improves the backup policy by ensuring that backups are checked for being up-to-date, which aligns with the main PR's enhancements to backup management functionalities.
Suggested reviewers
- derekbit: Suggested reviewer for the changes made in the pull request.
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?
🪧 Tips
Chat
There are 3 ways to chat with CodeRabbit:
- Review comments: Directly reply to a review comment made by CodeRabbit. Example:
I pushed a fix in commit <commit_id>, please review it.Generate unit testing code for this file.Open a follow-up GitHub issue for this discussion.
- Files and specific lines of code (under the "Files changed" tab): Tag
@coderabbitaiin a new review comment at the desired location with your query. Examples:@coderabbitai generate unit testing code for this file.@coderabbitai modularize this function.
- PR comments: Tag
@coderabbitaiin a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:@coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.@coderabbitai read src/utils.ts and generate unit testing code.@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.@coderabbitai help me debug CodeRabbit configuration file.
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.
CodeRabbit Commands (Invoked using PR comments)
@coderabbitai pauseto pause the reviews on a PR.@coderabbitai resumeto resume the paused reviews.@coderabbitai reviewto trigger an incremental review. This is useful when automatic reviews are disabled for the repository.@coderabbitai full reviewto do a full review from scratch and review all the files again.@coderabbitai summaryto regenerate the summary of the PR.@coderabbitai generate docstringsto generate docstrings for this PR. (Beta)@coderabbitai resolveresolve all the CodeRabbit review comments.@coderabbitai configurationto show the current CodeRabbit configuration for the repository.@coderabbitai helpto get help.
Other keywords and placeholders
- Add
@coderabbitai ignoreanywhere in the PR description to prevent this PR from being reviewed. - Add
@coderabbitai summaryto generate the high-level summary at a specific location in the PR description. - Add
@coderabbitaianywhere in the PR title to generate the title automatically.
Documentation and Community
- Visit our Documentation for detailed information on how to use CodeRabbit.
- Join our Discord Community to get help, request features, and share feedback.
- Follow us on X/Twitter for updates and announcements.
@mantissahz ready for review?
@derekbit, Yes, I think it is ready for review. And I will start to modify the test cases.
@mantissahz Need to make sure the routes of the backup resource creation without any problem, e.g.
- Longhorn cluster and add an empty backup store
- Longhorn cluster add non-empty backup store
- DR volume
Please have a complete test plan for the feature.
@coderabbitai pause
:white_check_mark: Actions performed
Reviews paused.
There is a volume whose spec.backupTargetName is set to target-001. If an user removes the backup target target-001 and add target-002. Who will update volume.spec.backupTargetName?
Users need to update the spec.backupTargetName by themself.
For the system backup and restore, should we include none-default BackupTarget CRs?
Yes, I think we should include BackupTarget CRs.
Some tasks need to be examined and done:
- [x] When deleting a backup target assigned to the volumes, the field
Spec.BackupTargetNameand labelbackup-targetof the volumes must be modified to thedefault. - [x] The corresponding backup targets of DR volumes can not be deleted and URLs can not be modified.
- [ ] System Backup test plans for saving and restoring the backup targets.
- [x] Clean up the backup target URL before deleting it while uninstalling Longhorn.
- What will happen after a valid URL of a backup target to an invalud URL? Will the backup volumes and backups be cleaned up? Any difference before and after applying the feature.
The backup volume and backups will not be cleaned up if the backup target URL is modified from valid one to invalid one in current implementation and this PR because getInforFromBackupStore failed will directly return back and skip the synchronization for backup volumes, backup backing images and system backups.
- What will happen after a valid URL of a backup target to an empty string? Will the backup volumes and backups be cleaned up? Any difference before and after applying the feature.
The same as the current implementation, in this PR the backup volumes, backups, backup backing images, and system backups will be cleaned up when the backup target URL is empty.
- For a newly created volume, the v.spec.backupTargetName is always empty, so users need to change it later. We should support a parameter backupTargetName in the storageClass, so the v.spec.backupTargetName can be from the storageClass.
If the field v.spec.backupTargetName is not assigned during creation, it will be the default backup target name when mutating,
but YES we can introduce backupTargetName in the parameters of the StorageClass
but YES we can introduce
backupTargetNamein the parameters of the StorageClass
Then, need to implement it in the PR.
Hi @mantissahz , as we discussed, remember to update below settings title with default prefix or update in setting description.
- backup target -> Default backup target
- Backup Target Credential Secret -> Default Backup Target Credential Secret
- Backupstore Poll Interval -> Default Backupstore Poll Interval
cc @derekbit
as we discussed, remember to update below settings title with default prefix or update in setting description.
- backup target -> Default backup target
- Backup Target Credential Secret -> Default Backup Target Credential Secret
- Backupstore Poll Interval -> Default Backupstore Poll Interval
@a110605 Modified. Could you take a look? Thanks
@a110605 Modified. Could you take a look? Thanks
Looks good. 👍
Need to update the descriptions of the two settings. They only serve for default backup store.
https://github.com/longhorn/longhorn-manager/blob/master/types/setting.go#L361-L377
Need to update the descriptions of the two settings. They only serve for default backup store. https://github.com/longhorn/longhorn-manager/blob/master/types/setting.go#L361-L377
Have a new commit e6a5b4e to address it.