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

Fix check for non-found PV
This commit is contained in:
Steve Kriss
2018-11-08 09:19:15 -07:00
committed by GitHub
2 changed files with 6 additions and 8 deletions
+5 -6
View File
@@ -696,14 +696,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. Just skip the volume restore logic.
if pv == nil {
if apierrors.IsNotFound(err) {
// restore the PV from snapshot (if applicable)
updatedObj, err := ctx.pvRestorer.executePVAction(obj)
if err != nil {
@@ -729,6 +725,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
}
}
+1 -2
View File
@@ -1007,8 +1007,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()