Update volume info in restore finalizing stage

Update volume info in restore finalizing stage to record info from DataDownload result

Signed-off-by: Wenkai Yin (尹文开) <wenkai.yin@broadcom.com>
This commit is contained in:
Wenkai Yin (尹文开)
2026-09-10 15:04:54 +08:00
parent 0255c6b8bf
commit a3d744db6a
12 changed files with 775 additions and 61 deletions
+12
View File
@@ -148,6 +148,18 @@ func (d *DataDownloadBuilder) Progress(progress shared.DataMoveOperationProgress
return d
}
// TotalBytes sets the DataDownload's TotalBytes.
func (d *DataDownloadBuilder) TotalBytes(totalBytes int64) *DataDownloadBuilder {
d.object.Status.Progress.TotalBytes = totalBytes
return d
}
// IncrementalBytes sets the DataDownload's IncrementalBytes.
func (d *DataDownloadBuilder) IncrementalBytes(incrementalBytes int64) *DataDownloadBuilder {
d.object.Status.IncrementalBytes = &incrementalBytes
return d
}
// Node sets the DataDownload's Node.
func (d *DataDownloadBuilder) Node(node string) *DataDownloadBuilder {
d.object.Status.Node = node
+19
View File
@@ -19,6 +19,7 @@ package builder
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"github.com/vmware-tanzu/velero/pkg/apis/velero/shared"
velerov1api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
)
@@ -62,6 +63,24 @@ func (b *PodVolumeBackupBuilder) Phase(phase velerov1api.PodVolumeBackupPhase) *
return b
}
// Progress sets the PodVolumeBackup's Progress.
func (b *PodVolumeBackupBuilder) Progress(progress shared.DataMoveOperationProgress) *PodVolumeBackupBuilder {
b.object.Status.Progress = progress
return b
}
// TotalBytes sets the PodVolumeBackup's TotalBytes.
func (b *PodVolumeBackupBuilder) TotalBytes(totalBytes int64) *PodVolumeBackupBuilder {
b.object.Status.Progress.TotalBytes = totalBytes
return b
}
// IncrementalBytes sets the PodVolumeBackup's IncrementalBytes.
func (b *PodVolumeBackupBuilder) IncrementalBytes(incrementalBytes int64) *PodVolumeBackupBuilder {
b.object.Status.IncrementalBytes = &incrementalBytes
return b
}
// Node sets the PodVolumeBackup's node name.
func (b *PodVolumeBackupBuilder) Node(name string) *PodVolumeBackupBuilder {
b.object.Spec.Node = name
+25
View File
@@ -19,6 +19,7 @@ package builder
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"github.com/vmware-tanzu/velero/pkg/apis/velero/shared"
velerov1api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
)
@@ -62,6 +63,30 @@ func (b *PodVolumeRestoreBuilder) Phase(phase velerov1api.PodVolumeRestorePhase)
return b
}
// RestoreType sets the PodVolumeRestore's RestoreType.
func (b *PodVolumeRestoreBuilder) RestoreType(restoreType string) *PodVolumeRestoreBuilder {
b.object.Spec.RestoreType = restoreType
return b
}
// Progress sets the PodVolumeRestore's Progress.
func (b *PodVolumeRestoreBuilder) Progress(progress shared.DataMoveOperationProgress) *PodVolumeRestoreBuilder {
b.object.Status.Progress = progress
return b
}
// TotalBytes sets the PodVolumeRestore's TotalBytes.
func (b *PodVolumeRestoreBuilder) TotalBytes(totalBytes int64) *PodVolumeRestoreBuilder {
b.object.Status.Progress.TotalBytes = totalBytes
return b
}
// IncrementalBytes sets the PodVolumeRestore's IncrementalBytes.
func (b *PodVolumeRestoreBuilder) IncrementalBytes(incrementalBytes int64) *PodVolumeRestoreBuilder {
b.object.Status.IncrementalBytes = &incrementalBytes
return b
}
// BackupStorageLocation sets the PodVolumeRestore's backup storage location.
func (b *PodVolumeRestoreBuilder) BackupStorageLocation(name string) *PodVolumeRestoreBuilder {
b.object.Spec.BackupStorageLocation = name
+83
View File
@@ -0,0 +1,83 @@
/*
Copyright the Velero contributors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package builder
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/vmware-tanzu/velero/pkg/apis/velero/shared"
velerov1api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
)
func TestDataDownloadBuilder_Bytes(t *testing.T) {
dd := ForDataDownload("velero", "dd-1").
TotalBytes(2048).
IncrementalBytes(512).
Result()
assert.Equal(t, int64(2048), dd.Status.Progress.TotalBytes)
assert.NotNil(t, dd.Status.IncrementalBytes)
assert.Equal(t, int64(512), *dd.Status.IncrementalBytes)
}
func TestPodVolumeBackupBuilder_ProgressAndBytes(t *testing.T) {
pvb1 := ForPodVolumeBackup("velero", "pvb-1").
Progress(shared.DataMoveOperationProgress{
TotalBytes: 4096,
BytesDone: 2048,
}).
Phase(velerov1api.PodVolumeBackupPhaseCompleted).
Result()
assert.Equal(t, int64(4096), pvb1.Status.Progress.TotalBytes)
assert.Equal(t, int64(2048), pvb1.Status.Progress.BytesDone)
pvb2 := ForPodVolumeBackup("velero", "pvb-2").
TotalBytes(1024).
IncrementalBytes(256).
Result()
assert.Equal(t, int64(1024), pvb2.Status.Progress.TotalBytes)
assert.NotNil(t, pvb2.Status.IncrementalBytes)
assert.Equal(t, int64(256), *pvb2.Status.IncrementalBytes)
}
func TestPodVolumeRestoreBuilder_ProgressAndBytes(t *testing.T) {
pvr1 := ForPodVolumeRestore("velero", "pvr-1").
RestoreType("Incremental").
Progress(shared.DataMoveOperationProgress{
TotalBytes: 8192,
BytesDone: 4096,
}).
Phase(velerov1api.PodVolumeRestorePhaseCompleted).
Result()
assert.Equal(t, "Incremental", pvr1.Spec.RestoreType)
assert.Equal(t, int64(8192), pvr1.Status.Progress.TotalBytes)
assert.Equal(t, int64(4096), pvr1.Status.Progress.BytesDone)
pvr2 := ForPodVolumeRestore("velero", "pvr-2").
TotalBytes(2048).
IncrementalBytes(512).
Result()
assert.Equal(t, int64(2048), pvr2.Status.Progress.TotalBytes)
assert.NotNil(t, pvr2.Status.IncrementalBytes)
assert.Equal(t, int64(512), *pvr2.Status.IncrementalBytes)
}