mirror of
https://github.com/vmware-tanzu/velero.git
synced 2026-08-27 19:36:19 +00:00
* Update CRDs and CLI to support in-place restore (#10038) Update CRDs(Restore, DataDownload, PodVolumeRestore) and restore create CLI to support in-place restore Signed-off-by: Wenkai Yin(尹文开) <yinw@vmware.com> * Update Kopia(filesystem) uploader to support incremental and deleteExtraFile during restore (#10066) Update Kopia(filesystem) uploader to support incremental and deleteExtraFile during restore Signed-off-by: Wenkai Yin(尹文开) <yinw@vmware.com> * Update Restore Exposer and PVC CSI to support in-place restore (#10104) 1. Update Restore Exposer to support exposing with existing PV for in-place restore 2. Update PVC CSI RIA to continue the restore process for in-place restore Signed-off-by: Wenkai Yin(尹文开) <yinw@vmware.com> * Update Block uploader to support increase restore (#10244) Update Block uploader to support increase restore Signed-off-by: Wenkai Yin(尹文开) <yinw@vmware.com> * Update Exposer to recreate the target PV if the volume mode is different with the restore PVC (#10257) Update Exposer to recreate the target PV if the volume mode is different with t he restore PVC Signed-off-by: Wenkai Yin(尹文开) <yinw@vmware.com> * Preserve PVC selected-node annotation via carrier annotation for in-place restore For in-place volume data restore, the existing PVC is deleted and recreated. For StorageClasses with the WaitForFirstConsumer volume binding mode, losing the volume.kubernetes.io/selected-node annotation could let the scheduler place the recreated workload Pod in a different zone than the original PV, leaving it stuck in ContainerCreating. Instead of relying on RestoreItemAction execution order (the generic PVC RIA unconditionally strips the selected-node annotation), the PVC CSI RIA now captures the annotation from the existing PVC right before deleting it and carries it on the target PVC via the Velero-internal restore.velero.io/inplace-restore-selected-node annotation. The restore engine translates the carrier back to the Kubernetes annotation after all RestoreItemActions have run and always strips the carrier so it never lands on the cluster. This makes the behavior independent of RIA ordering: the Kubernetes annotation is stripped by default on every path (including when the target PVC does not exist and Velero falls back to provisioning a new PVC), and preservation only happens when the CSI RIA explicitly captured a value from the existing PVC. Signed-off-by: chlins <chlins.zhang@gmail.com> * Update the control path to make the in-place incremental restore with block data mover work E2E (#10410) Update the control path to make the in-place incremental restore with block data mover work E2E Signed-off-by: Wenkai Yin(尹文开) <yinw@vmware.com> --------- Signed-off-by: Wenkai Yin(尹文开) <yinw@vmware.com> Signed-off-by: chlins <chlins.zhang@gmail.com> Co-authored-by: chlins <chlins.zhang@gmail.com>
214 lines
6.0 KiB
Go
214 lines
6.0 KiB
Go
/*
|
|
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 datapath
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/cockroachdb/errors"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/mock"
|
|
"github.com/stretchr/testify/require"
|
|
"k8s.io/utils/ptr"
|
|
|
|
velerotest "github.com/vmware-tanzu/velero/pkg/test"
|
|
"github.com/vmware-tanzu/velero/pkg/uploader/provider"
|
|
providerMock "github.com/vmware-tanzu/velero/pkg/uploader/provider/mocks"
|
|
)
|
|
|
|
func TestAsyncBackup(t *testing.T) {
|
|
var asyncErr error
|
|
var asyncResult Result
|
|
finish := make(chan struct{})
|
|
var failErr = errors.New("fake-fail-error")
|
|
tests := []struct {
|
|
name string
|
|
uploaderProv provider.Provider
|
|
callbacks Callbacks
|
|
err error
|
|
result Result
|
|
path string
|
|
}{
|
|
{
|
|
name: "async backup fail",
|
|
callbacks: Callbacks{
|
|
OnCompleted: nil,
|
|
OnCancelled: nil,
|
|
OnFailed: func(ctx context.Context, namespace string, job string, err error) {
|
|
asyncErr = failErr
|
|
asyncResult = Result{}
|
|
finish <- struct{}{}
|
|
},
|
|
},
|
|
err: failErr,
|
|
},
|
|
{
|
|
name: "async backup cancel",
|
|
callbacks: Callbacks{
|
|
OnCompleted: nil,
|
|
OnFailed: nil,
|
|
OnCancelled: func(ctx context.Context, namespace string, job string) {
|
|
asyncErr = provider.ErrorCanceled
|
|
asyncResult = Result{}
|
|
finish <- struct{}{}
|
|
},
|
|
},
|
|
err: provider.ErrorCanceled,
|
|
},
|
|
{
|
|
name: "async backup complete",
|
|
callbacks: Callbacks{
|
|
OnFailed: nil,
|
|
OnCancelled: nil,
|
|
OnCompleted: func(ctx context.Context, namespace string, job string, result Result) {
|
|
asyncResult = result
|
|
asyncErr = nil
|
|
finish <- struct{}{}
|
|
},
|
|
},
|
|
result: Result{
|
|
Backup: BackupResult{
|
|
SnapshotID: "fake-snapshot",
|
|
EmptySnapshot: false,
|
|
Source: AccessPoint{ByPath: "fake-path"},
|
|
TotalBytes: 1000,
|
|
IncrementalBytes: ptr.To(int64(0)),
|
|
},
|
|
},
|
|
path: "fake-path",
|
|
},
|
|
}
|
|
|
|
for _, test := range tests {
|
|
t.Run(test.name, func(t *testing.T) {
|
|
dp := newGeneralDataPath("job-1", "test", nil, "velero", Callbacks{}, velerotest.NewLogger()).(*generalDataPath)
|
|
mockProvider := providerMock.NewProvider(t)
|
|
var incrementalBytes int64
|
|
if test.result.Backup.IncrementalBytes != nil {
|
|
incrementalBytes = *test.result.Backup.IncrementalBytes
|
|
}
|
|
mockProvider.On("RunBackup", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(test.result.Backup.SnapshotID, test.result.Backup.EmptySnapshot, test.result.Backup.TotalBytes, incrementalBytes, test.err)
|
|
mockProvider.On("Close", mock.Anything).Return(nil)
|
|
dp.uploaderProv = mockProvider
|
|
dp.initialized = true
|
|
dp.callbacks = test.callbacks
|
|
|
|
err := dp.StartBackup(AccessPoint{ByPath: test.path}, map[string]string{}, &BackupStartParam{})
|
|
require.NoError(t, err)
|
|
|
|
<-finish
|
|
|
|
// Ensure the goroutine finishes so deferred fs.close executes, satisfying mock expectations.
|
|
dp.wgDataPath.Wait()
|
|
|
|
assert.Equal(t, test.err, asyncErr)
|
|
assert.Equal(t, test.result, asyncResult)
|
|
})
|
|
}
|
|
|
|
close(finish)
|
|
}
|
|
|
|
func TestAsyncRestore(t *testing.T) {
|
|
var asyncErr error
|
|
var asyncResult Result
|
|
finish := make(chan struct{})
|
|
var failErr = errors.New("fake-fail-error")
|
|
tests := []struct {
|
|
name string
|
|
uploaderProv provider.Provider
|
|
callbacks Callbacks
|
|
err error
|
|
result Result
|
|
path string
|
|
snapshot string
|
|
}{
|
|
{
|
|
name: "async restore fail",
|
|
callbacks: Callbacks{
|
|
OnCompleted: nil,
|
|
OnCancelled: nil,
|
|
OnFailed: func(ctx context.Context, namespace string, job string, err error) {
|
|
asyncErr = failErr
|
|
asyncResult = Result{}
|
|
finish <- struct{}{}
|
|
},
|
|
},
|
|
err: failErr,
|
|
},
|
|
{
|
|
name: "async restore cancel",
|
|
callbacks: Callbacks{
|
|
OnCompleted: nil,
|
|
OnFailed: nil,
|
|
OnCancelled: func(ctx context.Context, namespace string, job string) {
|
|
asyncErr = provider.ErrorCanceled
|
|
asyncResult = Result{}
|
|
finish <- struct{}{}
|
|
},
|
|
},
|
|
err: provider.ErrorCanceled,
|
|
},
|
|
{
|
|
name: "async restore complete",
|
|
callbacks: Callbacks{
|
|
OnFailed: nil,
|
|
OnCancelled: nil,
|
|
OnCompleted: func(ctx context.Context, namespace string, job string, result Result) {
|
|
asyncResult = result
|
|
asyncErr = nil
|
|
finish <- struct{}{}
|
|
},
|
|
},
|
|
result: Result{
|
|
Restore: RestoreResult{
|
|
Target: AccessPoint{ByPath: "fake-path"},
|
|
TotalBytes: 1000,
|
|
},
|
|
},
|
|
path: "fake-path",
|
|
snapshot: "fake-snapshot",
|
|
},
|
|
}
|
|
|
|
for _, test := range tests {
|
|
t.Run(test.name, func(t *testing.T) {
|
|
dp := newGeneralDataPath("job-1", "test", nil, "velero", Callbacks{}, velerotest.NewLogger()).(*generalDataPath)
|
|
mockProvider := providerMock.NewProvider(t)
|
|
mockProvider.On("RunRestore", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(test.result.Restore.TotalBytes, test.err)
|
|
mockProvider.On("Close", mock.Anything).Return(nil)
|
|
dp.uploaderProv = mockProvider
|
|
dp.initialized = true
|
|
dp.callbacks = test.callbacks
|
|
|
|
err := dp.StartRestore(test.snapshot, AccessPoint{ByPath: test.path}, map[string]string{}, &RestoreStartParam{})
|
|
require.NoError(t, err)
|
|
|
|
<-finish
|
|
|
|
// Ensure the goroutine finishes so deferred fs.close executes, satisfying mock expectations.
|
|
dp.wgDataPath.Wait()
|
|
|
|
assert.Equal(t, asyncErr, test.err)
|
|
assert.Equal(t, asyncResult, test.result)
|
|
})
|
|
}
|
|
|
|
close(finish)
|
|
}
|