kubeblocks icon indicating copy to clipboard operation
kubeblocks copied to clipboard

chore: restore Backup dataSource PVCs in dataprotection

Open leon-ape opened this issue 6 months ago • 1 comments

Summary

Implement the dataprotection runtime for PVCs whose dataSourceRef points to a DP Backup.

Changes

  • Add DP-specific restore parameter annotations and Backup dataSourceRef helpers.
  • Handle Backup-kind PVC data sources in VolumePopulatorReconciler.
  • Split PVC handling into restore-data, provision-only, and failed decisions.
  • Preserve old TargetVolumes and sharding target semantics, including provision-only for non-restored PVCs.
  • Reuse the populate PVC, PV rebind, cleanup, condition, and restore-manager lifecycle.
  • Restore system account data as part of the DP runtime path.
  • Protect referenced Backups by checking Cluster.spec.restore and restore status.

Not included

  • No restore ops switch to Cluster.spec.restore.
  • No legacy restore annotation constant or plan restore cleanup.

Validation

  • make generate
  • make manifests
  • make doc
  • make fmt
  • make lint
  • go test ./controllers/dataprotection
  • go test ./pkg/dataprotection/restore

leon-ape avatar May 18 '26 08:05 leon-ape

Codecov Report

:x: Patch coverage is 56.71741% with 654 lines in your changes missing coverage. Please review. :white_check_mark: Project coverage is 53.13%. Comparing base (7e2fd5a) to head (6abecfd).

Files with missing lines Patch % Lines
...llers/dataprotection/volumepopulator_controller.go 56.16% 503 Missing and 147 partials :warning:
controllers/dataprotection/backup_controller.go 81.81% 3 Missing and 1 partial :warning:
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #10245      +/-   ##
==========================================
+ Coverage   53.00%   53.13%   +0.12%     
==========================================
  Files         533      533              
  Lines       61423    62878    +1455     
==========================================
+ Hits        32560    33411     +851     
- Misses      25581    26051     +470     
- Partials     3282     3416     +134     
Flag Coverage Δ
unittests 53.13% <56.71%> (+0.12%) :arrow_up:

Flags with carried forward coverage won't be shown. Click here to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

codecov[bot] avatar May 18 '26 09:05 codecov[bot]

Found a few blocking issues in the updated implementation:

  1. backup_controller.go:694: the legacy restore annotation path is no longer protected. This PR changes checkRestoreInProgress from checking the Cluster kubeblocks.io/restore-from-backup annotation to only checking Cluster.spec.restore, while the PR still states that the legacy annotation path is preserved. During an existing annotation-based restore, backup jobs can now proceed instead of being delayed. Please keep the old annotation check alongside the new Cluster.spec.restore check until the legacy path is actually removed.

  2. volumepopulator_controller.go:237: Backup dataSourceRef.namespace is ignored. MatchToPopulate accepts dataSourceRef.kind=Backup, but validateRestoreAndBuildMGR resolves the Backup namespace from apps.kubeblocks.io/restore-source-namespace, falling back to the PVC namespace, and never uses pvc.Spec.DataSourceRef.Namespace. If dataSourceRef.namespace is set directly, or diverges from the annotation, the populator can restore from the wrong Backup object or fail to find the intended one. Please use dataSourceRef.Namespace as the canonical source namespace, or validate it matches the annotation before proceeding.

  3. volumepopulator_controller.go:1713: restored system accounts are not integrated with accountProvision state. This PR restores system account Secrets and marks them with apps.kubeblocks.io/system-account-provisioned, but the existing accountProvision transformer does not read this annotation. On the new Cluster.spec.restore path, transformer_component_account_provision.go:163 still only skips create when the old restore annotation exists. Non-init restored accounts can therefore be created again after the Component reaches Running, causing duplicate-account failures or unintended account/password changes. Please make accountProvision recognize restored/provisioned account Secrets, or update the Component accountProvision condition when restoring them.

leon-ape avatar Jun 01 '26 08:06 leon-ape

/approve

leon-ape avatar Jun 02 '26 05:06 leon-ape