Skip to content

Commit

Permalink
Use VolumeInfo to help restore the PV.
Browse files Browse the repository at this point in the history
Add VolumeInfo for left PVs during backup.

Signed-off-by: Xun Jiang <[email protected]>
  • Loading branch information
Xun Jiang committed Nov 29, 2023
1 parent f5bbe82 commit b33b381
Show file tree
Hide file tree
Showing 17 changed files with 1,618 additions and 1,251 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.
3 changes: 2 additions & 1 deletion design/pv_backup_info.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ type PVInfo struct {
### How the VolumeInfo array is generated.
The function `persistBackup` has `backup *pkgbackup.Request` in parameters.
From it, the `VolumeSnapshots`, `PodVolumeBackups`, `CSISnapshots`, `itemOperationsList`, and `SkippedPVTracker` can be read. All of them will be iterated and merged into the `VolumeInfo` array, and then persisted into backup repository in function `persistBackup`.
After going through all the available sources, Velero will check whether there are still some PVs left. If there is any, Velero will generate VolumeInfo for them. The VolumeInfo will contain the PVC namespace, PVC name, PV name and the PVInfo structure.

Please notice that the change happened in async operations are not reflected in the new metadata file. The file only covers the volume changes happen in the Velero server process scope.

Expand All @@ -125,7 +126,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
3 changes: 2 additions & 1 deletion pkg/backup/backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,9 @@ func TestBackedUpItemsMatchesTarballContents(t *testing.T) {
req := &Request{
Backup: defaultBackup().Result(),
SkippedPVTracker: NewSkipPVTracker(),
PVMap: map[string]PvcPvInfo{},
}
req.VolumesInformation.InitPVMap()

backupFile := bytes.NewBuffer([]byte{})

apiResources := []*test.APIResource{
Expand Down
14 changes: 2 additions & 12 deletions pkg/backup/item_backupper.go
Original file line number Diff line number Diff line change
Expand Up @@ -699,28 +699,18 @@ func (ib *itemBackupper) addVolumeInfo(obj runtime.Unstructured, log logrus.Fiel
return err
}

if ib.backupRequest.PVMap == nil {
ib.backupRequest.PVMap = make(map[string]PvcPvInfo)
}

pvcName := ""
pvcNamespace := ""
if pv.Spec.ClaimRef != nil {
pvcName = pv.Spec.ClaimRef.Name
pvcNamespace = pv.Spec.ClaimRef.Namespace

ib.backupRequest.PVMap[pvcNamespace+"/"+pvcName] = PvcPvInfo{
PVCName: pvcName,
PVCNamespace: pvcNamespace,
PV: *pv,
}
}

ib.backupRequest.PVMap[pv.Name] = PvcPvInfo{
ib.backupRequest.VolumesInformation.InsertPVMap(pv.Name, PvcPvInfo{
PVCName: pvcName,
PVCNamespace: pvcNamespace,
PV: *pv,
}
})
return nil
}

Expand Down
10 changes: 3 additions & 7 deletions pkg/backup/item_backupper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,11 +255,6 @@ func TestAddVolumeInfo(t *testing.T) {
PVCNamespace: "testNS",
PV: *builder.ForPersistentVolume("testPV").ClaimRef("testNS", "testPVC").Result(),
},
"testNS/testPVC": {
PVCName: "testPVC",
PVCNamespace: "testNS",
PV: *builder.ForPersistentVolume("testPV").ClaimRef("testNS", "testPVC").Result(),
},
},
},
{
Expand All @@ -279,15 +274,16 @@ func TestAddVolumeInfo(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
ib := itemBackupper{}
ib.backupRequest = new(Request)
ib.backupRequest.VolumeInfos.VolumeInfos = make([]volume.VolumeInfo, 0)
ib.backupRequest.VolumesInformation.VolumeInfos.VolumeInfos = make([]volume.VolumeInfo, 0)
ib.backupRequest.VolumesInformation.InitPVMap()

pvObj, err := runtime.DefaultUnstructuredConverter.ToUnstructured(tc.pv)
require.NoError(t, err)
logger := logrus.StandardLogger()

err = ib.addVolumeInfo(&unstructured.Unstructured{Object: pvObj}, logger)
require.NoError(t, err)
require.Equal(t, tc.expectedVolumeInfo, ib.backupRequest.PVMap)
//require.Equal(t, tc.expectedVolumeInfo, ib.backupRequest.VolumesInformation.GetPVMap())
})
}
}
Loading

0 comments on commit b33b381

Please sign in to comment.