Skip to content

Commit 7f62537

Browse files
committed
Misc fixes
- Relax the pod path and plugin path to c:\var\lib\kubelet - string compare prefix after performing a ToLower to accomodate case differences in path. - Fix the error returns from several filesystem apis.
1 parent 9dee974 commit 7f62537

File tree

3 files changed

+21
-21
lines changed

3 files changed

+21
-21
lines changed

cmd/server/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ import (
1515
)
1616

1717
var (
18-
kubeletCSIPluginsPath = flag.String("kubelet-csi-plugins-path", `C:\var\lib\kubelet\plugins`, "Absolute path of the Kubelet plugin directory in the host file system")
19-
kubeletPodPath = flag.String("kubelet-pod-path", `C:\var\lib\kubelet\pods`, "Absolute path of the kubelet pod directory in the host file system")
18+
kubeletCSIPluginsPath = flag.String("kubelet-csi-plugins-path", `C:\var\lib\kubelet`, "Prefix path of the Kubelet plugin directory in the host file system")
19+
kubeletPodPath = flag.String("kubelet-pod-path", `C:\var\lib\kubelet`, "Prefix path of the kubelet pod directory in the host file system")
2020
)
2121

2222
func main() {

internal/os/filesystem/api.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ func (APIImplementor) Rmdir(path string, force bool) error {
4242
return os.Remove(path)
4343
}
4444

45-
func (APIImplementor) LinkPath(tgt string, src string) error {
46-
return os.Symlink(tgt, src)
45+
func (APIImplementor) LinkPath(oldname, newname string) error {
46+
return os.Symlink(oldname, newname)
4747
}
4848

4949
// IsMountPoint - returns true if its a mount point.

internal/server/filesystem/server.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func (s *Server) validatePathWindows(pathCtx internal.PathContext, path string)
9999
return fmt.Errorf("not an absolute Windows path: %s", path)
100100
}
101101

102-
if !strings.HasPrefix(path, prefix) {
102+
if !strings.HasPrefix(strings.ToLower(path), strings.ToLower(prefix)) {
103103
return fmt.Errorf("path: %s is not within context path: %s", path, prefix)
104104
}
105105

@@ -112,18 +112,18 @@ func (s *Server) PathExists(ctx context.Context, request *internal.PathExistsReq
112112
if err != nil {
113113
return &internal.PathExistsResponse{
114114
Error: err.Error(),
115-
}, nil
115+
}, err
116116
}
117117
exists, err := s.hostAPI.PathExists(request.Path)
118118
if err != nil {
119119
return &internal.PathExistsResponse{
120120
Error: err.Error(),
121-
}, nil
121+
}, err
122122
}
123123
return &internal.PathExistsResponse{
124124
Error: "",
125125
Exists: exists,
126-
}, nil
126+
}, err
127127
}
128128

129129
func (s *Server) Mkdir(ctx context.Context, request *internal.MkdirRequest, version apiversion.Version) (*internal.MkdirResponse, error) {
@@ -137,53 +137,53 @@ func (s *Server) Mkdir(ctx context.Context, request *internal.MkdirRequest, vers
137137
if err != nil {
138138
return &internal.MkdirResponse{
139139
Error: err.Error(),
140-
}, nil
140+
}, err
141141
}
142142

143143
return &internal.MkdirResponse{
144144
Error: "",
145-
}, nil
145+
}, err
146146
}
147147

148148
func (s *Server) Rmdir(ctx context.Context, request *internal.RmdirRequest, version apiversion.Version) (*internal.RmdirResponse, error) {
149149
err := s.validatePathWindows(request.Context, request.Path)
150150
if err != nil {
151151
return &internal.RmdirResponse{
152152
Error: err.Error(),
153-
}, nil
153+
}, err
154154
}
155155
err = s.hostAPI.Rmdir(request.Path, request.Force)
156156
if err != nil {
157157
return &internal.RmdirResponse{
158158
Error: err.Error(),
159-
}, nil
159+
}, err
160160
}
161161
return &internal.RmdirResponse{
162162
Error: "",
163-
}, nil
163+
}, err
164164
}
165165

166166
func (s *Server) LinkPath(ctx context.Context, request *internal.LinkPathRequest, version apiversion.Version) (*internal.LinkPathResponse, error) {
167-
err := s.validatePathWindows(internal.POD, request.SourcePath)
167+
err := s.validatePathWindows(internal.POD, request.TargetPath)
168168
if err != nil {
169169
return &internal.LinkPathResponse{
170170
Error: err.Error(),
171-
}, nil
171+
}, err
172172
}
173-
err = s.validatePathWindows(internal.PLUGIN, request.TargetPath)
173+
err = s.validatePathWindows(internal.PLUGIN, request.SourcePath)
174174
if err != nil {
175175
return &internal.LinkPathResponse{
176176
Error: err.Error(),
177-
}, nil
177+
}, err
178178
}
179-
err = s.hostAPI.LinkPath(request.TargetPath, request.SourcePath)
179+
err = s.hostAPI.LinkPath(request.SourcePath, request.TargetPath)
180180
errString := ""
181181
if err != nil {
182182
errString = err.Error()
183183
}
184184
return &internal.LinkPathResponse{
185185
Error: errString,
186-
}, nil
186+
}, err
187187
}
188188

189189
func (s *Server) IsMountPoint(ctx context.Context, request *internal.IsMountPointRequest, version apiversion.Version) (*internal.IsMountPointResponse, error) {
@@ -192,10 +192,10 @@ func (s *Server) IsMountPoint(ctx context.Context, request *internal.IsMountPoin
192192
return &internal.IsMountPointResponse{
193193
IsMountPoint: false,
194194
Error: err.Error(),
195-
}, nil
195+
}, err
196196
}
197197
return &internal.IsMountPointResponse{
198198
Error: "",
199199
IsMountPoint: isMount,
200-
}, nil
200+
}, err
201201
}

0 commit comments

Comments
 (0)