From 061b4463ce3cdef48b3454860a26e45d1a2aa1c1 Mon Sep 17 00:00:00 2001 From: Ashish Amarnath Date: Fri, 3 Apr 2020 07:57:01 -0700 Subject: [PATCH] ensure target namespace exists prior to retoring a resource (#2389) Signed-off-by: Ashish Amarnath --- pkg/restore/restore.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pkg/restore/restore.go b/pkg/restore/restore.go index 6890c9924..4c45b6730 100644 --- a/pkg/restore/restore.go +++ b/pkg/restore/restore.go @@ -798,6 +798,15 @@ func (ctx *context) restoreItem(obj *unstructured.Unstructured, groupResource sc }).Info("Not restoring item because namespace is excluded") return warnings, errs } + + // if the namespace scoped resource should be restored, ensure that the namespace into + // which the resource is being restored into exists. + // This is the *remapped* namespace that we are ensuring exists. + nsToEnsure := getNamespace(ctx.log, getItemFilePath(ctx.restoreDir, "namespaces", "", obj.GetNamespace()), namespace) + if _, err := kube.EnsureNamespaceExistsAndIsReady(nsToEnsure, ctx.namespaceClient, ctx.resourceTerminatingTimeout); err != nil { + errs.AddVeleroError(err) + return warnings, errs + } } else { if boolptr.IsSetToFalse(ctx.restore.Spec.IncludeClusterResources) { ctx.log.WithFields(logrus.Fields{