@@ -22,38 +22,40 @@ import (
22
22
"fmt"
23
23
"os"
24
24
"path/filepath"
25
+ "strings"
25
26
26
- diskv1alpha1 "github.com/kubernetes-csi/csi-proxy/client/api/disk/v1alpha1 "
27
- diskclientv1alpha1 "github.com/kubernetes-csi/csi-proxy/client/groups/disk/v1alpha1 "
27
+ diskapi "github.com/kubernetes-csi/csi-proxy/client/api/disk/v1beta1 "
28
+ diskclient "github.com/kubernetes-csi/csi-proxy/client/groups/disk/v1beta1 "
28
29
29
- fsv1alpha1 "github.com/kubernetes-csi/csi-proxy/client/api/filesystem/v1alpha1"
30
- fsclientv1alpha1 "github.com/kubernetes-csi/csi-proxy/client/groups/filesystem/v1alpha1"
30
+ fsapi "github.com/kubernetes-csi/csi-proxy/client/api/filesystem/v1alpha1"
31
+ fsclient "github.com/kubernetes-csi/csi-proxy/client/groups/filesystem/v1alpha1"
31
32
32
- volumev1alpha1 "github.com/kubernetes-csi/csi-proxy/client/api/volume/v1alpha1 "
33
- volumeclientv1alpha1 "github.com/kubernetes-csi/csi-proxy/client/groups/volume/v1alpha1 "
33
+ volumeapi "github.com/kubernetes-csi/csi-proxy/client/api/volume/v1beta1 "
34
+ volumeclient "github.com/kubernetes-csi/csi-proxy/client/groups/volume/v1beta1 "
34
35
36
+ "k8s.io/klog"
35
37
utilexec "k8s.io/utils/exec"
36
38
"k8s.io/utils/mount"
37
39
)
38
40
39
41
var _ mount.Interface = & CSIProxyMounter {}
40
42
41
43
type CSIProxyMounter struct {
42
- FsClient * fsclientv1alpha1 .Client
43
- DiskClient * diskclientv1alpha1 .Client
44
- VolumeClient * volumeclientv1alpha1 .Client
44
+ FsClient * fsclient .Client
45
+ DiskClient * diskclient .Client
46
+ VolumeClient * volumeclient .Client
45
47
}
46
48
47
49
func NewCSIProxyMounter () (* CSIProxyMounter , error ) {
48
- fsClient , err := fsclientv1alpha1 .NewClient ()
50
+ fsClient , err := fsclient .NewClient ()
49
51
if err != nil {
50
52
return nil , err
51
53
}
52
- diskClient , err := diskclientv1alpha1 .NewClient ()
54
+ diskClient , err := diskclient .NewClient ()
53
55
if err != nil {
54
56
return nil , err
55
57
}
56
- volumeClient , err := volumeclientv1alpha1 .NewClient ()
58
+ volumeClient , err := volumeclient .NewClient ()
57
59
if err != nil {
58
60
return nil , err
59
61
}
@@ -93,7 +95,7 @@ func (mounter *CSIProxyMounter) MountSensitive(source string, target string, fst
93
95
if err := os .MkdirAll (parentDir , 0755 ); err != nil {
94
96
return err
95
97
}
96
- linkRequest := & fsv1alpha1 .LinkPathRequest {
98
+ linkRequest := & fsapi .LinkPathRequest {
97
99
SourcePath : mount .NormalizeWindowsPath (source ),
98
100
TargetPath : mount .NormalizeWindowsPath (target ),
99
101
}
@@ -110,9 +112,9 @@ func (mounter *CSIProxyMounter) MountSensitive(source string, target string, fst
110
112
// Delete the given directory with Pod context. CSI proxy does a check for path prefix
111
113
// based on context
112
114
func (mounter * CSIProxyMounter ) RemovePodDir (target string ) error {
113
- rmdirRequest := & fsv1alpha1 .RmdirRequest {
115
+ rmdirRequest := & fsapi .RmdirRequest {
114
116
Path : mount .NormalizeWindowsPath (target ),
115
- Context : fsv1alpha1 .PathContext_POD ,
117
+ Context : fsapi .PathContext_POD ,
116
118
Force : true ,
117
119
}
118
120
_ , err := mounter .FsClient .Rmdir (context .Background (), rmdirRequest )
@@ -125,9 +127,9 @@ func (mounter *CSIProxyMounter) RemovePodDir(target string) error {
125
127
// Delete the given directory with plugin context. CSI proxy does a check for path prefix
126
128
// based on context
127
129
func (mounter * CSIProxyMounter ) RemovePluginDir (target string ) error {
128
- rmdirRequest := & fsv1alpha1 .RmdirRequest {
130
+ rmdirRequest := & fsapi .RmdirRequest {
129
131
Path : mount .NormalizeWindowsPath (target ),
130
- Context : fsv1alpha1 .PathContext_PLUGIN ,
132
+ Context : fsapi .PathContext_PLUGIN ,
131
133
Force : true ,
132
134
}
133
135
_ , err := mounter .FsClient .Rmdir (context .Background (), rmdirRequest )
@@ -142,30 +144,43 @@ func (mounter *CSIProxyMounter) Unmount(target string) error {
142
144
}
143
145
144
146
func (mounter * CSIProxyMounter ) GetDevicePath (deviceName string , partition string , volumeKey string ) (string , error ) {
145
- getDiskNumberRequest := & diskv1alpha1.GetDiskNumberByNameRequest {
146
- DiskName : deviceName ,
147
- }
148
- getDiskNumberResponse , err := mounter .DiskClient .GetDiskNumberByName (context .Background (), getDiskNumberRequest )
147
+ id := "page83"
148
+ listRequest := & diskapi.ListDiskIDsRequest {}
149
+ diskIDsResponse , err := mounter .DiskClient .ListDiskIDs (context .Background (), listRequest )
149
150
if err != nil {
150
151
return "" , err
151
152
}
152
- return getDiskNumberResponse .DiskNumber , nil
153
+ diskIDsMap := diskIDsResponse .GetDiskIDs ()
154
+ for diskNum , diskInfo := range diskIDsMap {
155
+ klog .V (4 ).Infof ("found disk number %s, disk info %v" , diskNum , diskInfo )
156
+ idValue , found := diskInfo .Identifiers [id ]
157
+ // The page83 id for gce pd has format of "Google pvc-xxxxxxx(the device name passed in here)"
158
+ if ! found || idValue == "" {
159
+ continue
160
+ }
161
+ names := strings .Fields (idValue )
162
+ klog .V (4 ).Infof ("get page83 id %s" , idValue )
163
+ if names [len (names )- 1 ] == deviceName {
164
+ return diskNum , nil
165
+ }
166
+ }
167
+ return "" , fmt .Errorf ("could not find disk number for device %s" , deviceName )
153
168
154
169
}
155
170
156
171
// FormatAndMount accepts the source disk number, target path to mount, the fstype to format with and options to be used.
157
172
// After formatting, it will mount the disk to target path on the host
158
173
func (mounter * CSIProxyMounter ) FormatAndMount (source string , target string , fstype string , options []string ) error {
159
174
// Call PartitionDisk CSI proxy call to partition the disk and return the volume id
160
- partionDiskRequest := & diskv1alpha1 .PartitionDiskRequest {
175
+ partionDiskRequest := & diskapi .PartitionDiskRequest {
161
176
DiskID : source ,
162
177
}
163
178
164
179
_ , err := mounter .DiskClient .PartitionDisk (context .Background (), partionDiskRequest )
165
180
if err != nil {
166
181
return err
167
182
}
168
- volumeIDsRequest := & volumev1alpha1 .ListVolumesOnDiskRequest {
183
+ volumeIDsRequest := & volumeapi .ListVolumesOnDiskRequest {
169
184
DiskId : source ,
170
185
}
171
186
volumeIdResponse , err := mounter .VolumeClient .ListVolumesOnDisk (context .Background (), volumeIDsRequest )
@@ -174,15 +189,15 @@ func (mounter *CSIProxyMounter) FormatAndMount(source string, target string, fst
174
189
}
175
190
// TODO: consider partitions and choose the right partition.
176
191
volumeID := volumeIdResponse .VolumeIds [0 ]
177
- isVolumeFormattedRequest := & volumev1alpha1 .IsVolumeFormattedRequest {
192
+ isVolumeFormattedRequest := & volumeapi .IsVolumeFormattedRequest {
178
193
VolumeId : volumeID ,
179
194
}
180
195
isVolumeFormattedResponse , err := mounter .VolumeClient .IsVolumeFormatted (context .Background (), isVolumeFormattedRequest )
181
196
if err != nil {
182
197
return err
183
198
}
184
199
if ! isVolumeFormattedResponse .Formatted {
185
- formatVolumeRequest := & volumev1alpha1 .FormatVolumeRequest {
200
+ formatVolumeRequest := & volumeapi .FormatVolumeRequest {
186
201
VolumeId : volumeID ,
187
202
// TODO (jingxu97): Accept the filesystem and other options
188
203
}
@@ -192,7 +207,7 @@ func (mounter *CSIProxyMounter) FormatAndMount(source string, target string, fst
192
207
}
193
208
}
194
209
// Mount the volume by calling the CSI proxy call.
195
- mountVolumeRequest := & volumev1alpha1 .MountVolumeRequest {
210
+ mountVolumeRequest := & volumeapi .MountVolumeRequest {
196
211
VolumeId : volumeID ,
197
212
Path : target ,
198
213
}
@@ -208,7 +223,7 @@ func (mounter *CSIProxyMounter) GetMountRefs(pathname string) ([]string, error)
208
223
}
209
224
210
225
func (mounter * CSIProxyMounter ) IsLikelyNotMountPoint (file string ) (bool , error ) {
211
- isMountRequest := & fsv1alpha1 .IsMountPointRequest {
226
+ isMountRequest := & fsapi .IsMountPointRequest {
212
227
Path : file ,
213
228
}
214
229
@@ -231,7 +246,7 @@ func (mounter *CSIProxyMounter) IsMountPointMatch(mp mount.MountPoint, dir strin
231
246
// ExistsPath - Checks if a path exists. Unlike util ExistsPath, this call does not perform follow link.
232
247
func (mounter * CSIProxyMounter ) ExistsPath (path string ) (bool , error ) {
233
248
isExistsResponse , err := mounter .FsClient .PathExists (context .Background (),
234
- & fsv1alpha1 .PathExistsRequest {
249
+ & fsapi .PathExistsRequest {
235
250
Path : mount .NormalizeWindowsPath (path ),
236
251
})
237
252
return isExistsResponse .Exists , err
0 commit comments