fix nilpointer panic when decode addlitional item failed
Signed-off-by: 司司 <suyashi.sys@alibaba-inc.com>pull/8563/head
parent
78c97d93b5
commit
b9525af464
|
@ -1388,6 +1388,7 @@ func (ctx *restoreContext) restoreItem(obj *unstructured.Unstructured, groupReso
|
|||
additionalObj, err := archive.Unmarshal(ctx.fileSystem, itemPath)
|
||||
if err != nil {
|
||||
errs.Add(namespace, errors.Wrapf(err, "error restoring additional item %s", additionalResourceID))
|
||||
continue
|
||||
}
|
||||
|
||||
additionalItemNamespace := additionalItem.Namespace
|
||||
|
|
|
@ -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": {"error restoring 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)
|
||||
|
|
Loading…
Reference in New Issue