Skip to content

Commit

Permalink
Use VolumeInfo to help restore the PV.
Browse files Browse the repository at this point in the history
Signed-off-by: Xun Jiang <jxun@vmware.com>
  • Loading branch information
Xun Jiang committed Nov 22, 2023
1 parent 5c958d8 commit f0c2918
Show file tree
Hide file tree
Showing 8 changed files with 233 additions and 130 deletions.
1 change: 1 addition & 0 deletions changelogs/unreleased/7138-blackpiglet
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Use VolumeInfo to help restore the PV.
2 changes: 1 addition & 1 deletion design/pv_backup_info.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ type BackupStore interface {
### How the VolumeInfo array is used.

#### Generate the PVC backed-up information summary
The downstream tools can use this VolumeInfo array to format and display their volume information. This is in the scope of this feature.
The downstream tools can use this VolumeInfo array to format and display their volume information. This is not in the scope of this feature.

#### Retrieve volume backed-up information for `velero backup describe` command
The `velero backup describe` can also use this VolumeInfo array structure to display the volume information. The snapshot data mover volume should use this structure at first, then the Velero native snapshot, CSI snapshot, and PodVolumeBackup can also use this structure. The detailed implementation is also not in this feature's scope.
Expand Down
11 changes: 11 additions & 0 deletions pkg/controller/restore_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import (
kubeutil "github.com/vmware-tanzu/velero/pkg/util/kube"
"github.com/vmware-tanzu/velero/pkg/util/logging"
"github.com/vmware-tanzu/velero/pkg/util/results"
"github.com/vmware-tanzu/velero/pkg/volume"
)

// nonRestorableResources is an exclusion list for the restoration process. Any resources
Expand Down Expand Up @@ -520,6 +521,15 @@ func (r *restoreReconciler) runValidatedRestore(restore *api.Restore, info backu
return errors.Wrap(err, "fail to fetch CSI VolumeSnapshots metadata")
}

volumeInfos, err := backupStore.GetBackupVolumeInfos(restore.Spec.BackupName)
if err != nil {
restoreLog.WithError(err).Infof("Backup %s doesn't have volumeinfos metadata file.", restore.Spec.BackupName)
}
backupVolumeInfoMap := make(map[string]volume.VolumeInfo)
for _, volumeInfo := range volumeInfos.VolumeInfos {
backupVolumeInfoMap[volumeInfo.PVName] = volumeInfo
}

restoreLog.Info("starting restore")

var podVolumeBackups []*api.PodVolumeBackup
Expand All @@ -537,6 +547,7 @@ func (r *restoreReconciler) runValidatedRestore(restore *api.Restore, info backu
ResourceModifiers: resourceModifiers,
DisableInformerCache: r.disableInformerCache,
CSIVolumeSnapshots: csiVolumeSnapshots,
VolumeInfoMap: backupVolumeInfoMap,
}
restoreWarnings, restoreErrors := r.restorer.RestoreWithResolvers(restoreReq, actionsResolver, pluginManager)

Expand Down
23 changes: 23 additions & 0 deletions pkg/persistence/mocks/backup_store.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pkg/persistence/object_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ type BackupStore interface {
GetCSIVolumeSnapshots(name string) ([]*snapshotv1api.VolumeSnapshot, error)
GetCSIVolumeSnapshotContents(name string) ([]*snapshotv1api.VolumeSnapshotContent, error)
GetCSIVolumeSnapshotClasses(name string) ([]*snapshotv1api.VolumeSnapshotClass, error)
GetBackupVolumeInfos(name string) (*volume.VolumeInfos, error)

// BackupExists checks if the backup metadata file exists in object storage.
BackupExists(bucket, backupName string) (bool, error)
Expand Down
1 change: 1 addition & 0 deletions pkg/restore/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ type Request struct {
ResourceModifiers *resourcemodifiers.ResourceModifiers
DisableInformerCache bool
CSIVolumeSnapshots []*snapshotv1api.VolumeSnapshot
VolumeInfoMap map[string]volume.VolumeInfo
}

type restoredItemStatus struct {
Expand Down
Loading

0 comments on commit f0c2918

Please sign in to comment.