diff --git a/pkg/restore/restore.go b/pkg/restore/restore.go index 619db5b87e..d67da67f81 100644 --- a/pkg/restore/restore.go +++ b/pkg/restore/restore.go @@ -1387,7 +1387,14 @@ func (ctx *restoreContext) restoreItem(obj *unstructured.Unstructured, groupReso additionalResourceID := getResourceID(additionalItem.GroupResource, additionalItem.Namespace, additionalItem.Name) additionalObj, err := archive.Unmarshal(ctx.fileSystem, itemPath) if err != nil { - errs.Add(namespace, errors.Wrapf(err, "error restoring additional item %s", additionalResourceID)) + ctx.log.WithError(err).WithFields(logrus.Fields{ + "additionalResource": additionalItem.GroupResource.String(), + "additionalResourceNamespace": additionalItem.Namespace, + "additionalResourceName": additionalItem.Name, + }).Warn("Could not unmarshal additional item") + errs.Add(namespace, errors.Wrapf(err, "Could not unmarshal additional item: %s", additionalResourceID)) + + continue } additionalItemNamespace := additionalItem.Namespace diff --git a/pkg/restore/restore_test.go b/pkg/restore/restore_test.go index f3da852023..1c87d7fb0d 100644 --- a/pkg/restore/restore_test.go +++ b/pkg/restore/restore_test.go @@ -955,6 +955,7 @@ func TestInvalidTarballContents(t *testing.T) { backup *velerov1api.Backup apiResources []*test.APIResource tarball io.Reader + actions []riav2.RestoreItemAction want map[*test.APIResource][]string wantErrs Result wantWarnings Result @@ -991,6 +992,39 @@ func TestInvalidTarballContents(t *testing.T) { }, }, }, + { + name: "invalid JSON for additional item is reported as an error and restore continues", + restore: defaultRestore().IncludedNamespaces("ns-1").Result(), + backup: defaultBackup().Result(), + tarball: test.NewTarWriter(t). + AddItems("pods", builder.ForPod("ns-1", "pod-1").Result()). + Add("resources/persistentvolumes/cluster/pv-1.json", []byte("invalid JSON")). + Done(), + apiResources: []*test.APIResource{ + test.Pods(), + test.PVs(), + }, + actions: []riav2.RestoreItemAction{ + &pluggableAction{ + executeFunc: func(input *velero.RestoreItemActionExecuteInput) (*velero.RestoreItemActionExecuteOutput, error) { + return &velero.RestoreItemActionExecuteOutput{ + UpdatedItem: input.Item, + AdditionalItems: []velero.ResourceIdentifier{ + {GroupResource: kuberesource.PersistentVolumes, Name: "pv-1"}, + }, + }, nil + }, + }, + }, + want: map[*test.APIResource][]string{ + test.Pods(): {"ns-1/pod-1"}, + }, + wantErrs: Result{ + Namespaces: map[string][]string{ + "ns-1": {"Could not unmarshal additional item: persistentvolumes/pv-1"}, + }, + }, + }, } for _, tc := range tests { @@ -1012,8 +1046,8 @@ func TestInvalidTarballContents(t *testing.T) { } warnings, errs := h.restorer.Restore( data, - nil, // restoreItemActions - nil, // volume snapshotter getter + tc.actions, // restoreItemActions + nil, // volume snapshotter getter ) assertWantErrsOrWarnings(t, tc.wantWarnings, warnings) assertWantErrsOrWarnings(t, tc.wantErrs, errs)