Cherry pick the in-place restore implementation PRs from feature branch to main (#10415)

* 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>
This commit is contained in:
Wenkai Yin(尹文开)
2026-08-26 10:21:32 -04:00
committed by GitHub
co-authored by chlins
parent ac5744c7b4
commit b7d83a6f2b
54 changed files with 2164 additions and 335 deletions
+11
View File
@@ -174,6 +174,17 @@ const (
// Notice: SkipRestore on the Execute output takes precedence. If SkipRestore is true, the
// annotation is never inspected and AdditionalItems are not processed.
MustIncludeAdditionalItemRestoreAnnotation = "restore.velero.io/must-include-additional-items"
// InplaceRestoreSelectedNodeAnnotation is a Velero-internal carrier annotation set by the
// PVC CSI RestoreItemAction during an in-place volume data restore. It carries the
// "volume.kubernetes.io/selected-node" value captured from the existing PVC right before
// that PVC is deleted, so the restore engine can re-apply it to the recreated target PVC
// after all RestoreItemActions have run. This keeps the recreated PVC (and the workload
// Pod, for WaitForFirstConsumer StorageClasses) scheduled to the original node/zone.
// The annotation is always translated and stripped by the restore engine; it never lands
// on the cluster. Using a carrier annotation avoids any dependency on the execution order
// of RestoreItemActions.
InplaceRestoreSelectedNodeAnnotation = "restore.velero.io/inplace-restore-selected-node"
// SkippedNoCSIPVAnnotation - Velero checks this annotation on processed PVC to
// find out if the snapshot was skipped b/c the PV is not provisioned via CSI
SkippedNoCSIPVAnnotation = "backup.velero.io/skipped-no-csi-pv"
@@ -46,6 +46,9 @@ type PodVolumeRestoreSpec struct {
// SnapshotID is the ID of the volume snapshot to be restored.
SnapshotID string `json:"snapshotID"`
// RestoreType indicates the type of the restore.
RestoreType string `json:"restoreType"`
// SourceNamespace is the original namespace for namaspace mapping.
SourceNamespace string `json:"sourceNamespace"`
+41 -7
View File
@@ -113,7 +113,12 @@ type RestoreSpec struct {
// ExistingResourcePolicy specifies the restore behavior for the Kubernetes resource to be restored
// +optional
// +nullable
ExistingResourcePolicy PolicyType `json:"existingResourcePolicy,omitempty"`
ExistingResourcePolicy ResourcePolicyType `json:"existingResourcePolicy,omitempty"`
// ExistingVolumeDataPolicy specifies the restore behavior for the volume data to be restored
// +optional
// +nullable
ExistingVolumeDataPolicy VolumeDataPolicyType `json:"existingVolumeDataPolicy,omitempty"`
// ItemOperationTimeout specifies the time used to wait for RestoreItemAction operations
// The default value is 4 hour.
@@ -158,6 +163,11 @@ type UploaderConfigForRestore struct {
// ParallelFilesDownload is the concurrency number setting for restore.
// +optional
ParallelFilesDownload int `json:"parallelFilesDownload,omitempty"`
// DeleteExtraFiles specifies whether to delete the extra files in the target volume that do not exist in the backup.
// This setting is only applicable to File System restores (PodVolumeBackup or CSI File System Data Move) and has no effect on Block Data Move restores.
// +optional
// +nullable
DeleteExtraFiles *bool `json:"deleteExtraFiles,omitempty"`
}
// RestoreHooks contains custom behaviors that should be executed during or post restore.
@@ -324,13 +334,22 @@ const (
// The failing error is recorded in status.FailureReason.
RestorePhaseFailed RestorePhase = "Failed"
// PolicyTypeNone means velero will not overwrite the resource
// ResourcePolicyTypeNone means velero will not overwrite the resource
// in cluster with the one in backup whether changed/unchanged.
PolicyTypeNone PolicyType = "none"
ResourcePolicyTypeNone ResourcePolicyType = "none"
// PolicyTypeUpdate means velero will try to attempt a patch on
// ResourcePolicyTypeUpdate means velero will try to attempt a patch on
// the changed resources.
PolicyTypeUpdate PolicyType = "update"
ResourcePolicyTypeUpdate ResourcePolicyType = "update"
// VolumeDataPolicyTypeNone means velero will skip and not overwrite the volume data if the volume already exists
VolumeDataPolicyTypeNone VolumeDataPolicyType = "none"
// VolumeDataPolicyTypeFull means velero will try to restore the volume data fully if the volume already exists.
VolumeDataPolicyTypeFull VolumeDataPolicyType = "full"
// VolumeDataPolicyTypeIncremental means velero will try to restore the volume data incrementally if the volume already exists.
VolumeDataPolicyTypeIncremental VolumeDataPolicyType = "incremental"
)
// RestoreStatus captures the current status of a Velero restore
@@ -441,6 +460,18 @@ type Restore struct {
Status RestoreStatus `json:"status,omitempty"`
}
func (r *Restore) IsVolumeDataInplaceRestore() bool {
return r.Spec.ExistingVolumeDataPolicy == VolumeDataPolicyTypeFull || r.Spec.ExistingVolumeDataPolicy == VolumeDataPolicyTypeIncremental
}
func (r *Restore) IsVolumeDataInplaceFullRestore() bool {
return r.Spec.ExistingVolumeDataPolicy == VolumeDataPolicyTypeFull
}
func (r *Restore) IsVolumeDataInplaceIncrementalRestore() bool {
return r.Spec.ExistingVolumeDataPolicy == VolumeDataPolicyTypeIncremental
}
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// RestoreList is a list of Restores.
@@ -453,5 +484,8 @@ type RestoreList struct {
Items []Restore `json:"items"`
}
// PolicyType helps specify the ExistingResourcePolicy
type PolicyType string
// ResourcePolicyType helps specify the ExistingResourcePolicy
type ResourcePolicyType string
// VolumeDataPolicyType helps specify the ExistingVolumeDataPolicy
type VolumeDataPolicyType string
+69
View File
@@ -0,0 +1,69 @@
/*
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 v1
import (
"testing"
)
func TestIsVolumeDataInplaceRestore(t *testing.T) {
tests := []struct {
name string
existingVolumeDataPolicy VolumeDataPolicyType
expected bool
}{
{
name: "empty policy",
existingVolumeDataPolicy: "",
expected: false,
},
{
name: "none policy",
existingVolumeDataPolicy: VolumeDataPolicyTypeNone,
expected: false,
},
{
name: "full policy",
existingVolumeDataPolicy: VolumeDataPolicyTypeFull,
expected: true,
},
{
name: "incremental policy",
existingVolumeDataPolicy: VolumeDataPolicyTypeIncremental,
expected: true,
},
{
name: "unknown policy",
existingVolumeDataPolicy: VolumeDataPolicyType("unknown"),
expected: false,
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
restore := &Restore{
Spec: RestoreSpec{
ExistingVolumeDataPolicy: tc.existingVolumeDataPolicy,
},
}
actual := restore.IsVolumeDataInplaceRestore()
if actual != tc.expected {
t.Errorf("expected %v, got %v", tc.expected, actual)
}
})
}
}
@@ -1771,6 +1771,11 @@ func (in *UploaderConfigForRestore) DeepCopyInto(out *UploaderConfigForRestore)
*out = new(bool)
**out = **in
}
if in.DeleteExtraFiles != nil {
in, out := &in.DeleteExtraFiles, &out.DeleteExtraFiles
*out = new(bool)
**out = **in
}
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new UploaderConfigForRestore.
@@ -39,6 +39,14 @@ type DataDownloadSpec struct {
// SnapshotID is the ID of the Velero backup snapshot to be restored from.
SnapshotID string `json:"snapshotID"`
// RestoreType indicates the type of the restore.
RestoreType string `json:"restoreType"`
// CSISnapshot provides the information of the CSI snapshot used to do the incremental restore.
// +optional
// +nullable
CSISnapshot *CSISnapshotSpec `json:"csiSnapshot"`
// SourceNamespace is the original namespace where the volume is backed up from.
// It may be different from SourcePVC's namespace if namespace is remapped during restore.
SourceNamespace string `json:"sourceNamespace"`
@@ -80,6 +80,10 @@ const (
// CSISnapshotSpec is the specification for a CSI snapshot.
type CSISnapshotSpec struct {
// VolumeSnapshotNamespace is the namespece of the volume snapshot to be backed up
// +optional
VolumeSnapshotNamespace string `json:"volumeSnapshotNamespace"`
// VolumeSnapshot is the name of the volume snapshot to be backed up
VolumeSnapshot string `json:"volumeSnapshot"`
@@ -86,6 +86,11 @@ func (in *DataDownloadList) DeepCopyObject() runtime.Object {
func (in *DataDownloadSpec) DeepCopyInto(out *DataDownloadSpec) {
*out = *in
out.TargetVolume = in.TargetVolume
if in.CSISnapshot != nil {
in, out := &in.CSISnapshot, &out.CSISnapshot
*out = new(CSISnapshotSpec)
**out = **in
}
if in.DataMoverConfig != nil {
in, out := &in.DataMoverConfig, &out.DataMoverConfig
*out = make(map[string]string, len(*in))