Skip to content

Commit 9dee974

Browse files
authored
Merge pull request #21 from kkmsft/fsApis
IsMountPoint implementation
2 parents 7a001bc + e82f027 commit 9dee974

File tree

11 files changed

+371
-31
lines changed

11 files changed

+371
-31
lines changed

client/api/filesystem/v1alpha1/api.pb.go

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

client/api/filesystem/v1alpha1/api.proto

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ service Filesystem {
1616
// LinkPath creates a local directory symbolic link between a source path
1717
// and target path in the host's filesystem
1818
rpc LinkPath(LinkPathRequest) returns (LinkPathResponse) {}
19+
20+
//IsMountPoint checks if a given path is mount or not
21+
rpc IsMountPoint(IsMountPointRequest) returns (IsMountPointResponse) {}
1922
}
2023

2124
// Context of the paths used for path prefix validation
@@ -150,3 +153,16 @@ message LinkPathResponse {
150153
// Error message if any. Empty string indicates success
151154
string error = 1;
152155
}
156+
157+
message IsMountPointRequest {
158+
// The path whose existence we want to check in the host's filesystem
159+
string path = 1;
160+
}
161+
162+
message IsMountPointResponse {
163+
// Error message if any. Empty string indicates success
164+
string error = 1;
165+
166+
// Indicates whether the path in PathExistsRequest exists in the host's filesystem
167+
bool is_mount_point = 2;
168+
}

client/groups/filesystem/v1alpha1/client_generated.go

Lines changed: 4 additions & 0 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: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,70 @@ func TestFilesystemAPIGroup(t *testing.T) {
9999
exists, err = pathExists(stagepath)
100100
assert.False(t, exists, err)
101101
})
102+
t.Run("IsMount", func(t *testing.T) {
103+
client, err := v1alpha1client.NewClient()
104+
require.Nil(t, err)
105+
defer client.Close()
106+
107+
s1 := rand.NewSource(time.Now().UnixNano())
108+
r1 := rand.New(s1)
109+
rand1 := r1.Intn(100)
110+
rand2 := r1.Intn(100)
111+
112+
testDir := fmt.Sprintf("C:\\var\\lib\\kubelet\\plugins\\testplugin-%d.csi.io", rand1)
113+
err = os.MkdirAll(testDir, os.ModeDir)
114+
require.Nil(t, err)
115+
defer os.RemoveAll(testDir)
116+
117+
// 1. Check the isMount on a path which does not exist. Failure scenario.
118+
stagepath := fmt.Sprintf("C:\\var\\lib\\kubelet\\plugins\\testplugin-%d.csi.io\\volume%d", rand1, rand2)
119+
isMountRequest := &v1alpha1.IsMountPointRequest{
120+
Path: stagepath,
121+
}
122+
isMountResponse, err := client.IsMountPoint(context.Background(), isMountRequest)
123+
require.Nil(t, err)
124+
require.Equal(t, isMountResponse.IsMountPoint, false)
125+
126+
// 2. Create the directory. This time its not a mount point. Failure scenario.
127+
err = os.Mkdir(stagepath, os.ModeDir)
128+
require.Nil(t, err)
129+
defer os.Remove(stagepath)
130+
isMountRequest = &v1alpha1.IsMountPointRequest{
131+
Path: stagepath,
132+
}
133+
isMountResponse, err = client.IsMountPoint(context.Background(), isMountRequest)
134+
require.Nil(t, err)
135+
require.Equal(t, isMountResponse.IsMountPoint, false)
136+
137+
err = os.Remove(stagepath)
138+
require.Nil(t, err)
139+
targetStagePath := fmt.Sprintf("C:\\var\\lib\\kubelet\\plugins\\testplugin-%d.csi.io\\volume%d-tgt", rand1, rand2)
140+
lnTargetStagePath := fmt.Sprintf("C:\\var\\lib\\kubelet\\plugins\\testplugin-%d.csi.io\\volume%d-tgt-ln", rand1, rand2)
141+
142+
// 3. Create soft link to the directory and make sure target exists. Success scenario.
143+
os.Mkdir(targetStagePath, os.ModeDir)
144+
require.Nil(t, err)
145+
defer os.Remove(targetStagePath)
146+
// Create a sym link
147+
err = os.Symlink(targetStagePath, lnTargetStagePath)
148+
require.Nil(t, err)
149+
defer os.Remove(lnTargetStagePath)
150+
151+
isMountRequest = &v1alpha1.IsMountPointRequest{
152+
Path: lnTargetStagePath,
153+
}
154+
isMountResponse, err = client.IsMountPoint(context.Background(), isMountRequest)
155+
require.Nil(t, err)
156+
require.Equal(t, isMountResponse.IsMountPoint, true)
157+
158+
// 4. Remove the path. Failure scenario.
159+
err = os.Remove(targetStagePath)
160+
require.Nil(t, err)
161+
isMountRequest = &v1alpha1.IsMountPointRequest{
162+
Path: lnTargetStagePath,
163+
}
164+
isMountResponse, err = client.IsMountPoint(context.Background(), isMountRequest)
165+
require.Nil(t, err)
166+
require.Equal(t, isMountResponse.IsMountPoint, false)
167+
})
102168
}

0 commit comments

Comments
 (0)