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:
Xun Jiang
2023-12-06 18:27:42 +08:00
parent 8d8d68d649
commit edb0860dd2
6 changed files with 105 additions and 21 deletions

View File

@@ -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)
})
}
}