mirror of
https://github.com/vmware-tanzu/velero.git
synced 2026-01-08 14:21:18 +00:00
Fix issue #7163.
Update CSIVolumeSnapshotsCompleted in backup's status and the metric during backup finalize stage according to async operations content. Signed-off-by: Xun Jiang <jxun@vmware.com>
This commit is contained in:
@@ -36,6 +36,7 @@ import (
|
||||
|
||||
velerov1api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
|
||||
"github.com/vmware-tanzu/velero/pkg/builder"
|
||||
"github.com/vmware-tanzu/velero/pkg/features"
|
||||
"github.com/vmware-tanzu/velero/pkg/itemoperation"
|
||||
"github.com/vmware-tanzu/velero/pkg/kuberesource"
|
||||
"github.com/vmware-tanzu/velero/pkg/metrics"
|
||||
@@ -66,12 +67,14 @@ func TestBackupFinalizerReconcile(t *testing.T) {
|
||||
defaultBackupLocation := builder.ForBackupStorageLocation(velerov1api.DefaultNamespace, "default").Result()
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
backup *velerov1api.Backup
|
||||
backupOperations []*itemoperation.BackupOperation
|
||||
backupLocation *velerov1api.BackupStorageLocation
|
||||
expectError bool
|
||||
expectPhase velerov1api.BackupPhase
|
||||
name string
|
||||
backup *velerov1api.Backup
|
||||
backupOperations []*itemoperation.BackupOperation
|
||||
backupLocation *velerov1api.BackupStorageLocation
|
||||
enableCSI bool
|
||||
expectError bool
|
||||
expectPhase velerov1api.BackupPhase
|
||||
expectedCompletedVS int
|
||||
}{
|
||||
{
|
||||
name: "Finalizing backup is completed",
|
||||
@@ -145,6 +148,50 @@ func TestBackupFinalizerReconcile(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Test calculate backup.Status.BackupItemOperationsCompleted",
|
||||
backup: builder.ForBackup(velerov1api.DefaultNamespace, "backup-3").
|
||||
StorageLocation("default").
|
||||
ObjectMeta(builder.WithUID("foo")).
|
||||
StartTimestamp(fakeClock.Now()).
|
||||
WithStatus(velerov1api.BackupStatus{
|
||||
StartTimestamp: &metav1Now,
|
||||
CompletionTimestamp: &metav1Now,
|
||||
CSIVolumeSnapshotsAttempted: 1,
|
||||
Phase: velerov1api.BackupPhaseFinalizing,
|
||||
}).
|
||||
Result(),
|
||||
backupLocation: defaultBackupLocation,
|
||||
enableCSI: true,
|
||||
expectPhase: velerov1api.BackupPhaseCompleted,
|
||||
expectedCompletedVS: 1,
|
||||
backupOperations: []*itemoperation.BackupOperation{
|
||||
{
|
||||
Spec: itemoperation.BackupOperationSpec{
|
||||
BackupName: "backup-3",
|
||||
BackupUID: "foo",
|
||||
BackupItemAction: "foo",
|
||||
ResourceIdentifier: velero.ResourceIdentifier{
|
||||
GroupResource: kuberesource.VolumeSnapshots,
|
||||
Namespace: "ns-1",
|
||||
Name: "vs-1",
|
||||
},
|
||||
PostOperationItems: []velero.ResourceIdentifier{
|
||||
{
|
||||
GroupResource: kuberesource.Secrets,
|
||||
Namespace: "ns-1",
|
||||
Name: "secret-1",
|
||||
},
|
||||
},
|
||||
OperationID: "operation-3",
|
||||
},
|
||||
Status: itemoperation.OperationStatus{
|
||||
Phase: itemoperation.OperationPhaseCompleted,
|
||||
Created: &metav1Now,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
@@ -160,6 +207,11 @@ func TestBackupFinalizerReconcile(t *testing.T) {
|
||||
initObjs = append(initObjs, test.backupLocation)
|
||||
}
|
||||
|
||||
if test.enableCSI {
|
||||
features.Enable(velerov1api.CSIFeatureFlag)
|
||||
defer features.Enable()
|
||||
}
|
||||
|
||||
fakeClient := velerotest.NewFakeControllerRuntimeClient(t, initObjs...)
|
||||
|
||||
fakeGlobalClient := velerotest.NewFakeControllerRuntimeClient(t, initObjs...)
|
||||
@@ -184,6 +236,7 @@ func TestBackupFinalizerReconcile(t *testing.T) {
|
||||
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, test.expectPhase, backupAfter.Status.Phase)
|
||||
assert.Equal(t, test.expectedCompletedVS, backupAfter.Status.CSIVolumeSnapshotsCompleted)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user