Merge pull request #1041 from ncdc/0.9/fix-pv-not-found-check

[0.9] Fix check for non-found PV
This commit is contained in:
Steve Kriss
2018-11-08 09:21:29 -07:00
committed by GitHub
2 changed files with 7 additions and 9 deletions

View File

@@ -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
}
}

View File

@@ -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()