Skip to content

Commit 63767a8

Browse files
committed
chore: refine CSIProxyMounter interface
1 parent 005a3a9 commit 63767a8

File tree

3 files changed

+74
-89
lines changed

3 files changed

+74
-89
lines changed

pkg/mounter/safe_mounter_v1beta_windows.go

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@ import (
3737
mount "k8s.io/mount-utils"
3838
)
3939

40-
var _ mount.Interface = &CSIProxyMounterV1Beta{}
40+
var _ CSIProxyMounter = &csiProxyMounter{}
4141

42-
type CSIProxyMounterV1Beta struct {
42+
type csiProxyMounterV1Beta struct {
4343
FsClient *fsclient.Client
4444
SMBClient *smbclient.Client
4545
}
4646

47-
func (mounter *CSIProxyMounterV1Beta) SMBMount(source, target, fsType string, mountOptions, sensitiveMountOptions []string) error {
47+
func (mounter *csiProxyMounterV1Beta) SMBMount(source, target, fsType string, mountOptions, sensitiveMountOptions []string) error {
4848
klog.V(4).Infof("SMBMount: remote path: %s. local path: %s", source, target)
4949

5050
if len(mountOptions) == 0 || len(sensitiveMountOptions) == 0 {
@@ -90,15 +90,15 @@ func (mounter *CSIProxyMounterV1Beta) SMBMount(source, target, fsType string, mo
9090
return nil
9191
}
9292

93-
func (mounter *CSIProxyMounterV1Beta) SMBUnmount(target string) error {
93+
func (mounter *csiProxyMounterV1Beta) SMBUnmount(target string) error {
9494
klog.V(4).Infof("SMBUnmount: local path: %s", target)
9595
// TODO: We need to remove the SMB mapping. The change to remove the
9696
// directory brings the CSI code in parity with the in-tree.
9797
return mounter.Rmdir(target)
9898
}
9999

100100
// Mount just creates a soft link at target pointing to source.
101-
func (mounter *CSIProxyMounterV1Beta) Mount(source string, target string, fstype string, options []string) error {
101+
func (mounter *csiProxyMounterV1Beta) Mount(source string, target string, fstype string, options []string) error {
102102
klog.V(4).Infof("Mount: old name: %s. new name: %s", source, target)
103103
// Mount is called after the format is done.
104104
// TODO: Confirm that fstype is empty.
@@ -117,7 +117,7 @@ func (mounter *CSIProxyMounterV1Beta) Mount(source string, target string, fstype
117117
// TODO: Call separate rmdir for pod context and plugin context. v1alpha1 for CSI
118118
// proxy does a relaxed check for prefix as c:\var\lib\kubelet, so we can do
119119
// rmdir with either pod or plugin context.
120-
func (mounter *CSIProxyMounterV1Beta) Rmdir(path string) error {
120+
func (mounter *csiProxyMounterV1Beta) Rmdir(path string) error {
121121
klog.V(4).Infof("Remove directory: %s", path)
122122
rmdirRequest := &fs.RmdirRequest{
123123
Path: normalizeWindowsPath(path),
@@ -132,23 +132,23 @@ func (mounter *CSIProxyMounterV1Beta) Rmdir(path string) error {
132132
}
133133

134134
// Unmount - Removes the directory - equivalent to unmount on Linux.
135-
func (mounter *CSIProxyMounterV1Beta) Unmount(target string) error {
135+
func (mounter *csiProxyMounterV1Beta) Unmount(target string) error {
136136
klog.V(4).Infof("Unmount: %s", target)
137137
return mounter.Rmdir(target)
138138
}
139139

140-
func (mounter *CSIProxyMounterV1Beta) List() ([]mount.MountPoint, error) {
140+
func (mounter *csiProxyMounterV1Beta) List() ([]mount.MountPoint, error) {
141141
return []mount.MountPoint{}, fmt.Errorf("List not implemented for CSIProxyMounterV1Beta")
142142
}
143143

144-
func (mounter *CSIProxyMounterV1Beta) IsMountPointMatch(mp mount.MountPoint, dir string) bool {
144+
func (mounter *csiProxyMounterV1Beta) IsMountPointMatch(mp mount.MountPoint, dir string) bool {
145145
return mp.Path == dir
146146
}
147147

148148
// IsLikelyMountPoint - If the directory does not exists, the function will return os.ErrNotExist error.
149149
// If the path exists, call to CSI proxy will check if its a link, if its a link then existence of target
150150
// path is checked.
151-
func (mounter *CSIProxyMounterV1Beta) IsLikelyNotMountPoint(path string) (bool, error) {
151+
func (mounter *csiProxyMounterV1Beta) IsLikelyNotMountPoint(path string) (bool, error) {
152152
klog.V(4).Infof("IsLikelyNotMountPoint: %s", path)
153153
isExists, err := mounter.ExistsPath(path)
154154
if err != nil {
@@ -168,30 +168,30 @@ func (mounter *CSIProxyMounterV1Beta) IsLikelyNotMountPoint(path string) (bool,
168168
return !response.IsMountPoint, nil
169169
}
170170

171-
func (mounter *CSIProxyMounterV1Beta) PathIsDevice(pathname string) (bool, error) {
171+
func (mounter *csiProxyMounterV1Beta) PathIsDevice(pathname string) (bool, error) {
172172
return false, fmt.Errorf("PathIsDevice not implemented for CSIProxyMounterV1Beta")
173173
}
174174

175-
func (mounter *CSIProxyMounterV1Beta) DeviceOpened(pathname string) (bool, error) {
175+
func (mounter *csiProxyMounterV1Beta) DeviceOpened(pathname string) (bool, error) {
176176
return false, fmt.Errorf("DeviceOpened not implemented for CSIProxyMounterV1Beta")
177177
}
178178

179-
func (mounter *CSIProxyMounterV1Beta) GetDeviceNameFromMount(mountPath, pluginMountDir string) (string, error) {
179+
func (mounter *csiProxyMounterV1Beta) GetDeviceNameFromMount(mountPath, pluginMountDir string) (string, error) {
180180
return "", fmt.Errorf("GetDeviceNameFromMount not implemented for CSIProxyMounterV1Beta")
181181
}
182182

183-
func (mounter *CSIProxyMounterV1Beta) MakeRShared(path string) error {
183+
func (mounter *csiProxyMounterV1Beta) MakeRShared(path string) error {
184184
return fmt.Errorf("MakeRShared not implemented for CSIProxyMounterV1Beta")
185185
}
186186

187-
func (mounter *CSIProxyMounterV1Beta) MakeFile(pathname string) error {
187+
func (mounter *csiProxyMounterV1Beta) MakeFile(pathname string) error {
188188
return fmt.Errorf("MakeFile not implemented for CSIProxyMounterV1Beta")
189189
}
190190

191191
// MakeDir - Creates a directory. The CSI proxy takes in context information.
192192
// Currently the make dir is only used from the staging code path, hence we call it
193193
// with Plugin context..
194-
func (mounter *CSIProxyMounterV1Beta) MakeDir(path string) error {
194+
func (mounter *csiProxyMounterV1Beta) MakeDir(path string) error {
195195
klog.V(4).Infof("Make directory: %s", path)
196196
mkdirReq := &fs.MkdirRequest{
197197
Path: normalizeWindowsPath(path),
@@ -206,7 +206,7 @@ func (mounter *CSIProxyMounterV1Beta) MakeDir(path string) error {
206206
}
207207

208208
// ExistsPath - Checks if a path exists. Unlike util ExistsPath, this call does not perform follow link.
209-
func (mounter *CSIProxyMounterV1Beta) ExistsPath(path string) (bool, error) {
209+
func (mounter *csiProxyMounterV1Beta) ExistsPath(path string) (bool, error) {
210210
klog.V(4).Infof("Exists path: %s", path)
211211
isExistsResponse, err := mounter.FsClient.PathExists(context.Background(),
212212
&fs.PathExistsRequest{
@@ -219,45 +219,45 @@ func (mounter *CSIProxyMounterV1Beta) ExistsPath(path string) (bool, error) {
219219
}
220220

221221
// GetAPIVersions returns the versions of the client APIs this mounter is using.
222-
func (mounter *CSIProxyMounterV1Beta) GetAPIVersions() string {
222+
func (mounter *csiProxyMounterV1Beta) GetAPIVersions() string {
223223
return fmt.Sprintf(
224224
"API Versions filesystem: %s, SMB: %s",
225225
fsclient.Version,
226226
smbclient.Version,
227227
)
228228
}
229229

230-
func (mounter *CSIProxyMounterV1Beta) EvalHostSymlinks(pathname string) (string, error) {
230+
func (mounter *csiProxyMounterV1Beta) EvalHostSymlinks(pathname string) (string, error) {
231231
return "", fmt.Errorf("EvalHostSymlinks not implemented for CSIProxyMounterV1Beta")
232232
}
233233

234-
func (mounter *CSIProxyMounterV1Beta) GetMountRefs(pathname string) ([]string, error) {
234+
func (mounter *csiProxyMounterV1Beta) GetMountRefs(pathname string) ([]string, error) {
235235
return []string{}, fmt.Errorf("GetMountRefs not implemented for CSIProxyMounterV1Beta")
236236
}
237237

238-
func (mounter *CSIProxyMounterV1Beta) GetFSGroup(pathname string) (int64, error) {
238+
func (mounter *csiProxyMounterV1Beta) GetFSGroup(pathname string) (int64, error) {
239239
return -1, fmt.Errorf("GetFSGroup not implemented for CSIProxyMounterV1Beta")
240240
}
241241

242-
func (mounter *CSIProxyMounterV1Beta) GetSELinuxSupport(pathname string) (bool, error) {
242+
func (mounter *csiProxyMounterV1Beta) GetSELinuxSupport(pathname string) (bool, error) {
243243
return false, fmt.Errorf("GetSELinuxSupport not implemented for CSIProxyMounterV1Beta")
244244
}
245245

246-
func (mounter *CSIProxyMounterV1Beta) GetMode(pathname string) (os.FileMode, error) {
246+
func (mounter *csiProxyMounterV1Beta) GetMode(pathname string) (os.FileMode, error) {
247247
return 0, fmt.Errorf("GetMode not implemented for CSIProxyMounterV1Beta")
248248
}
249249

250-
func (mounter *CSIProxyMounterV1Beta) MountSensitive(source string, target string, fstype string, options []string, sensitiveOptions []string) error {
250+
func (mounter *csiProxyMounterV1Beta) MountSensitive(source string, target string, fstype string, options []string, sensitiveOptions []string) error {
251251
return fmt.Errorf("MountSensitive not implemented for CSIProxyMounterV1Beta")
252252
}
253253

254-
func (mounter *CSIProxyMounterV1Beta) MountSensitiveWithoutSystemd(source string, target string, fstype string, options []string, sensitiveOptions []string) error {
254+
func (mounter *csiProxyMounterV1Beta) MountSensitiveWithoutSystemd(source string, target string, fstype string, options []string, sensitiveOptions []string) error {
255255
return fmt.Errorf("MountSensitiveWithoutSystemd not implemented for CSIProxyMounterV1Beta")
256256
}
257257

258258
// NewCSIProxyMounter - creates a new CSI Proxy mounter struct which encompassed all the
259259
// clients to the CSI proxy - filesystem, disk and volume clients.
260-
func NewCSIProxyMounterV1Beta() (*CSIProxyMounterV1Beta, error) {
260+
func NewCSIProxyMounterV1Beta() (*csiProxyMounterV1Beta, error) {
261261
fsClient, err := fsclient.NewClient()
262262
if err != nil {
263263
return nil, err
@@ -267,7 +267,7 @@ func NewCSIProxyMounterV1Beta() (*CSIProxyMounterV1Beta, error) {
267267
return nil, err
268268
}
269269

270-
return &CSIProxyMounterV1Beta{
270+
return &csiProxyMounterV1Beta{
271271
FsClient: fsClient,
272272
SMBClient: smbClient,
273273
}, nil

pkg/mounter/safe_mounter_windows.go

Lines changed: 41 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,23 @@ import (
3838
utilexec "k8s.io/utils/exec"
3939
)
4040

41-
var _ mount.Interface = &CSIProxyMounter{}
41+
// CSIProxyMounter extends the mount.Interface interface with CSI Proxy methods.
42+
type CSIProxyMounter interface {
43+
mount.Interface
44+
45+
SMBMount(source, target, fsType string, mountOptions, sensitiveMountOptions []string) error
46+
SMBUnmount(target string) error
47+
MakeDir(path string) error
48+
Rmdir(path string) error
49+
IsMountPointMatch(mp mount.MountPoint, dir string) bool
50+
ExistsPath(path string) (bool, error)
51+
GetAPIVersions() string
52+
EvalHostSymlinks(pathname string) (string, error)
53+
}
54+
55+
var _ CSIProxyMounter = &csiProxyMounter{}
4256

43-
type CSIProxyMounter struct {
57+
type csiProxyMounter struct {
4458
FsClient *fsclient.Client
4559
SMBClient *smbclient.Client
4660
}
@@ -53,7 +67,7 @@ func normalizeWindowsPath(path string) string {
5367
return normalizedPath
5468
}
5569

56-
func (mounter *CSIProxyMounter) SMBMount(source, target, fsType string, mountOptions, sensitiveMountOptions []string) error {
70+
func (mounter *csiProxyMounter) SMBMount(source, target, fsType string, mountOptions, sensitiveMountOptions []string) error {
5771
klog.V(4).Infof("SMBMount: remote path: %s. local path: %s", source, target)
5872

5973
if len(mountOptions) == 0 || len(sensitiveMountOptions) == 0 {
@@ -99,15 +113,15 @@ func (mounter *CSIProxyMounter) SMBMount(source, target, fsType string, mountOpt
99113
return nil
100114
}
101115

102-
func (mounter *CSIProxyMounter) SMBUnmount(target string) error {
116+
func (mounter *csiProxyMounter) SMBUnmount(target string) error {
103117
klog.V(4).Infof("SMBUnmount: local path: %s", target)
104118
// TODO: We need to remove the SMB mapping. The change to remove the
105119
// directory brings the CSI code in parity with the in-tree.
106120
return mounter.Rmdir(target)
107121
}
108122

109123
// Mount just creates a soft link at target pointing to source.
110-
func (mounter *CSIProxyMounter) Mount(source string, target string, fstype string, options []string) error {
124+
func (mounter *csiProxyMounter) Mount(source string, target string, fstype string, options []string) error {
111125
klog.V(4).Infof("Mount: old name: %s. new name: %s", source, target)
112126
// Mount is called after the format is done.
113127
// TODO: Confirm that fstype is empty.
@@ -130,7 +144,7 @@ func Split(r rune) bool {
130144
// TODO: Call separate rmdir for pod context and plugin context. v1alpha1 for CSI
131145
// proxy does a relaxed check for prefix as c:\var\lib\kubelet, so we can do
132146
// rmdir with either pod or plugin context.
133-
func (mounter *CSIProxyMounter) Rmdir(path string) error {
147+
func (mounter *csiProxyMounter) Rmdir(path string) error {
134148
klog.V(4).Infof("Remove directory: %s", path)
135149
rmdirRequest := &fs.RmdirRequest{
136150
Path: normalizeWindowsPath(path),
@@ -144,23 +158,23 @@ func (mounter *CSIProxyMounter) Rmdir(path string) error {
144158
}
145159

146160
// Unmount - Removes the directory - equivalent to unmount on Linux.
147-
func (mounter *CSIProxyMounter) Unmount(target string) error {
161+
func (mounter *csiProxyMounter) Unmount(target string) error {
148162
klog.V(4).Infof("Unmount: %s", target)
149163
return mounter.Rmdir(target)
150164
}
151165

152-
func (mounter *CSIProxyMounter) List() ([]mount.MountPoint, error) {
166+
func (mounter *csiProxyMounter) List() ([]mount.MountPoint, error) {
153167
return []mount.MountPoint{}, fmt.Errorf("List not implemented for CSIProxyMounter")
154168
}
155169

156-
func (mounter *CSIProxyMounter) IsMountPointMatch(mp mount.MountPoint, dir string) bool {
170+
func (mounter *csiProxyMounter) IsMountPointMatch(mp mount.MountPoint, dir string) bool {
157171
return mp.Path == dir
158172
}
159173

160174
// IsLikelyMountPoint - If the directory does not exists, the function will return os.ErrNotExist error.
161175
// If the path exists, call to CSI proxy will check if its a link, if its a link then existence of target
162176
// path is checked.
163-
func (mounter *CSIProxyMounter) IsLikelyNotMountPoint(path string) (bool, error) {
177+
func (mounter *csiProxyMounter) IsLikelyNotMountPoint(path string) (bool, error) {
164178
klog.V(4).Infof("IsLikelyNotMountPoint: %s", path)
165179
isExists, err := mounter.ExistsPath(path)
166180
if err != nil {
@@ -180,30 +194,30 @@ func (mounter *CSIProxyMounter) IsLikelyNotMountPoint(path string) (bool, error)
180194
return !response.IsSymlink, nil
181195
}
182196

183-
func (mounter *CSIProxyMounter) PathIsDevice(pathname string) (bool, error) {
197+
func (mounter *csiProxyMounter) PathIsDevice(pathname string) (bool, error) {
184198
return false, fmt.Errorf("PathIsDevice not implemented for CSIProxyMounter")
185199
}
186200

187-
func (mounter *CSIProxyMounter) DeviceOpened(pathname string) (bool, error) {
201+
func (mounter *csiProxyMounter) DeviceOpened(pathname string) (bool, error) {
188202
return false, fmt.Errorf("DeviceOpened not implemented for CSIProxyMounter")
189203
}
190204

191-
func (mounter *CSIProxyMounter) GetDeviceNameFromMount(mountPath, pluginMountDir string) (string, error) {
205+
func (mounter *csiProxyMounter) GetDeviceNameFromMount(mountPath, pluginMountDir string) (string, error) {
192206
return "", fmt.Errorf("GetDeviceNameFromMount not implemented for CSIProxyMounter")
193207
}
194208

195-
func (mounter *CSIProxyMounter) MakeRShared(path string) error {
209+
func (mounter *csiProxyMounter) MakeRShared(path string) error {
196210
return fmt.Errorf("MakeRShared not implemented for CSIProxyMounter")
197211
}
198212

199-
func (mounter *CSIProxyMounter) MakeFile(pathname string) error {
213+
func (mounter *csiProxyMounter) MakeFile(pathname string) error {
200214
return fmt.Errorf("MakeFile not implemented for CSIProxyMounter")
201215
}
202216

203217
// MakeDir - Creates a directory. The CSI proxy takes in context information.
204218
// Currently the make dir is only used from the staging code path, hence we call it
205219
// with Plugin context..
206-
func (mounter *CSIProxyMounter) MakeDir(path string) error {
220+
func (mounter *csiProxyMounter) MakeDir(path string) error {
207221
klog.V(4).Infof("Make directory: %s", path)
208222
mkdirReq := &fs.MkdirRequest{
209223
Path: normalizeWindowsPath(path),
@@ -217,7 +231,7 @@ func (mounter *CSIProxyMounter) MakeDir(path string) error {
217231
}
218232

219233
// ExistsPath - Checks if a path exists. Unlike util ExistsPath, this call does not perform follow link.
220-
func (mounter *CSIProxyMounter) ExistsPath(path string) (bool, error) {
234+
func (mounter *csiProxyMounter) ExistsPath(path string) (bool, error) {
221235
klog.V(4).Infof("Exists path: %s", path)
222236
isExistsResponse, err := mounter.FsClient.PathExists(context.Background(),
223237
&fs.PathExistsRequest{
@@ -230,45 +244,45 @@ func (mounter *CSIProxyMounter) ExistsPath(path string) (bool, error) {
230244
}
231245

232246
// GetAPIVersions returns the versions of the client APIs this mounter is using.
233-
func (mounter *CSIProxyMounter) GetAPIVersions() string {
247+
func (mounter *csiProxyMounter) GetAPIVersions() string {
234248
return fmt.Sprintf(
235249
"API Versions filesystem: %s, SMB: %s",
236250
fsclient.Version,
237251
smbclient.Version,
238252
)
239253
}
240254

241-
func (mounter *CSIProxyMounter) EvalHostSymlinks(pathname string) (string, error) {
255+
func (mounter *csiProxyMounter) EvalHostSymlinks(pathname string) (string, error) {
242256
return "", fmt.Errorf("EvalHostSymlinks not implemented for CSIProxyMounter")
243257
}
244258

245-
func (mounter *CSIProxyMounter) GetMountRefs(pathname string) ([]string, error) {
259+
func (mounter *csiProxyMounter) GetMountRefs(pathname string) ([]string, error) {
246260
return []string{}, fmt.Errorf("GetMountRefs not implemented for CSIProxyMounter")
247261
}
248262

249-
func (mounter *CSIProxyMounter) GetFSGroup(pathname string) (int64, error) {
263+
func (mounter *csiProxyMounter) GetFSGroup(pathname string) (int64, error) {
250264
return -1, fmt.Errorf("GetFSGroup not implemented for CSIProxyMounter")
251265
}
252266

253-
func (mounter *CSIProxyMounter) GetSELinuxSupport(pathname string) (bool, error) {
267+
func (mounter *csiProxyMounter) GetSELinuxSupport(pathname string) (bool, error) {
254268
return false, fmt.Errorf("GetSELinuxSupport not implemented for CSIProxyMounter")
255269
}
256270

257-
func (mounter *CSIProxyMounter) GetMode(pathname string) (os.FileMode, error) {
271+
func (mounter *csiProxyMounter) GetMode(pathname string) (os.FileMode, error) {
258272
return 0, fmt.Errorf("GetMode not implemented for CSIProxyMounter")
259273
}
260274

261-
func (mounter *CSIProxyMounter) MountSensitive(source string, target string, fstype string, options []string, sensitiveOptions []string) error {
275+
func (mounter *csiProxyMounter) MountSensitive(source string, target string, fstype string, options []string, sensitiveOptions []string) error {
262276
return fmt.Errorf("MountSensitive not implemented for CSIProxyMounter")
263277
}
264278

265-
func (mounter *CSIProxyMounter) MountSensitiveWithoutSystemd(source string, target string, fstype string, options []string, sensitiveOptions []string) error {
279+
func (mounter *csiProxyMounter) MountSensitiveWithoutSystemd(source string, target string, fstype string, options []string, sensitiveOptions []string) error {
266280
return fmt.Errorf("MountSensitiveWithoutSystemd not implemented for CSIProxyMounter")
267281
}
268282

269283
// NewCSIProxyMounter - creates a new CSI Proxy mounter struct which encompassed all the
270284
// clients to the CSI proxy - filesystem, disk and volume clients.
271-
func NewCSIProxyMounter() (*CSIProxyMounter, error) {
285+
func NewCSIProxyMounter() (*csiProxyMounter, error) {
272286
fsClient, err := fsclient.NewClient()
273287
if err != nil {
274288
return nil, err
@@ -278,7 +292,7 @@ func NewCSIProxyMounter() (*CSIProxyMounter, error) {
278292
return nil, err
279293
}
280294

281-
return &CSIProxyMounter{
295+
return &csiProxyMounter{
282296
FsClient: fsClient,
283297
SMBClient: smbClient,
284298
}, nil

0 commit comments

Comments
 (0)