Repository: kubernetes-csi/csi-driver-nfs
Pull request #267 (2022-01-07 03:58:13)

fix: ValidateVolumeCapabilities
<!--  Thanks for sending a pull request!  Here are some tips for you:

1. If this is your first time, please read our contributor guidelines: https://git.k8s.io/community/contributors/guide#your-first-contribution and developer guide https://git.k8s.io/community/contributors/devel/development.md#development-guide
2. Follow the instructions for writing a release note: https://git.k8s.io/community/contributors/guide/release-notes.md
3. If the PR is unfinished, see how to mark it: https://git.k8s.io/community/contributors/guide/pull-requests.md#marking-unfinished-pull-requests
-->

**What type of PR is this?**
/kind bug

**What this PR does / why we need it**:
fix: ValidateVolumeCapabilities

**Which issue(s) this PR fixes**:
<!--
*Automatically closes linked issue when PR is merged.
Usage: `Fixes #<issue number>`, or `Fixes (paste link of issue)`.
_If PR is about `failing-tests or flakes`, please post the related issues/tests in a comment and do not use `Fixes`_*
-->
Fixes #

**Special notes for your reviewer**:

**Does this PR introduce a user-facing change?**:
<!--
If no, just write "NONE" in the release-note block below.
If yes, a release note is required:
Enter your extended release note in the block below. If the PR requires additional action from users switching to the new release, include the string "action required".
-->
```release-note
fix: ValidateVolumeCapabilities
```



Patch:
diff --git a/.github/workflows/static.yaml b/.github/workflows/static.yaml
index 1d887fb2..9efaaa44 100644
--- a/.github/workflows/static.yaml
+++ b/.github/workflows/static.yaml
@@ -12,7 +12,7 @@ jobs:
             - name: Run linter
               uses: golangci/golangci-lint-action@v2
               with:
-                  version: v1.29
+                  version: v1.31
                   args: -E=gofmt,deadcode,unused,varcheck,ineffassign,golint,misspell --timeout=30m0s
     verify-helm:
         name: Verify Helm
diff --git a/pkg/nfs/controllerserver.go b/pkg/nfs/controllerserver.go
index b14af9f0..446033b3 100644
--- a/pkg/nfs/controllerserver.go
+++ b/pkg/nfs/controllerserver.go
@@ -178,8 +178,12 @@ func (cs *ControllerServer) ValidateVolumeCapabilities(ctx context.Context, req
 		return nil, status.Error(codes.InvalidArgument, "Volume capabilities missing in request")
 	}
 
-	// supports all AccessModes, no need to check capabilities here
-	return &csi.ValidateVolumeCapabilitiesResponse{Message: ""}, nil
+	return &csi.ValidateVolumeCapabilitiesResponse{
+		Confirmed: &csi.ValidateVolumeCapabilitiesResponse_Confirmed{
+			VolumeCapabilities: req.GetVolumeCapabilities(),
+		},
+		Message: "",
+	}, nil
 }
 
 func (cs *ControllerServer) ListVolumes(ctx context.Context, req *csi.ListVolumesRequest) (*csi.ListVolumesResponse, error) {


Test patch:
diff --git a/pkg/nfs/controllerserver_test.go b/pkg/nfs/controllerserver_test.go
index 664529bc..d7fb6309 100644
--- a/pkg/nfs/controllerserver_test.go
+++ b/pkg/nfs/controllerserver_test.go
@@ -294,6 +294,17 @@ func TestDeleteVolume(t *testing.T) {
 }
 
 func TestValidateVolumeCapabilities(t *testing.T) {
+	capabilities := []*csi.VolumeCapability{
+		{
+			AccessType: &csi.VolumeCapability_Mount{
+				Mount: &csi.VolumeCapability_MountVolume{},
+			},
+			AccessMode: &csi.VolumeCapability_AccessMode{
+				Mode: csi.VolumeCapability_AccessMode_MULTI_NODE_MULTI_WRITER,
+			},
+		},
+	}
+
 	cases := []struct {
 		desc        string
 		req         *csi.ValidateVolumeCapabilitiesRequest
@@ -315,37 +326,23 @@ func TestValidateVolumeCapabilities(t *testing.T) {
 		{
 			desc: "valid request",
 			req: &csi.ValidateVolumeCapabilitiesRequest{
-				VolumeId: testVolumeID,
-				VolumeCapabilities: []*csi.VolumeCapability{
-					{
-						AccessType: &csi.VolumeCapability_Mount{
-							Mount: &csi.VolumeCapability_MountVolume{},
-						},
-						AccessMode: &csi.VolumeCapability_AccessMode{
-							Mode: csi.VolumeCapability_AccessMode_MULTI_NODE_MULTI_WRITER,
-						},
-					},
-				},
+				VolumeId:           testVolumeID,
+				VolumeCapabilities: capabilities,
+			},
+			resp: &csi.ValidateVolumeCapabilitiesResponse{
+				Confirmed: &csi.ValidateVolumeCapabilitiesResponse_Confirmed{VolumeCapabilities: capabilities},
 			},
-			resp:        &csi.ValidateVolumeCapabilitiesResponse{Message: ""},
 			expectedErr: nil,
 		},
 		{
 			desc: "valid request with newTestVolumeID",
 			req: &csi.ValidateVolumeCapabilitiesRequest{
-				VolumeId: newTestVolumeID,
-				VolumeCapabilities: []*csi.VolumeCapability{
-					{
-						AccessType: &csi.VolumeCapability_Mount{
-							Mount: &csi.VolumeCapability_MountVolume{},
-						},
-						AccessMode: &csi.VolumeCapability_AccessMode{
-							Mode: csi.VolumeCapability_AccessMode_MULTI_NODE_MULTI_WRITER,
-						},
-					},
-				},
+				VolumeId:           newTestVolumeID,
+				VolumeCapabilities: capabilities,
+			},
+			resp: &csi.ValidateVolumeCapabilitiesResponse{
+				Confirmed: &csi.ValidateVolumeCapabilitiesResponse_Confirmed{VolumeCapabilities: capabilities},
 			},
-			resp:        &csi.ValidateVolumeCapabilitiesResponse{Message: ""},
 			expectedErr: nil,
 		},
 	}
@@ -353,13 +350,8 @@ func TestValidateVolumeCapabilities(t *testing.T) {
 	for _, test := range cases {
 		test := test //pin
 		t.Run(test.desc, func(t *testing.T) {
-			// Setup
 			cs := initTestController(t)
-
-			// Run
 			resp, err := cs.ValidateVolumeCapabilities(context.TODO(), test.req)
-
-			// Verify
 			if test.expectedErr == nil && err != nil {
 				t.Errorf("test %q failed: %v", test.desc, err)
 			}