Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix nilpointer panic when decode addlitional item failed in restore #8563

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion pkg/restore/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
AlbeeSo marked this conversation as resolved.
Show resolved Hide resolved
}

additionalItemNamespace := additionalItem.Namespace
Expand Down
38 changes: 36 additions & 2 deletions pkg/restore/restore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
Expand Down
Loading