diff --git a/pkg/restore/restore.go b/pkg/restore/restore.go index c77997132..3c30e4cd2 100644 --- a/pkg/restore/restore.go +++ b/pkg/restore/restore.go @@ -1955,6 +1955,11 @@ func hasCSIVolumeSnapshot(ctx *restoreContext, unstructuredPV *unstructured.Unst } for _, vs := range ctx.csiVolumeSnapshots { + // In some error cases, the VSs' source PVC could be nil. Skip them. + if vs.Spec.Source.PersistentVolumeClaimName == nil { + continue + } + if pv.Spec.ClaimRef.Name == *vs.Spec.Source.PersistentVolumeClaimName && pv.Spec.ClaimRef.Namespace == vs.Namespace { return true diff --git a/pkg/restore/restore_test.go b/pkg/restore/restore_test.go index 33b6d4a2e..efca33870 100644 --- a/pkg/restore/restore_test.go +++ b/pkg/restore/restore_test.go @@ -4044,6 +4044,21 @@ func TestHasCSIVolumeSnapshot(t *testing.T) { }, expectedResult: false, }, + { + name: "VS's source PVC is nil, expect false", + obj: &unstructured.Unstructured{ + Object: map[string]interface{}{ + "kind": "PersistentVolume", + "apiVersion": "v1", + "metadata": map[string]interface{}{ + "namespace": "default", + "name": "test", + }, + }, + }, + vs: builder.ForVolumeSnapshot("velero", "test").Result(), + expectedResult: false, + }, { name: "Find VS, expect true.", obj: &unstructured.Unstructured{