@@ -22,20 +22,22 @@ import (
22
22
"fmt"
23
23
"os"
24
24
"path/filepath"
25
- "strconv"
26
25
"strings"
27
26
28
- diskapi "github.com/kubernetes-csi/csi-proxy/client/api/disk/v1"
29
- diskclient "github.com/kubernetes-csi/csi-proxy/client/groups/disk/v1"
27
+ // TODO(mauriciopoppe): these packages will become v1 if there are no more changes in the v1beta3 API,
28
+ // that's why this file it's called v1_windows.go even though it's still using v1beta3/v1beta2 APIs
30
29
31
- fsapi "github.com/kubernetes-csi/csi-proxy/client/api/filesystem/v1 "
32
- fsclient "github.com/kubernetes-csi/csi-proxy/client/groups/filesystem/v1 "
30
+ diskapi "github.com/kubernetes-csi/csi-proxy/client/api/disk/v1beta3 "
31
+ diskclient "github.com/kubernetes-csi/csi-proxy/client/groups/disk/v1beta3 "
33
32
34
- volumeapi "github.com/kubernetes-csi/csi-proxy/client/api/volume/v1"
35
- volumeclient "github.com/kubernetes-csi/csi-proxy/client/groups/volume/v1"
33
+ fsapi "github.com/kubernetes-csi/csi-proxy/client/api/filesystem/v1beta2"
34
+ fsclient "github.com/kubernetes-csi/csi-proxy/client/groups/filesystem/v1beta2"
35
+
36
+ volumeapi "github.com/kubernetes-csi/csi-proxy/client/api/volume/v1beta3"
37
+ volumeclient "github.com/kubernetes-csi/csi-proxy/client/groups/volume/v1beta3"
36
38
37
39
"k8s.io/klog"
38
- "k8s.io/utils/ mount"
40
+ mount "k8s.io/mount-utils "
39
41
)
40
42
41
43
var _ mount.Interface = & CSIProxyMounterV1 {}
@@ -66,6 +68,16 @@ func NewCSIProxyMounterV1() (*CSIProxyMounterV1, error) {
66
68
}, nil
67
69
}
68
70
71
+ // GetAPIVersions returns the versions of the client APIs this mounter is using.
72
+ func (mounter * CSIProxyMounterV1 ) GetAPIVersions () string {
73
+ return fmt .Sprintf (
74
+ "API Versions Disk: %s, Filesystem: %s, Volume: %s" ,
75
+ diskclient .Version ,
76
+ fsclient .Version ,
77
+ volumeclient .Version ,
78
+ )
79
+ }
80
+
69
81
// Mount just creates a soft link at target pointing to source.
70
82
func (mounter * CSIProxyMounterV1 ) Mount (source string , target string , fstype string , options []string ) error {
71
83
return mounter .MountSensitive (source , target , fstype , options , nil /* sensitiveOptions */ )
@@ -84,27 +96,23 @@ func (mounter *CSIProxyMounterV1) MountSensitive(source string, target string, f
84
96
if err := os .MkdirAll (parentDir , 0755 ); err != nil {
85
97
return err
86
98
}
87
- linkRequest := & fsapi.LinkPathRequest {
99
+ createSymlinkRequest := & fsapi.CreateSymlinkRequest {
88
100
SourcePath : mount .NormalizeWindowsPath (source ),
89
101
TargetPath : mount .NormalizeWindowsPath (target ),
90
102
}
91
- response , err := mounter .FsClient .LinkPath (context .Background (), linkRequest )
103
+ _ , err := mounter .FsClient .CreateSymlink (context .Background (), createSymlinkRequest )
92
104
if err != nil {
93
105
return err
94
106
}
95
- if response .Error != "" {
96
- return errors .New (response .Error )
97
- }
98
107
return nil
99
108
}
100
109
101
110
// Delete the given directory with Pod context. CSI proxy does a check for path prefix
102
111
// based on context
103
112
func (mounter * CSIProxyMounterV1 ) RemovePodDir (target string ) error {
104
113
rmdirRequest := & fsapi.RmdirRequest {
105
- Path : mount .NormalizeWindowsPath (target ),
106
- Context : fsapi .PathContext_POD ,
107
- Force : true ,
114
+ Path : mount .NormalizeWindowsPath (target ),
115
+ Force : true ,
108
116
}
109
117
_ , err := mounter .FsClient .Rmdir (context .Background (), rmdirRequest )
110
118
if err != nil {
@@ -122,48 +130,47 @@ func (mounter *CSIProxyMounterV1) UnmountDevice(target string) error {
122
130
if exists , err := mounter .ExistsPath (target ); ! exists {
123
131
return err
124
132
}
125
- idRequest := & volumeapi.VolumeIDFromMountRequest {
126
- Mount : target ,
133
+ idRequest := & volumeapi.GetVolumeIDFromTargetPathRequest {
134
+ TargetPath : target ,
127
135
}
128
- idResponse , err := mounter .VolumeClient .GetVolumeIDFromMount (context .Background (), idRequest )
136
+ idResponse , err := mounter .VolumeClient .GetVolumeIDFromTargetPath (context .Background (), idRequest )
129
137
if err != nil {
130
138
return err
131
139
}
132
140
volumeId := idResponse .GetVolumeId ()
133
141
134
- dismountRequest := & volumeapi.DismountVolumeRequest {
135
- Path : target ,
136
- VolumeId : volumeId ,
142
+ unmountRequest := & volumeapi.UnmountVolumeRequest {
143
+ TargetPath : target ,
144
+ VolumeId : volumeId ,
137
145
}
138
- _ , err = mounter .VolumeClient .DismountVolume (context .Background (), dismountRequest )
146
+ _ , err = mounter .VolumeClient .UnmountVolume (context .Background (), unmountRequest )
139
147
if err != nil {
140
148
return err
141
149
}
142
150
rmdirRequest := & fsapi.RmdirRequest {
143
- Path : target ,
144
- Context : fsapi .PathContext_PLUGIN ,
145
- Force : true ,
151
+ Path : target ,
152
+ Force : true ,
146
153
}
147
154
_ , err = mounter .FsClient .Rmdir (context .Background (), rmdirRequest )
148
155
if err != nil {
149
156
return err
150
157
}
151
158
152
159
// Set disk to offline mode to have a clean state
153
- getDiskNumberRequest := & volumeapi.VolumeDiskNumberRequest {
160
+ getDiskNumberRequest := & volumeapi.GetDiskNumberFromVolumeIDRequest {
154
161
VolumeId : volumeId ,
155
162
}
156
- id , err := mounter .VolumeClient .GetVolumeDiskNumber (context .Background (), getDiskNumberRequest )
163
+ getDiskNumberResponse , err := mounter .VolumeClient .GetDiskNumberFromVolumeID (context .Background (), getDiskNumberRequest )
157
164
if err != nil {
158
165
return err
159
166
}
160
- diskId := id .GetDiskNumber ()
161
- klog .V (4 ).Infof ("get disk number %d from volume %s" , diskId , volumeId )
162
- setDiskRequest := & diskapi.SetAttachStateRequest {
163
- DiskID : strconv . FormatInt ( diskId , 10 ) ,
164
- IsOnline : false ,
167
+ diskNumber := getDiskNumberResponse .GetDiskNumber ()
168
+ klog .V (4 ).Infof ("get disk number %d from volume %s" , diskNumber , volumeId )
169
+ setDiskStateRequest := & diskapi.SetDiskStateRequest {
170
+ DiskNumber : diskNumber ,
171
+ IsOnline : false ,
165
172
}
166
- if _ , err = mounter .DiskClient .SetAttachState (context .Background (), setDiskRequest ); err != nil {
173
+ if _ , err = mounter .DiskClient .SetDiskState (context .Background (), setDiskStateRequest ); err != nil {
167
174
return err
168
175
}
169
176
@@ -174,37 +181,36 @@ func (mounter *CSIProxyMounterV1) Unmount(target string) error {
174
181
return mounter .RemovePodDir (target )
175
182
}
176
183
177
- func (mounter * CSIProxyMounterV1 ) GetDevicePath (deviceName string , partition string , volumeKey string ) (string , error ) {
178
- id := "page83"
184
+ func (mounter * CSIProxyMounterV1 ) GetDevicePath (deviceName string , partition string , volumeKey string ) (uint32 , error ) {
179
185
listRequest := & diskapi.ListDiskIDsRequest {}
180
186
diskIDsResponse , err := mounter .DiskClient .ListDiskIDs (context .Background (), listRequest )
181
187
if err != nil {
182
- return "" , err
188
+ return 0 , err
183
189
}
184
190
diskIDsMap := diskIDsResponse .GetDiskIDs ()
185
191
for diskNum , diskInfo := range diskIDsMap {
186
- klog .V (4 ).Infof ("found disk number %s , disk info %v" , diskNum , diskInfo )
187
- idValue , found := diskInfo .Identifiers [ id ]
192
+ klog .V (4 ).Infof ("found disk number %d , disk info %v" , diskNum , diskInfo )
193
+ idValue := diskInfo .Page83
188
194
// The page83 id for gce pd has format of "Google pvc-xxxxxxx(the device name passed in here)"
189
- if ! found || idValue == "" {
195
+ if idValue == "" {
190
196
continue
191
197
}
192
- names := strings .Fields (idValue )
193
198
klog .V (4 ).Infof ("get page83 id %s" , idValue )
199
+ names := strings .Fields (idValue )
194
200
if names [len (names )- 1 ] == deviceName {
195
201
return diskNum , nil
196
202
}
197
203
}
198
- return "" , fmt .Errorf ("could not find disk number for device %s" , deviceName )
204
+ return 0 , fmt .Errorf ("could not find disk number for device %s" , deviceName )
199
205
200
206
}
201
207
202
208
// FormatAndMount accepts the source disk number, target path to mount, the fstype to format with and options to be used.
203
209
// After formatting, it will mount the disk to target path on the host
204
- func (mounter * CSIProxyMounterV1 ) FormatAndMount (source string , target string , fstype string , options []string ) error {
210
+ func (mounter * CSIProxyMounterV1 ) FormatAndMount (diskNumber uint32 , target string , fstype string , options []string ) error {
205
211
// Call PartitionDisk CSI proxy call to partition the disk and return the volume id
206
212
partionDiskRequest := & diskapi.PartitionDiskRequest {
207
- DiskID : source ,
213
+ DiskNumber : diskNumber ,
208
214
}
209
215
210
216
_ , err := mounter .DiskClient .PartitionDisk (context .Background (), partionDiskRequest )
@@ -213,17 +219,17 @@ func (mounter *CSIProxyMounterV1) FormatAndMount(source string, target string, f
213
219
}
214
220
215
221
// make sure disk is online. if disk is already online, this call should also succeed.
216
- setDiskRequest := & diskapi.SetAttachStateRequest {
217
- DiskID : source ,
218
- IsOnline : true ,
222
+ setDiskStateRequest := & diskapi.SetDiskStateRequest {
223
+ DiskNumber : diskNumber ,
224
+ IsOnline : true ,
219
225
}
220
- _ , err = mounter .DiskClient .SetAttachState (context .Background (), setDiskRequest )
226
+ _ , err = mounter .DiskClient .SetDiskState (context .Background (), setDiskStateRequest )
221
227
if err != nil {
222
228
return err
223
229
}
224
230
225
231
volumeIDsRequest := & volumeapi.ListVolumesOnDiskRequest {
226
- DiskId : source ,
232
+ DiskNumber : diskNumber ,
227
233
}
228
234
volumeIdResponse , err := mounter .VolumeClient .ListVolumesOnDisk (context .Background (), volumeIDsRequest )
229
235
if err != nil {
@@ -253,8 +259,8 @@ func (mounter *CSIProxyMounterV1) FormatAndMount(source string, target string, f
253
259
}
254
260
// Mount the volume by calling the CSI proxy call.
255
261
mountVolumeRequest := & volumeapi.MountVolumeRequest {
256
- VolumeId : volumeID ,
257
- Path : target ,
262
+ VolumeId : volumeID ,
263
+ TargetPath : target ,
258
264
}
259
265
_ , err = mounter .VolumeClient .MountVolume (context .Background (), mountVolumeRequest )
260
266
if err != nil {
@@ -268,16 +274,16 @@ func (mounter *CSIProxyMounterV1) GetMountRefs(pathname string) ([]string, error
268
274
}
269
275
270
276
func (mounter * CSIProxyMounterV1 ) IsLikelyNotMountPoint (file string ) (bool , error ) {
271
- isMountRequest := & fsapi.IsMountPointRequest {
277
+ isSymlinkRequest := & fsapi.IsSymlinkRequest {
272
278
Path : file ,
273
279
}
274
280
275
- isMountResponse , err := mounter .FsClient .IsMountPoint (context .Background (), isMountRequest )
281
+ isSymlinkResponse , err := mounter .FsClient .IsSymlink (context .Background (), isSymlinkRequest )
276
282
if err != nil {
277
283
return true , err
278
284
}
279
285
280
- return ! isMountResponse . IsMountPoint , nil
286
+ return ! isSymlinkResponse . IsSymlink , nil
281
287
}
282
288
283
289
func (mounter * CSIProxyMounterV1 ) List () ([]mount.MountPoint , error ) {
@@ -300,10 +306,16 @@ func (mounter *CSIProxyMounterV1) ExistsPath(path string) (bool, error) {
300
306
return isExistsResponse .Exists , err
301
307
}
302
308
303
- func (mounter * CSIProxyMounterV1 ) GetBlockSizeBytes (diskId string ) (int64 , error ) {
304
- DiskStatsResponse , err := mounter .DiskClient .DiskStats (context .Background (),
305
- & diskapi.DiskStatsRequest {
306
- DiskID : diskId ,
309
+ func (mounter * CSIProxyMounterV1 ) GetBlockSizeBytes (diskNumber uint32 ) (int64 , error ) {
310
+ DiskStatsResponse , err := mounter .DiskClient .GetDiskStats (context .Background (),
311
+ & diskapi.GetDiskStatsRequest {
312
+ DiskNumber : diskNumber ,
307
313
})
308
- return DiskStatsResponse .DiskSize , err
314
+ return DiskStatsResponse .TotalBytes , err
315
+ }
316
+
317
+ // MountSensitiveWithoutSystemd is the same as MountSensitive() but this method disable using systemd mount.
318
+ // It's unimplemented in PD CSI Driver
319
+ func (mounter * CSIProxyMounterV1 ) MountSensitiveWithoutSystemd (source string , target string , fstype string , options []string , sensitiveOptions []string ) error {
320
+ return errors .New ("MountSensitiveWithoutSystemd is not implemented" )
309
321
}
0 commit comments