Repository: dell/csi-baremetal
Pull request #482 (2021-08-11 07:23:45)

[ISSUE-463] Retry on PVC not found
## Purpose
### Issue #463

We shouldn't proceed with reservation request when some PVC is not found - retry instead. Otherwise _CreateVolume_ request will fail due to reservation not found:

```
[CSIControllerService] [CreateVolume] [pvc-4f3d2131-8819-47ed-a750-c3ce889fa475] Failed to create volume: rpc error: code = NotFound desc = Reservation csi-baremetalgbxtj not found
csi-baremetal-controller-678684b9b4-svlwc/csi-provisioner: I0810 18:49:50.657294       1 connection.go:185] GRPC response: {}
```

## PR checklist
- [x] Add link to the issue
- [x] Choose PR label
- [ ] New unit tests added
- [x] Modified code has meaningful comments
- [ ] All TODOs are linked with the issues
- [ ] All comments are resolved

## Testing
Custom CI failed with csi node pod not running issue. No problems with reservation not found.

codecov[bot]: # [Codecov](https://codecov.io/gh/dell/csi-baremetal/pull/482?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=dell) Report
> Merging [#482](https://codecov.io/gh/dell/csi-baremetal/pull/482?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=dell) (17fb1ee) into [master](https://codecov.io/gh/dell/csi-baremetal/commit/740c92d9d6a2879f20029b70e1763b2758ba9973?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=dell) (740c92d) will **decrease** coverage by `0.00%`.
> The diff coverage is `33.33%`.

> :exclamation: Current head 17fb1ee differs from pull request most recent head c0e020d. Consider uploading reports for the commit c0e020d to get more accurate results
[![Impacted file tree graph](https://codecov.io/gh/dell/csi-baremetal/pull/482/graphs/tree.svg?width=650&height=150&src=pr&token=4D8WVNWX5O&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=dell)](https://codecov.io/gh/dell/csi-baremetal/pull/482?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=dell)

```diff
@@            Coverage Diff             @@
##           master     #482      +/-   ##
==========================================
- Coverage   59.13%   59.12%   -0.01%     
==========================================
  Files          60       60              
  Lines        6003     6004       +1     
==========================================
  Hits         3550     3550              
- Misses       2246     2247       +1     
  Partials      207      207              
```

| Flag | Coverage Δ | |
|---|---|---|
| unittests | `59.12% <33.33%> (-0.01%)` | :arrow_down: |

Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=dell#carryforward-flags-in-the-pull-request-comment) to find out more.

| [Impacted Files](https://codecov.io/gh/dell/csi-baremetal/pull/482?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=dell) | Coverage Δ | |
|---|---|---|
| [pkg/scheduler/extender/extender.go](https://codecov.io/gh/dell/csi-baremetal/pull/482/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=dell#diff-cGtnL3NjaGVkdWxlci9leHRlbmRlci9leHRlbmRlci5nbw==) | `36.01% <33.33%> (-0.12%)` | :arrow_down: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/dell/csi-baremetal/pull/482?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=dell).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=dell)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/dell/csi-baremetal/pull/482?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=dell). Last update [740c92d...c0e020d](https://codecov.io/gh/dell/csi-baremetal/pull/482?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=dell). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=dell).


Patch:
diff --git a/pkg/scheduler/extender/extender.go b/pkg/scheduler/extender/extender.go
index 90d200a..e195f88 100644
--- a/pkg/scheduler/extender/extender.go
+++ b/pkg/scheduler/extender/extender.go
@@ -40,6 +40,7 @@ import (
 	volcrd "github.com/dell/csi-baremetal/api/v1/volumecrd"
 	"github.com/dell/csi-baremetal/pkg/base"
 	"github.com/dell/csi-baremetal/pkg/base/capacityplanner"
+	baseerr "github.com/dell/csi-baremetal/pkg/base/error"
 	fc "github.com/dell/csi-baremetal/pkg/base/featureconfig"
 	"github.com/dell/csi-baremetal/pkg/base/k8s"
 	"github.com/dell/csi-baremetal/pkg/base/util"
@@ -106,7 +107,10 @@ func (e *Extender) FilterHandler(w http.ResponseWriter, req *http.Request) {
 	pod := extenderArgs.Pod
 	requests, err := e.gatherCapacityRequestsByProvisioner(ctxWithVal, pod)
 	if err != nil {
-		extenderRes.Error = err.Error()
+		// not found error is re-triable
+		if err != baseerr.ErrorNotFound {
+			extenderRes.Error = err.Error()
+		}
 		if err := resp.Encode(extenderRes); err != nil {
 			ll.Errorf("Unable to write response %v: %v", extenderRes, err)
 		}
@@ -246,7 +250,7 @@ func (e *Extender) gatherCapacityRequestsByProvisioner(ctx context.Context, pod
 			if err != nil {
 				ll.Errorf("Unable to read PVC %s in NS %s: %v. ", v.PersistentVolumeClaim.ClaimName, pod.Namespace, err)
 				// PVC can be created later. csi-provisioner repeat request if not error.
-				return nil, nil
+				return nil, baseerr.ErrorNotFound
 			}
 			if pvc.Spec.StorageClassName == nil {
 				continue


Test patch:
diff --git a/pkg/scheduler/extender/extender_test.go b/pkg/scheduler/extender/extender_test.go
index 674e9cd..da32c23 100644
--- a/pkg/scheduler/extender/extender_test.go
+++ b/pkg/scheduler/extender/extender_test.go
@@ -37,6 +37,7 @@ import (
 	volcrd "github.com/dell/csi-baremetal/api/v1/volumecrd"
 	"github.com/dell/csi-baremetal/pkg/base"
 	"github.com/dell/csi-baremetal/pkg/base/capacityplanner"
+	baseerr "github.com/dell/csi-baremetal/pkg/base/error"
 	fc "github.com/dell/csi-baremetal/pkg/base/featureconfig"
 	"github.com/dell/csi-baremetal/pkg/base/k8s"
 	annotations "github.com/dell/csi-baremetal/pkg/crcontrollers/operator/common"
@@ -188,7 +189,7 @@ func TestExtender_gatherVolumesByProvisioner_Fail(t *testing.T) {
 	})
 	volumes, err = e.gatherCapacityRequestsByProvisioner(testCtx, &pod)
 	assert.Nil(t, volumes)
-	assert.Nil(t, err) // PVC can be created later
+	assert.Equal(t, err, baseerr.ErrorNotFound) // PVC can be created later
 
 	// PVC doesn't contain information about size
 	pod.Namespace = testNs