Skip to content

Commit e7c1df0

Browse files
authored
Merge pull request #150 from mauriciopoppe/kubelet-path
Combine plugin and pod paths into one KubeletPath
2 parents b1b655c + 1e7625e commit e7c1df0

File tree

17 files changed

+177
-524
lines changed

17 files changed

+177
-524
lines changed

.github/workflows/windows.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
run: |
2626
# start the CSI Proxy before running tests on windows
2727
Start-Job -Name CSIProxy -ScriptBlock {
28-
.\bin\csi-proxy.exe --kubelet-csi-plugins-path $pwd --kubelet-pod-path $pwd
28+
.\bin\csi-proxy.exe
2929
};
3030
Start-Sleep -Seconds 30;
3131
Write-Output "getting named pipes"
@@ -47,4 +47,4 @@ jobs:
4747
uses: actions/checkout@v2
4848
- name: Run Windows Unit Tests
4949
run: |
50-
go test -v -race ./internal/...
50+
go test -v -race ./internal/...

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

Lines changed: 61 additions & 164 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: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -24,27 +24,9 @@ service Filesystem {
2424
rpc IsSymlink(IsSymlinkRequest) returns (IsSymlinkResponse) {}
2525
}
2626

27-
// Context of the paths used for path prefix validation
28-
enum PathContext {
29-
// Indicates the kubelet-csi-plugins-path parameter of csi-proxy be used as
30-
// the path context. This may be used while handling NodeStageVolume where
31-
// a volume may need to be mounted at a plugin-specific path like:
32-
// kubelet\plugins\kubernetes.io\csi\pv\<pv-name>\globalmount
33-
PLUGIN = 0;
34-
// Indicates the kubelet-pod-path parameter of csi-proxy be used as the path
35-
// context. This may be used while handling NodePublishVolume where a staged
36-
// volume may be need to be symlinked to a pod-specific path like:
37-
// kubelet\pods\<pod-uuid>\volumes\kubernetes.io~csi\<pvc-name>\mount
38-
POD = 1;
39-
}
40-
4127
message PathExistsRequest {
4228
// The path whose existence we want to check in the host's filesystem
4329
string path = 1;
44-
45-
// Context of the path parameter.
46-
// This is used to validate prefix for absolute paths passed
47-
PathContext context = 2;
4830
}
4931

5032
message PathExistsResponse {
@@ -72,10 +54,6 @@ message MkdirRequest {
7254
// Characters: .. / : | ? * in the path are not allowed.
7355
// Maximum path length will be capped to 260 characters.
7456
string path = 1;
75-
76-
// Context of the path parameter.
77-
// This is used to validate prefix for absolute paths passed
78-
PathContext context = 2;
7957
}
8058

8159
message MkdirResponse {
@@ -100,12 +78,8 @@ message RmdirRequest {
10078
// Maximum path length will be capped to 260 characters.
10179
string path = 1;
10280

103-
// Context of the path parameter.
104-
// This is used to validate prefix for absolute paths passed
105-
PathContext context = 2;
106-
10781
// Force remove all contents under path (if any).
108-
bool force = 3;
82+
bool force = 2;
10983
}
11084

11185
message RmdirResponse {

cmd/csi-proxy/main.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,9 @@ import (
2323
)
2424

2525
var (
26-
kubeletCSIPluginsPath = flag.String("kubelet-csi-plugins-path", `C:\var\lib\kubelet`, "Prefix path of the Kubelet plugin directory in the host file system")
27-
kubeletPodPath = flag.String("kubelet-pod-path", `C:\var\lib\kubelet`, "Prefix path of the kubelet pod directory in the host file system")
28-
windowsSvc = flag.Bool("windows-service", false, "Configure as a Windows Service")
29-
service *handler
26+
kubeletPath = flag.String("kubelet-path", `C:\var\lib\kubelet`, "Prefix path of the kubelet directory in the host file system")
27+
windowsSvc = flag.Bool("windows-service", false, "Configure as a Windows Service")
28+
service *handler
3029
)
3130

3231
type handler struct {
@@ -61,7 +60,7 @@ func main() {
6160

6261
// apiGroups returns the list of enabled API groups.
6362
func apiGroups() ([]srvtypes.APIGroup, error) {
64-
fssrv, err := filesystemsrv.NewServer(*kubeletCSIPluginsPath, *kubeletPodPath, filesystemapi.New())
63+
fssrv, err := filesystemsrv.NewServer(*kubeletPath, filesystemapi.New())
6564
if err != nil {
6665
return []srvtypes.APIGroup{}, err
6766
}

integrationtests/filesystem_v1alpha1_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func v1alpha1FilesystemTests(t *testing.T) {
2626
r1 := rand.New(s1)
2727

2828
// simulate FS operations around staging a volume on a node
29-
stagepath := getWorkDirPath(fmt.Sprintf("testplugin-%d.csi.io\\volume%d", r1.Intn(100), r1.Intn(100)), t)
29+
stagepath := getKubeletPathForTest(fmt.Sprintf("testplugin-%d.csi.io\\volume%d", r1.Intn(100), r1.Intn(100)), t)
3030
mkdirReq := &v1alpha1.MkdirRequest{
3131
Path: stagepath,
3232
Context: v1alpha1.PathContext_PLUGIN,
@@ -38,7 +38,7 @@ func v1alpha1FilesystemTests(t *testing.T) {
3838
assert.True(t, exists, err)
3939

4040
// simulate operations around publishing a volume to a pod
41-
podpath := getWorkDirPath(fmt.Sprintf("test-pod-id\\volumes\\kubernetes.io~csi\\pvc-test%d", r1.Intn(100)), t)
41+
podpath := getKubeletPathForTest(fmt.Sprintf("test-pod-id\\volumes\\kubernetes.io~csi\\pvc-test%d", r1.Intn(100)), t)
4242
mkdirReq = &v1alpha1.MkdirRequest{
4343
Path: podpath,
4444
Context: v1alpha1.PathContext_POD,
@@ -96,13 +96,13 @@ func v1alpha1FilesystemTests(t *testing.T) {
9696
rand1 := r1.Intn(100)
9797
rand2 := r1.Intn(100)
9898

99-
testDir := getWorkDirPath(fmt.Sprintf("testplugin-%d.csi.io", rand1), t)
99+
testDir := getKubeletPathForTest(fmt.Sprintf("testplugin-%d.csi.io", rand1), t)
100100
err = os.MkdirAll(testDir, os.ModeDir)
101101
require.Nil(t, err)
102102
defer os.RemoveAll(testDir)
103103

104104
// 1. Check the isMount on a path which does not exist. Failure scenario.
105-
stagepath := getWorkDirPath(fmt.Sprintf("testplugin-%d.csi.io\\volume%d", rand1, rand2), t)
105+
stagepath := getKubeletPathForTest(fmt.Sprintf("testplugin-%d.csi.io\\volume%d", rand1, rand2), t)
106106
isMountRequest := &v1alpha1.IsMountPointRequest{
107107
Path: stagepath,
108108
}
@@ -122,8 +122,8 @@ func v1alpha1FilesystemTests(t *testing.T) {
122122

123123
err = os.Remove(stagepath)
124124
require.Nil(t, err)
125-
targetStagePath := getWorkDirPath(fmt.Sprintf("testplugin-%d.csi.io\\volume%d-tgt", rand1, rand2), t)
126-
lnTargetStagePath := getWorkDirPath(fmt.Sprintf("testplugin-%d.csi.io\\volume%d-tgt-ln", rand1, rand2), t)
125+
targetStagePath := getKubeletPathForTest(fmt.Sprintf("testplugin-%d.csi.io\\volume%d-tgt", rand1, rand2), t)
126+
lnTargetStagePath := getKubeletPathForTest(fmt.Sprintf("testplugin-%d.csi.io\\volume%d-tgt-ln", rand1, rand2), t)
127127

128128
// 3. Create soft link to the directory and make sure target exists. Success scenario.
129129
err = os.Mkdir(targetStagePath, os.ModeDir)

integrationtests/filesystem_v1beta1_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func v1beta1FilesystemTests(t *testing.T) {
2626
r1 := rand.New(s1)
2727

2828
// simulate FS operations around staging a volume on a node
29-
stagepath := getWorkDirPath(fmt.Sprintf("testplugin-%d.csi.io\\volume%d", r1.Intn(100), r1.Intn(100)), t)
29+
stagepath := getKubeletPathForTest(fmt.Sprintf("testplugin-%d.csi.io\\volume%d", r1.Intn(100), r1.Intn(100)), t)
3030
mkdirReq := &v1beta1.MkdirRequest{
3131
Path: stagepath,
3232
Context: v1beta1.PathContext_PLUGIN,
@@ -38,7 +38,7 @@ func v1beta1FilesystemTests(t *testing.T) {
3838
assert.True(t, exists, err)
3939

4040
// simulate operations around publishing a volume to a pod
41-
podpath := getWorkDirPath(fmt.Sprintf("test-pod-id\\volumes\\kubernetes.io~csi\\pvc-test%d", r1.Intn(100)), t)
41+
podpath := getKubeletPathForTest(fmt.Sprintf("test-pod-id\\volumes\\kubernetes.io~csi\\pvc-test%d", r1.Intn(100)), t)
4242
mkdirReq = &v1beta1.MkdirRequest{
4343
Path: podpath,
4444
Context: v1beta1.PathContext_POD,
@@ -96,13 +96,13 @@ func v1beta1FilesystemTests(t *testing.T) {
9696
rand1 := r1.Intn(100)
9797
rand2 := r1.Intn(100)
9898

99-
testDir := getWorkDirPath(fmt.Sprintf("testplugin-%d.csi.io", rand1), t)
99+
testDir := getKubeletPathForTest(fmt.Sprintf("testplugin-%d.csi.io", rand1), t)
100100
err = os.MkdirAll(testDir, os.ModeDir)
101101
require.Nil(t, err)
102102
defer os.RemoveAll(testDir)
103103

104104
// 1. Check the isMount on a path which does not exist. Failure scenario.
105-
stagepath := getWorkDirPath(fmt.Sprintf("testplugin-%d.csi.io\\volume%d", rand1, rand2), t)
105+
stagepath := getKubeletPathForTest(fmt.Sprintf("testplugin-%d.csi.io\\volume%d", rand1, rand2), t)
106106
isMountRequest := &v1beta1.IsMountPointRequest{
107107
Path: stagepath,
108108
}
@@ -122,8 +122,8 @@ func v1beta1FilesystemTests(t *testing.T) {
122122

123123
err = os.Remove(stagepath)
124124
require.Nil(t, err)
125-
targetStagePath := getWorkDirPath(fmt.Sprintf("testplugin-%d.csi.io\\volume%d-tgt", rand1, rand2), t)
126-
lnTargetStagePath := getWorkDirPath(fmt.Sprintf("testplugin-%d.csi.io\\volume%d-tgt-ln", rand1, rand2), t)
125+
targetStagePath := getKubeletPathForTest(fmt.Sprintf("testplugin-%d.csi.io\\volume%d-tgt", rand1, rand2), t)
126+
lnTargetStagePath := getKubeletPathForTest(fmt.Sprintf("testplugin-%d.csi.io\\volume%d-tgt-ln", rand1, rand2), t)
127127

128128
// 3. Create soft link to the directory and make sure target exists. Success scenario.
129129
err = os.Mkdir(targetStagePath, os.ModeDir)

integrationtests/filesystem_v1beta2_test.go

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,9 @@ func v1beta2FilesystemTests(t *testing.T) {
2626
r1 := rand.New(s1)
2727

2828
// simulate FS operations around staging a volume on a node
29-
stagepath := getWorkDirPath(fmt.Sprintf("testplugin-%d.csi.io\\volume%d", r1.Intn(100), r1.Intn(100)), t)
29+
stagepath := getKubeletPathForTest(fmt.Sprintf("testplugin-%d.csi.io\\volume%d", r1.Intn(100), r1.Intn(100)), t)
3030
mkdirReq := &v1beta2.MkdirRequest{
31-
Path: stagepath,
32-
Context: v1beta2.PathContext_PLUGIN,
31+
Path: stagepath,
3332
}
3433
_, err = client.Mkdir(context.Background(), mkdirReq)
3534
require.NoError(t, err)
@@ -38,10 +37,9 @@ func v1beta2FilesystemTests(t *testing.T) {
3837
assert.True(t, exists, err)
3938

4039
// simulate operations around publishing a volume to a pod
41-
podpath := getWorkDirPath(fmt.Sprintf("test-pod-id\\volumes\\kubernetes.io~csi\\pvc-test%d", r1.Intn(100)), t)
40+
podpath := getKubeletPathForTest(fmt.Sprintf("test-pod-id\\volumes\\kubernetes.io~csi\\pvc-test%d", r1.Intn(100)), t)
4241
mkdirReq = &v1beta2.MkdirRequest{
43-
Path: podpath,
44-
Context: v1beta2.PathContext_POD,
42+
Path: podpath,
4543
}
4644
_, err = client.Mkdir(context.Background(), mkdirReq)
4745
require.NoError(t, err)
@@ -64,9 +62,8 @@ func v1beta2FilesystemTests(t *testing.T) {
6462

6563
// cleanup pvpath
6664
rmdirReq := &v1beta2.RmdirRequest{
67-
Path: podpath,
68-
Context: v1beta2.PathContext_POD,
69-
Force: true,
65+
Path: podpath,
66+
Force: true,
7067
}
7168
_, err = client.Rmdir(context.Background(), rmdirReq)
7269
require.NoError(t, err)
@@ -76,9 +73,8 @@ func v1beta2FilesystemTests(t *testing.T) {
7673

7774
// cleanup plugin path
7875
rmdirReq = &v1beta2.RmdirRequest{
79-
Path: stagepath,
80-
Context: v1beta2.PathContext_PLUGIN,
81-
Force: true,
76+
Path: stagepath,
77+
Force: true,
8278
}
8379
_, err = client.Rmdir(context.Background(), rmdirReq)
8480
require.NoError(t, err)
@@ -96,13 +92,13 @@ func v1beta2FilesystemTests(t *testing.T) {
9692
rand1 := r1.Intn(100)
9793
rand2 := r1.Intn(100)
9894

99-
testDir := getWorkDirPath(fmt.Sprintf("testplugin-%d.csi.io", rand1), t)
95+
testDir := getKubeletPathForTest(fmt.Sprintf("testplugin-%d.csi.io", rand1), t)
10096
err = os.MkdirAll(testDir, os.ModeDir)
10197
require.Nil(t, err)
10298
defer os.RemoveAll(testDir)
10399

104100
// 1. Check the isMount on a path which does not exist. Failure scenario.
105-
stagepath := getWorkDirPath(fmt.Sprintf("testplugin-%d.csi.io\\volume%d", rand1, rand2), t)
101+
stagepath := getKubeletPathForTest(fmt.Sprintf("testplugin-%d.csi.io\\volume%d", rand1, rand2), t)
106102
IsSymlinkRequest := &v1beta2.IsSymlinkRequest{
107103
Path: stagepath,
108104
}
@@ -122,8 +118,8 @@ func v1beta2FilesystemTests(t *testing.T) {
122118

123119
err = os.Remove(stagepath)
124120
require.Nil(t, err)
125-
targetStagePath := getWorkDirPath(fmt.Sprintf("testplugin-%d.csi.io\\volume%d-tgt", rand1, rand2), t)
126-
lnTargetStagePath := getWorkDirPath(fmt.Sprintf("testplugin-%d.csi.io\\volume%d-tgt-ln", rand1, rand2), t)
121+
targetStagePath := getKubeletPathForTest(fmt.Sprintf("testplugin-%d.csi.io\\volume%d-tgt", rand1, rand2), t)
122+
lnTargetStagePath := getKubeletPathForTest(fmt.Sprintf("testplugin-%d.csi.io\\volume%d-tgt-ln", rand1, rand2), t)
127123

128124
// 3. Create soft link to the directory and make sure target exists. Success scenario.
129125
err = os.Mkdir(targetStagePath, os.ModeDir)

integrationtests/utils.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -125,14 +125,10 @@ func readFile(t *testing.T, filePath string) string {
125125
return string(contents)
126126
}
127127

128-
// GetWorkDirPath returns the path to the current working directory
128+
// getKubeletPathForTest returns the path to the current working directory
129129
// to be used anytime the filepath is required to be within context of csi-proxy
130-
func getWorkDirPath(dir string, t *testing.T) string {
131-
path, err := os.Getwd()
132-
if err != nil {
133-
t.Fatalf("failed to get working directory: %s", err)
134-
}
135-
return filepath.Join(path, "testdir", dir)
130+
func getKubeletPathForTest(dir string, t *testing.T) string {
131+
return filepath.Join("C:\\var\\lib\\kubelet", "testdir", dir)
136132
}
137133

138134
// returns true if CSI_PROXY_GH_ACTIONS is set to "TRUE"

internal/server/filesystem/internal/types.go

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,9 @@
11
package internal
22

3-
type PathContext int32
4-
5-
const (
6-
// Indicates the kubelet-csi-plugins-path parameter of csi-proxy be used as the path context
7-
PLUGIN PathContext = iota
8-
// Indicates the kubelet-pod-path parameter of csi-proxy be used as the path context
9-
POD
10-
)
11-
123
// PathExistsRequest is the internal representation of requests to the PathExists endpoint.
134
type PathExistsRequest struct {
145
// The path whose existence we want to check in the host's filesystem
156
Path string
16-
// Context of the path parameter.
17-
// This is used to determine the root for relative path parameters
18-
Context PathContext
197
}
208

219
// PathExistsResponse is the internal representation of responses from the PathExists endpoint.
@@ -44,11 +32,6 @@ type MkdirRequest struct {
4432
// Characters: .. / : | ? * in the path are not allowed.
4533
// Maximum path length will be capped to 260 characters.
4634
Path string
47-
// Context of the path parameter.
48-
// This is used to [1] determine the root for relative path parameters
49-
// or [2] validate prefix for absolute paths (indicated by a drive letter
50-
// prefix: e.g. "C:\")
51-
Context PathContext
5235
}
5336

5437
type MkdirResponse struct {
@@ -71,11 +54,6 @@ type RmdirRequest struct {
7154
// Path cannot be a file of type symlink.
7255
// Maximum path length will be capped to 260 characters.
7356
Path string
74-
// Context of the path creation used for path prefix validation
75-
// This is used to [1] determine the root for relative path parameters
76-
// or [2] validate prefix for absolute paths (indicated by a drive letter
77-
// prefix: e.g. "C:\")
78-
Context PathContext
7957
// Force remove all contents under path (if any).
8058
Force bool
8159
}

internal/server/filesystem/internal/v1alpha1/conversion_generated.go

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

0 commit comments

Comments
 (0)