From 5424b07bb325f6bc17480cd3a306bacaa019f03b Mon Sep 17 00:00:00 2001 From: Anshul Ahuja Date: Mon, 3 Jul 2023 13:48:24 +0530 Subject: [PATCH] restore flow changes Signed-off-by: Anshul Ahuja --- pkg/restore/request.go | 2 ++ pkg/restore/restore.go | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/pkg/restore/request.go b/pkg/restore/request.go index 01ebf3f84..8f49395c8 100644 --- a/pkg/restore/request.go +++ b/pkg/restore/request.go @@ -24,6 +24,7 @@ import ( "github.com/sirupsen/logrus" "k8s.io/apimachinery/pkg/runtime" + "github.com/vmware-tanzu/velero/internal/resourcemodifiers" velerov1api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1" "github.com/vmware-tanzu/velero/pkg/itemoperation" "github.com/vmware-tanzu/velero/pkg/volume" @@ -57,6 +58,7 @@ type Request struct { BackupReader io.Reader RestoredItems map[itemKey]restoredItemStatus itemOperationsList *[]*itemoperation.RestoreOperation + ResourceModifiers *resourcemodifiers.ResourceModifiers } type restoredItemStatus struct { diff --git a/pkg/restore/restore.go b/pkg/restore/restore.go index 1288f69f8..22bf860ae 100644 --- a/pkg/restore/restore.go +++ b/pkg/restore/restore.go @@ -48,6 +48,7 @@ import ( "github.com/vmware-tanzu/velero/internal/credentials" "github.com/vmware-tanzu/velero/internal/hook" + "github.com/vmware-tanzu/velero/internal/resourcemodifiers" velerov1api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1" "github.com/vmware-tanzu/velero/pkg/archive" "github.com/vmware-tanzu/velero/pkg/client" @@ -305,6 +306,7 @@ func (kr *kubernetesRestorer) RestoreWithResolvers( hooksCancelFunc: hooksCancelFunc, kbClient: kr.kbClient, itemOperationsList: req.GetItemOperationsList(), + resourceModifiers: req.ResourceModifiers, } return restoreCtx.execute() @@ -350,6 +352,7 @@ type restoreContext struct { hooksCancelFunc go_context.CancelFunc kbClient crclient.Client itemOperationsList *[]*itemoperation.RestoreOperation + resourceModifiers *resourcemodifiers.ResourceModifiers } type resourceClientKey struct { @@ -1340,6 +1343,12 @@ func (ctx *restoreContext) restoreItem(obj *unstructured.Unstructured, groupReso // and which backup they came from. addRestoreLabels(obj, ctx.restore.Name, ctx.restore.Spec.BackupName) + if ctx.resourceModifiers != nil { + if err := ctx.resourceModifiers.ApplyResourceModifierRules(obj, ctx.log); err != nil { + errs.Add(namespace, err) + } + } + ctx.log.Infof("Attempting to restore %s: %v", obj.GroupVersionKind().Kind, name) createdObj, restoreErr := resourceClient.Create(obj) if restoreErr == nil {