diff --git a/pkg/restore/restore.go b/pkg/restore/restore.go index 23261b137..077753391 100644 --- a/pkg/restore/restore.go +++ b/pkg/restore/restore.go @@ -676,14 +676,10 @@ func (ctx *context) restoreResource(resource, namespace, resourcePath string) (a // Check if the PV exists in the cluster before attempting to create // a volume from the snapshot, in order to avoid orphaned volumes (GH #609) - pv, err := resourceClient.Get(name, metav1.GetOptions{}) - if err != nil && !apierrors.IsNotFound(err) { - addToResult(&errs, namespace, fmt.Errorf("error checking existence for PV %s: %v", name, err)) - continue - } + _, err = resourceClient.Get(name, metav1.GetOptions{}) - // PV's existence will be recorded later. Jest skip volume restore logic - if pv == nil { + // PV's existence will be recorded later. Just skip volume restore logic + if apierrors.IsNotFound(err) { // restore the PV from snapshot (if applicable) updatedObj, err := ctx.pvRestorer.executePVAction(obj) if err != nil { @@ -709,6 +705,9 @@ func (ctx *context) restoreResource(resource, namespace, resourcePath string) (a } }() } + } else if err != nil { + addToResult(&errs, namespace, fmt.Errorf("error checking existence for PV %s: %v", name, err)) + continue } } diff --git a/pkg/restore/restore_test.go b/pkg/restore/restore_test.go index eeca69fea..eca8de901 100644 --- a/pkg/restore/restore_test.go +++ b/pkg/restore/restore_test.go @@ -921,8 +921,7 @@ status: } // Only set up the client expectation if the test has the proper prerequisites if test.haveSnapshot || test.reclaimPolicy != "Delete" { - var empty *unstructured.Unstructured - pvClient.On("Get", mock.Anything, metav1.GetOptions{}).Return(empty, nil) + pvClient.On("Get", unstructuredPV.GetName(), metav1.GetOptions{}).Return(&unstructured.Unstructured{}, k8serrors.NewNotFound(schema.GroupResource{Resource: "persistentvolumes"}, unstructuredPV.GetName())) } pvToRestore := unstructuredPV.DeepCopy()