@@ -22,38 +22,40 @@ import (
2222 "fmt"
2323 "os"
2424 "path/filepath"
25+ "strings"
2526
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 "
2829
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"
3132
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 "
3435
36+ "k8s.io/klog"
3537 utilexec "k8s.io/utils/exec"
3638 "k8s.io/utils/mount"
3739)
3840
3941var _ mount.Interface = & CSIProxyMounter {}
4042
4143type 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
4547}
4648
4749func NewCSIProxyMounter () (* CSIProxyMounter , error ) {
48- fsClient , err := fsclientv1alpha1 .NewClient ()
50+ fsClient , err := fsclient .NewClient ()
4951 if err != nil {
5052 return nil , err
5153 }
52- diskClient , err := diskclientv1alpha1 .NewClient ()
54+ diskClient , err := diskclient .NewClient ()
5355 if err != nil {
5456 return nil , err
5557 }
56- volumeClient , err := volumeclientv1alpha1 .NewClient ()
58+ volumeClient , err := volumeclient .NewClient ()
5759 if err != nil {
5860 return nil , err
5961 }
@@ -93,7 +95,7 @@ func (mounter *CSIProxyMounter) MountSensitive(source string, target string, fst
9395 if err := os .MkdirAll (parentDir , 0755 ); err != nil {
9496 return err
9597 }
96- linkRequest := & fsv1alpha1 .LinkPathRequest {
98+ linkRequest := & fsapi .LinkPathRequest {
9799 SourcePath : mount .NormalizeWindowsPath (source ),
98100 TargetPath : mount .NormalizeWindowsPath (target ),
99101 }
@@ -110,9 +112,9 @@ func (mounter *CSIProxyMounter) MountSensitive(source string, target string, fst
110112// Delete the given directory with Pod context. CSI proxy does a check for path prefix
111113// based on context
112114func (mounter * CSIProxyMounter ) RemovePodDir (target string ) error {
113- rmdirRequest := & fsv1alpha1 .RmdirRequest {
115+ rmdirRequest := & fsapi .RmdirRequest {
114116 Path : mount .NormalizeWindowsPath (target ),
115- Context : fsv1alpha1 .PathContext_POD ,
117+ Context : fsapi .PathContext_POD ,
116118 Force : true ,
117119 }
118120 _ , err := mounter .FsClient .Rmdir (context .Background (), rmdirRequest )
@@ -125,9 +127,9 @@ func (mounter *CSIProxyMounter) RemovePodDir(target string) error {
125127// Delete the given directory with plugin context. CSI proxy does a check for path prefix
126128// based on context
127129func (mounter * CSIProxyMounter ) RemovePluginDir (target string ) error {
128- rmdirRequest := & fsv1alpha1 .RmdirRequest {
130+ rmdirRequest := & fsapi .RmdirRequest {
129131 Path : mount .NormalizeWindowsPath (target ),
130- Context : fsv1alpha1 .PathContext_PLUGIN ,
132+ Context : fsapi .PathContext_PLUGIN ,
131133 Force : true ,
132134 }
133135 _ , err := mounter .FsClient .Rmdir (context .Background (), rmdirRequest )
@@ -142,30 +144,43 @@ func (mounter *CSIProxyMounter) Unmount(target string) error {
142144}
143145
144146func (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 )
149150 if err != nil {
150151 return "" , err
151152 }
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 )
153168
154169}
155170
156171// FormatAndMount accepts the source disk number, target path to mount, the fstype to format with and options to be used.
157172// After formatting, it will mount the disk to target path on the host
158173func (mounter * CSIProxyMounter ) FormatAndMount (source string , target string , fstype string , options []string ) error {
159174 // Call PartitionDisk CSI proxy call to partition the disk and return the volume id
160- partionDiskRequest := & diskv1alpha1 .PartitionDiskRequest {
175+ partionDiskRequest := & diskapi .PartitionDiskRequest {
161176 DiskID : source ,
162177 }
163178
164179 _ , err := mounter .DiskClient .PartitionDisk (context .Background (), partionDiskRequest )
165180 if err != nil {
166181 return err
167182 }
168- volumeIDsRequest := & volumev1alpha1 .ListVolumesOnDiskRequest {
183+ volumeIDsRequest := & volumeapi .ListVolumesOnDiskRequest {
169184 DiskId : source ,
170185 }
171186 volumeIdResponse , err := mounter .VolumeClient .ListVolumesOnDisk (context .Background (), volumeIDsRequest )
@@ -174,15 +189,15 @@ func (mounter *CSIProxyMounter) FormatAndMount(source string, target string, fst
174189 }
175190 // TODO: consider partitions and choose the right partition.
176191 volumeID := volumeIdResponse .VolumeIds [0 ]
177- isVolumeFormattedRequest := & volumev1alpha1 .IsVolumeFormattedRequest {
192+ isVolumeFormattedRequest := & volumeapi .IsVolumeFormattedRequest {
178193 VolumeId : volumeID ,
179194 }
180195 isVolumeFormattedResponse , err := mounter .VolumeClient .IsVolumeFormatted (context .Background (), isVolumeFormattedRequest )
181196 if err != nil {
182197 return err
183198 }
184199 if ! isVolumeFormattedResponse .Formatted {
185- formatVolumeRequest := & volumev1alpha1 .FormatVolumeRequest {
200+ formatVolumeRequest := & volumeapi .FormatVolumeRequest {
186201 VolumeId : volumeID ,
187202 // TODO (jingxu97): Accept the filesystem and other options
188203 }
@@ -192,7 +207,7 @@ func (mounter *CSIProxyMounter) FormatAndMount(source string, target string, fst
192207 }
193208 }
194209 // Mount the volume by calling the CSI proxy call.
195- mountVolumeRequest := & volumev1alpha1 .MountVolumeRequest {
210+ mountVolumeRequest := & volumeapi .MountVolumeRequest {
196211 VolumeId : volumeID ,
197212 Path : target ,
198213 }
@@ -208,7 +223,7 @@ func (mounter *CSIProxyMounter) GetMountRefs(pathname string) ([]string, error)
208223}
209224
210225func (mounter * CSIProxyMounter ) IsLikelyNotMountPoint (file string ) (bool , error ) {
211- isMountRequest := & fsv1alpha1 .IsMountPointRequest {
226+ isMountRequest := & fsapi .IsMountPointRequest {
212227 Path : file ,
213228 }
214229
@@ -231,7 +246,7 @@ func (mounter *CSIProxyMounter) IsMountPointMatch(mp mount.MountPoint, dir strin
231246// ExistsPath - Checks if a path exists. Unlike util ExistsPath, this call does not perform follow link.
232247func (mounter * CSIProxyMounter ) ExistsPath (path string ) (bool , error ) {
233248 isExistsResponse , err := mounter .FsClient .PathExists (context .Background (),
234- & fsv1alpha1 .PathExistsRequest {
249+ & fsapi .PathExistsRequest {
235250 Path : mount .NormalizeWindowsPath (path ),
236251 })
237252 return isExistsResponse .Exists , err
0 commit comments