Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
run: |
# start the CSI Proxy before running tests on windows
Start-Job -Name CSIProxy -ScriptBlock {
.\bin\csi-proxy.exe --kubelet-csi-plugins-path $pwd --kubelet-pod-path $pwd
.\bin\csi-proxy.exe
};
Start-Sleep -Seconds 30;
Write-Output "getting named pipes"
Expand All @@ -47,4 +47,4 @@ jobs:
uses: actions/checkout@v2
- name: Run Windows Unit Tests
run: |
go test -v -race ./internal/...
go test -v -race ./internal/...
225 changes: 61 additions & 164 deletions client/api/filesystem/v1beta2/api.pb.go

Large diffs are not rendered by default.

28 changes: 1 addition & 27 deletions client/api/filesystem/v1beta2/api.proto
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,9 @@ service Filesystem {
rpc IsSymlink(IsSymlinkRequest) returns (IsSymlinkResponse) {}
}

// Context of the paths used for path prefix validation
enum PathContext {
// Indicates the kubelet-csi-plugins-path parameter of csi-proxy be used as
// the path context. This may be used while handling NodeStageVolume where
// a volume may need to be mounted at a plugin-specific path like:
// kubelet\plugins\kubernetes.io\csi\pv\<pv-name>\globalmount
PLUGIN = 0;
// Indicates the kubelet-pod-path parameter of csi-proxy be used as the path
// context. This may be used while handling NodePublishVolume where a staged
// volume may be need to be symlinked to a pod-specific path like:
// kubelet\pods\<pod-uuid>\volumes\kubernetes.io~csi\<pvc-name>\mount
POD = 1;
}

message PathExistsRequest {
// The path whose existence we want to check in the host's filesystem
string path = 1;

// Context of the path parameter.
// This is used to validate prefix for absolute paths passed
PathContext context = 2;
}

message PathExistsResponse {
Expand Down Expand Up @@ -72,10 +54,6 @@ message MkdirRequest {
// Characters: .. / : | ? * in the path are not allowed.
// Maximum path length will be capped to 260 characters.
string path = 1;

// Context of the path parameter.
// This is used to validate prefix for absolute paths passed
PathContext context = 2;
}

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

// Context of the path parameter.
// This is used to validate prefix for absolute paths passed
PathContext context = 2;

// Force remove all contents under path (if any).
bool force = 3;
bool force = 2;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Somehow the comment here got deleted. Can we use reserved https://developers.google.com/protocol-buffers/docs/proto3#reserved here to prevent the re-numbering?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is useful if the same proto file is used across versions, because we have new protos for every version I'm not sure if this makes sense in this project

}

message RmdirResponse {
Expand Down
9 changes: 4 additions & 5 deletions cmd/csi-proxy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ import (
)

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

type handler struct {
Expand Down Expand Up @@ -61,7 +60,7 @@ func main() {

// apiGroups returns the list of enabled API groups.
func apiGroups() ([]srvtypes.APIGroup, error) {
fssrv, err := filesystemsrv.NewServer(*kubeletCSIPluginsPath, *kubeletPodPath, filesystemapi.New())
fssrv, err := filesystemsrv.NewServer(*kubeletPath, filesystemapi.New())
if err != nil {
return []srvtypes.APIGroup{}, err
}
Expand Down
12 changes: 6 additions & 6 deletions integrationtests/filesystem_v1alpha1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func v1alpha1FilesystemTests(t *testing.T) {
r1 := rand.New(s1)

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

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

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

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

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

// 3. Create soft link to the directory and make sure target exists. Success scenario.
err = os.Mkdir(targetStagePath, os.ModeDir)
Expand Down
12 changes: 6 additions & 6 deletions integrationtests/filesystem_v1beta1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func v1beta1FilesystemTests(t *testing.T) {
r1 := rand.New(s1)

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

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

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

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

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

// 3. Create soft link to the directory and make sure target exists. Success scenario.
err = os.Mkdir(targetStagePath, os.ModeDir)
Expand Down
28 changes: 12 additions & 16 deletions integrationtests/filesystem_v1beta2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@ func v1beta2FilesystemTests(t *testing.T) {
r1 := rand.New(s1)

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

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

// cleanup pvpath
rmdirReq := &v1beta2.RmdirRequest{
Path: podpath,
Context: v1beta2.PathContext_POD,
Force: true,
Path: podpath,
Force: true,
}
_, err = client.Rmdir(context.Background(), rmdirReq)
require.NoError(t, err)
Expand All @@ -76,9 +73,8 @@ func v1beta2FilesystemTests(t *testing.T) {

// cleanup plugin path
rmdirReq = &v1beta2.RmdirRequest{
Path: stagepath,
Context: v1beta2.PathContext_PLUGIN,
Force: true,
Path: stagepath,
Force: true,
}
_, err = client.Rmdir(context.Background(), rmdirReq)
require.NoError(t, err)
Expand All @@ -96,13 +92,13 @@ func v1beta2FilesystemTests(t *testing.T) {
rand1 := r1.Intn(100)
rand2 := r1.Intn(100)

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

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

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

// 3. Create soft link to the directory and make sure target exists. Success scenario.
err = os.Mkdir(targetStagePath, os.ModeDir)
Expand Down
10 changes: 3 additions & 7 deletions integrationtests/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,10 @@ func readFile(t *testing.T, filePath string) string {
return string(contents)
}

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

// returns true if CSI_PROXY_GH_ACTIONS is set to "TRUE"
Expand Down
22 changes: 0 additions & 22 deletions internal/server/filesystem/internal/types.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,9 @@
package internal

type PathContext int32

const (
// Indicates the kubelet-csi-plugins-path parameter of csi-proxy be used as the path context
PLUGIN PathContext = iota
// Indicates the kubelet-pod-path parameter of csi-proxy be used as the path context
POD
)

// PathExistsRequest is the internal representation of requests to the PathExists endpoint.
type PathExistsRequest struct {
// The path whose existence we want to check in the host's filesystem
Path string
// Context of the path parameter.
// This is used to determine the root for relative path parameters
Context PathContext
}

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

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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading