mirror of
https://github.com/vmware-tanzu/velero.git
synced 2026-08-28 03:46:14 +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>
196 lines
5.9 KiB
Go
196 lines
5.9 KiB
Go
/*
|
|
Copyright 2019 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 (
|
|
"time"
|
|
|
|
corev1api "k8s.io/api/core/v1"
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
|
|
velerov1api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
|
|
)
|
|
|
|
// RestoreBuilder builds Restore objects.
|
|
type RestoreBuilder struct {
|
|
object *velerov1api.Restore
|
|
}
|
|
|
|
// ForRestore is the constructor for a RestoreBuilder.
|
|
func ForRestore(ns, name string) *RestoreBuilder {
|
|
return &RestoreBuilder{
|
|
object: &velerov1api.Restore{
|
|
TypeMeta: metav1.TypeMeta{
|
|
APIVersion: velerov1api.SchemeGroupVersion.String(),
|
|
Kind: "Restore",
|
|
},
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
Namespace: ns,
|
|
Name: name,
|
|
},
|
|
},
|
|
}
|
|
}
|
|
|
|
// Result returns the built Restore.
|
|
func (b *RestoreBuilder) Result() *velerov1api.Restore {
|
|
return b.object
|
|
}
|
|
|
|
// ObjectMeta applies functional options to the Restore's ObjectMeta.
|
|
func (b *RestoreBuilder) ObjectMeta(opts ...ObjectMetaOpt) *RestoreBuilder {
|
|
for _, opt := range opts {
|
|
opt(b.object)
|
|
}
|
|
|
|
return b
|
|
}
|
|
|
|
// Backup sets the Restore's backup name.
|
|
func (b *RestoreBuilder) Backup(name string) *RestoreBuilder {
|
|
b.object.Spec.BackupName = name
|
|
return b
|
|
}
|
|
|
|
// Schedule sets the Restore's schedule name.
|
|
func (b *RestoreBuilder) Schedule(name string) *RestoreBuilder {
|
|
b.object.Spec.ScheduleName = name
|
|
return b
|
|
}
|
|
|
|
// IncludedNamespaces appends to the Restore's included namespaces.
|
|
func (b *RestoreBuilder) IncludedNamespaces(namespaces ...string) *RestoreBuilder {
|
|
b.object.Spec.IncludedNamespaces = append(b.object.Spec.IncludedNamespaces, namespaces...)
|
|
return b
|
|
}
|
|
|
|
// ExcludedNamespaces appends to the Restore's excluded namespaces.
|
|
func (b *RestoreBuilder) ExcludedNamespaces(namespaces ...string) *RestoreBuilder {
|
|
b.object.Spec.ExcludedNamespaces = append(b.object.Spec.ExcludedNamespaces, namespaces...)
|
|
return b
|
|
}
|
|
|
|
// IncludedResources appends to the Restore's included resources.
|
|
func (b *RestoreBuilder) IncludedResources(resources ...string) *RestoreBuilder {
|
|
b.object.Spec.IncludedResources = append(b.object.Spec.IncludedResources, resources...)
|
|
return b
|
|
}
|
|
|
|
// ExcludedResources appends to the Restore's excluded resources.
|
|
func (b *RestoreBuilder) ExcludedResources(resources ...string) *RestoreBuilder {
|
|
b.object.Spec.ExcludedResources = append(b.object.Spec.ExcludedResources, resources...)
|
|
return b
|
|
}
|
|
|
|
// ExistingResourcePolicy sets the Restore's resource policy.
|
|
func (b *RestoreBuilder) ExistingResourcePolicy(policy string) *RestoreBuilder {
|
|
b.object.Spec.ExistingResourcePolicy = velerov1api.ResourcePolicyType(policy)
|
|
return b
|
|
}
|
|
|
|
// ExistingVolumeDataPolicy sets the Restore's volume data policy.
|
|
func (b *RestoreBuilder) ExistingVolumeDataPolicy(policy string) *RestoreBuilder {
|
|
b.object.Spec.ExistingVolumeDataPolicy = velerov1api.VolumeDataPolicyType(policy)
|
|
return b
|
|
}
|
|
|
|
// IncludeClusterResources sets the Restore's "include cluster resources" flag.
|
|
func (b *RestoreBuilder) IncludeClusterResources(val bool) *RestoreBuilder {
|
|
b.object.Spec.IncludeClusterResources = &val
|
|
return b
|
|
}
|
|
|
|
// LabelSelector sets the Restore's label selector.
|
|
func (b *RestoreBuilder) LabelSelector(selector *metav1.LabelSelector) *RestoreBuilder {
|
|
b.object.Spec.LabelSelector = selector
|
|
return b
|
|
}
|
|
|
|
// OrLabelSelector sets the Restore's orLabelSelector set.
|
|
func (b *RestoreBuilder) OrLabelSelector(orSelectors []*metav1.LabelSelector) *RestoreBuilder {
|
|
b.object.Spec.OrLabelSelectors = orSelectors
|
|
return b
|
|
}
|
|
|
|
// NamespaceMappings sets the Restore's namespace mappings.
|
|
func (b *RestoreBuilder) NamespaceMappings(mapping ...string) *RestoreBuilder {
|
|
if b.object.Spec.NamespaceMapping == nil {
|
|
b.object.Spec.NamespaceMapping = make(map[string]string)
|
|
}
|
|
|
|
if len(mapping)%2 != 0 {
|
|
panic("mapping must contain an even number of values")
|
|
}
|
|
|
|
for i := 0; i < len(mapping); i += 2 {
|
|
b.object.Spec.NamespaceMapping[mapping[i]] = mapping[i+1]
|
|
}
|
|
|
|
return b
|
|
}
|
|
|
|
// Phase sets the Restore's phase.
|
|
func (b *RestoreBuilder) Phase(phase velerov1api.RestorePhase) *RestoreBuilder {
|
|
b.object.Status.Phase = phase
|
|
return b
|
|
}
|
|
|
|
// RestorePVs sets the Restore's restore PVs.
|
|
func (b *RestoreBuilder) RestorePVs(val bool) *RestoreBuilder {
|
|
b.object.Spec.RestorePVs = &val
|
|
return b
|
|
}
|
|
|
|
// PreserveNodePorts sets the Restore's preserved NodePorts.
|
|
func (b *RestoreBuilder) PreserveNodePorts(val bool) *RestoreBuilder {
|
|
b.object.Spec.PreserveNodePorts = &val
|
|
return b
|
|
}
|
|
|
|
// StartTimestamp sets the Restore's start timestamp.
|
|
func (b *RestoreBuilder) StartTimestamp(val time.Time) *RestoreBuilder {
|
|
b.object.Status.StartTimestamp = &metav1.Time{Time: val}
|
|
return b
|
|
}
|
|
|
|
// CompletionTimestamp sets the Restore's completion timestamp.
|
|
func (b *RestoreBuilder) CompletionTimestamp(val time.Time) *RestoreBuilder {
|
|
b.object.Status.CompletionTimestamp = &metav1.Time{Time: val}
|
|
return b
|
|
}
|
|
|
|
// ItemOperationTimeout sets the Restore's ItemOperationTimeout
|
|
func (b *RestoreBuilder) ItemOperationTimeout(timeout time.Duration) *RestoreBuilder {
|
|
b.object.Spec.ItemOperationTimeout.Duration = timeout
|
|
return b
|
|
}
|
|
|
|
// ResourcePoliciesConfigmap sets the Restore's resource policies configmap.
|
|
func (b *RestoreBuilder) ResourcePoliciesConfigmap(name string) *RestoreBuilder {
|
|
b.object.Spec.ResourcePolicy = &corev1api.TypedLocalObjectReference{
|
|
Kind: "configmap",
|
|
Name: name,
|
|
}
|
|
return b
|
|
}
|
|
|
|
// SkipDefaultResourceModifier sets whether to skip the server default resource modifier.
|
|
func (b *RestoreBuilder) SkipDefaultResourceModifier(val bool) *RestoreBuilder {
|
|
b.object.Spec.SkipDefaultResourceModifier = &val
|
|
return b
|
|
}
|