Skip to content

Commit 6d16ceb

Browse files
authored
Merge pull request #143 from mauriciopoppe/fs-api-changes
Updates/refactors in the Filesystem v1beta2 API
2 parents c201c0a + 484c217 commit 6d16ceb

File tree

25 files changed

+1238
-836
lines changed

25 files changed

+1238
-836
lines changed

client/api/filesystem/v1beta2/api.pb.go

Lines changed: 166 additions & 218 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/api/filesystem/v1beta2/api.proto

Lines changed: 23 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,23 @@ package v1beta2;
55
option go_package = "github.com/kubernetes-csi/csi-proxy/client/api/filesystem/v1beta2";
66

77
service Filesystem {
8-
// PathExists checks if the requested path exists in the host's filesystem
8+
// PathExists checks if the requested path exists in the host filesystem.
99
rpc PathExists(PathExistsRequest) returns (PathExistsResponse) {}
1010

11-
// Mkdir creates a directory at the requested path in the host's filesystem
11+
// Mkdir creates a directory at the requested path in the host filesystem.
1212
rpc Mkdir(MkdirRequest) returns (MkdirResponse) {}
1313

14-
// Rmdir removes the directory at the requested path in the host's filesystem.
15-
// This may be used for unlinking a symlink created through LinkPath
14+
// Rmdir removes the directory at the requested path in the host filesystem.
15+
// This may be used for unlinking a symlink created through CreateSymlink.
1616
rpc Rmdir(RmdirRequest) returns (RmdirResponse) {}
1717

18-
// LinkPath creates a local directory symbolic link between a source path
19-
// and target path in the host's filesystem
20-
rpc LinkPath(LinkPathRequest) returns (LinkPathResponse) {}
18+
// CreateSymlink creates a symbolic link called target_path that points to source_path
19+
// in the host filesystem (target_path is the name of the symbolic link created,
20+
// source_path is the existing path).
21+
rpc CreateSymlink(CreateSymlinkRequest) returns (CreateSymlinkResponse) {}
2122

22-
//IsMountPoint checks if a given path is mount or not
23-
rpc IsMountPoint(IsMountPointRequest) returns (IsMountPointResponse) {}
23+
// IsSymlink checks if a given path is a symlink.
24+
rpc IsSymlink(IsSymlinkRequest) returns (IsSymlinkResponse) {}
2425
}
2526

2627
// Context of the paths used for path prefix validation
@@ -47,11 +48,8 @@ message PathExistsRequest {
4748
}
4849

4950
message PathExistsResponse {
50-
// Error message if any. Empty string indicates success
51-
string error = 1;
52-
5351
// Indicates whether the path in PathExistsRequest exists in the host's filesystem
54-
bool exists = 2;
52+
bool exists = 1;
5553
}
5654

5755
message MkdirRequest {
@@ -81,8 +79,7 @@ message MkdirRequest {
8179
}
8280

8381
message MkdirResponse {
84-
// Error message if any. Empty string indicates success
85-
string error = 1;
82+
// Intentionally empty.
8683
}
8784

8885
message RmdirRequest {
@@ -112,12 +109,11 @@ message RmdirRequest {
112109
}
113110

114111
message RmdirResponse {
115-
// Error message if any. Empty string indicates success
116-
string error = 1;
112+
// Intentionally empty.
117113
}
118114

119-
message LinkPathRequest {
120-
// The path where the symlink is created in the host's filesystem.
115+
message CreateSymlinkRequest {
116+
// The path of the existing directory to be linked.
121117
// All special characters allowed by Windows in path names will be allowed
122118
// except for restrictions noted below. For details, please check:
123119
// https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file
@@ -133,7 +129,7 @@ message LinkPathRequest {
133129
// Maximum path length will be capped to 260 characters.
134130
string source_path = 1;
135131

136-
// Target path in the host's filesystem used for the symlink creation.
132+
// Target path is the location of the new directory entry to be created in the host's filesystem.
137133
// All special characters allowed by Windows in path names will be allowed
138134
// except for restrictions noted below. For details, please check:
139135
// https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file
@@ -151,20 +147,16 @@ message LinkPathRequest {
151147
string target_path = 2;
152148
}
153149

154-
message LinkPathResponse {
155-
// Error message if any. Empty string indicates success
156-
string error = 1;
150+
message CreateSymlinkResponse {
151+
// Intentionally empty.
157152
}
158153

159-
message IsMountPointRequest {
160-
// The path whose existence we want to check in the host's filesystem
154+
message IsSymlinkRequest {
155+
// The path whose existence as a symlink we want to check in the host's filesystem.
161156
string path = 1;
162157
}
163158

164-
message IsMountPointResponse {
165-
// Error message if any. Empty string indicates success
166-
string error = 1;
167-
168-
// Indicates whether the path in PathExistsRequest exists in the host's filesystem
169-
bool is_mount_point = 2;
159+
message IsSymlinkResponse {
160+
// Indicates whether the path in IsSymlinkRequest is a symlink.
161+
bool is_symlink = 1;
170162
}

client/groups/filesystem/v1beta2/client_generated.go

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

integrationtests/filesystem_test.go

Lines changed: 7 additions & 147 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,8 @@
11
package integrationtests
22

33
import (
4-
"context"
5-
"fmt"
6-
"math/rand"
74
"os"
85
"testing"
9-
"time"
10-
11-
"github.com/stretchr/testify/assert"
12-
"github.com/stretchr/testify/require"
13-
14-
"github.com/kubernetes-csi/csi-proxy/client/api/filesystem/v1beta2"
15-
v1beta2client "github.com/kubernetes-csi/csi-proxy/client/groups/filesystem/v1beta2"
166
)
177

188
func pathExists(path string) (bool, error) {
@@ -27,143 +17,13 @@ func pathExists(path string) (bool, error) {
2717
}
2818

2919
func TestFilesystemAPIGroup(t *testing.T) {
30-
t.Run("PathExists positive", func(t *testing.T) {
31-
skipTestOnCondition(t, isRunningOnGhActions())
32-
33-
client, err := v1beta2client.NewClient()
34-
require.Nil(t, err)
35-
defer client.Close()
36-
37-
s1 := rand.NewSource(time.Now().UnixNano())
38-
r1 := rand.New(s1)
39-
40-
// simulate FS operations around staging a volume on a node
41-
stagepath := getWorkDirPath(fmt.Sprintf("testplugin-%d.csi.io\\volume%d", r1.Intn(100), r1.Intn(100)), t)
42-
mkdirReq := &v1beta2.MkdirRequest{
43-
Path: stagepath,
44-
Context: v1beta2.PathContext_PLUGIN,
45-
}
46-
mkdirRsp, err := client.Mkdir(context.Background(), mkdirReq)
47-
if assert.Nil(t, err) {
48-
assert.Equal(t, "", mkdirRsp.Error)
49-
}
50-
51-
exists, err := pathExists(stagepath)
52-
assert.True(t, exists, err)
53-
54-
// simulate operations around publishing a volume to a pod
55-
podpath := getWorkDirPath(fmt.Sprintf("test-pod-id\\volumes\\kubernetes.io~csi\\pvc-test%d", r1.Intn(100)), t)
56-
mkdirReq = &v1beta2.MkdirRequest{
57-
Path: podpath,
58-
Context: v1beta2.PathContext_POD,
59-
}
60-
mkdirRsp, err = client.Mkdir(context.Background(), mkdirReq)
61-
if assert.Nil(t, err) {
62-
assert.Equal(t, "", mkdirRsp.Error)
63-
}
64-
linkReq := &v1beta2.LinkPathRequest{
65-
TargetPath: stagepath,
66-
SourcePath: podpath + "\\rootvol",
67-
}
68-
linkRsp, err := client.LinkPath(context.Background(), linkReq)
69-
if assert.Nil(t, err) {
70-
assert.Equal(t, "", linkRsp.Error)
71-
}
72-
73-
exists, err = pathExists(podpath + "\\rootvol")
74-
assert.True(t, exists, err)
75-
76-
// cleanup pvpath
77-
rmdirReq := &v1beta2.RmdirRequest{
78-
Path: podpath,
79-
Context: v1beta2.PathContext_POD,
80-
Force: true,
81-
}
82-
rmdirRsp, err := client.Rmdir(context.Background(), rmdirReq)
83-
if assert.Nil(t, err) {
84-
assert.Equal(t, "", rmdirRsp.Error)
85-
}
86-
87-
exists, err = pathExists(podpath)
88-
assert.False(t, exists, err)
89-
90-
// cleanup plugin path
91-
rmdirReq = &v1beta2.RmdirRequest{
92-
Path: stagepath,
93-
Context: v1beta2.PathContext_PLUGIN,
94-
Force: true,
95-
}
96-
rmdirRsp, err = client.Rmdir(context.Background(), rmdirReq)
97-
if assert.Nil(t, err) {
98-
assert.Equal(t, "", rmdirRsp.Error)
99-
}
100-
101-
exists, err = pathExists(stagepath)
102-
assert.False(t, exists, err)
20+
t.Run("v1beta2FilesystemTests", func(t *testing.T) {
21+
v1beta2FilesystemTests(t)
10322
})
104-
t.Run("IsMount", func(t *testing.T) {
105-
client, err := v1beta2client.NewClient()
106-
require.Nil(t, err)
107-
defer client.Close()
108-
109-
s1 := rand.NewSource(time.Now().UnixNano())
110-
r1 := rand.New(s1)
111-
rand1 := r1.Intn(100)
112-
rand2 := r1.Intn(100)
113-
114-
testDir := getWorkDirPath(fmt.Sprintf("testplugin-%d.csi.io", rand1), t)
115-
err = os.MkdirAll(testDir, os.ModeDir)
116-
require.Nil(t, err)
117-
defer os.RemoveAll(testDir)
118-
119-
// 1. Check the isMount on a path which does not exist. Failure scenario.
120-
stagepath := getWorkDirPath(fmt.Sprintf("testplugin-%d.csi.io\\volume%d", rand1, rand2), t)
121-
isMountRequest := &v1beta2.IsMountPointRequest{
122-
Path: stagepath,
123-
}
124-
isMountResponse, err := client.IsMountPoint(context.Background(), isMountRequest)
125-
require.NotNil(t, err)
126-
127-
// 2. Create the directory. This time its not a mount point. Failure scenario.
128-
err = os.Mkdir(stagepath, os.ModeDir)
129-
require.Nil(t, err)
130-
defer os.Remove(stagepath)
131-
isMountRequest = &v1beta2.IsMountPointRequest{
132-
Path: stagepath,
133-
}
134-
isMountResponse, err = client.IsMountPoint(context.Background(), isMountRequest)
135-
require.Nil(t, err)
136-
require.Equal(t, isMountResponse.IsMountPoint, false)
137-
138-
err = os.Remove(stagepath)
139-
require.Nil(t, err)
140-
targetStagePath := getWorkDirPath(fmt.Sprintf("testplugin-%d.csi.io\\volume%d-tgt", rand1, rand2), t)
141-
lnTargetStagePath := getWorkDirPath(fmt.Sprintf("testplugin-%d.csi.io\\volume%d-tgt-ln", rand1, rand2), t)
142-
143-
// 3. Create soft link to the directory and make sure target exists. Success scenario.
144-
err = os.Mkdir(targetStagePath, os.ModeDir)
145-
require.Nil(t, err)
146-
defer os.Remove(targetStagePath)
147-
// Create a sym link
148-
err = os.Symlink(targetStagePath, lnTargetStagePath)
149-
require.Nil(t, err)
150-
defer os.Remove(lnTargetStagePath)
151-
152-
isMountRequest = &v1beta2.IsMountPointRequest{
153-
Path: lnTargetStagePath,
154-
}
155-
isMountResponse, err = client.IsMountPoint(context.Background(), isMountRequest)
156-
require.Nil(t, err)
157-
require.Equal(t, isMountResponse.IsMountPoint, true)
158-
159-
// 4. Remove the path. Failure scenario.
160-
err = os.Remove(targetStagePath)
161-
require.Nil(t, err)
162-
isMountRequest = &v1beta2.IsMountPointRequest{
163-
Path: lnTargetStagePath,
164-
}
165-
isMountResponse, err = client.IsMountPoint(context.Background(), isMountRequest)
166-
require.Nil(t, err)
167-
require.Equal(t, isMountResponse.IsMountPoint, false)
23+
t.Run("v1beta1FilesystemTests", func(t *testing.T) {
24+
v1beta1FilesystemTests(t)
25+
})
26+
t.Run("v1alpha1FilesystemTests", func(t *testing.T) {
27+
v1alpha1FilesystemTests(t)
16828
})
16929
}

0 commit comments

Comments
 (0)