@@ -28,12 +28,12 @@ import (
2828 csi "github.com/container-storage-interface/spec/lib/go/csi"
2929
3030 "k8s.io/klog"
31- "k8s.io/kubernetes/pkg/util/mount"
32- "k8s.io/kubernetes/pkg/util/resizefs"
31+ "k8s.io/utils/mount"
3332
3433 "sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/pkg/common"
3534 metadataservice "sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/pkg/gce-cloud-provider/metadata"
3635 mountmanager "sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/pkg/mount-manager"
36+ "sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/pkg/resizefs"
3737)
3838
3939type GCENodeServer struct {
@@ -130,7 +130,7 @@ func (ns *GCENodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePub
130130
131131 sourcePath = stagingTargetPath
132132
133- if err := ns . Mounter . Interface . MakeDir (targetPath ); err != nil {
133+ if err := os . MkdirAll (targetPath , 0750 ); err != nil {
134134 return nil , status .Error (codes .Internal , fmt .Sprintf ("mkdir failed on disk %s (%v)" , targetPath , err ))
135135 }
136136 } else if blk := volumeCapability .GetBlock (); blk != nil {
@@ -147,7 +147,7 @@ func (ns *GCENodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePub
147147 }
148148
149149 // Expose block volume as file at target path
150- err = ns . Mounter . MakeFile (targetPath )
150+ err = makeFile (targetPath )
151151 if err != nil {
152152 if removeErr := os .Remove (targetPath ); removeErr != nil {
153153 return nil , status .Error (codes .Internal , fmt .Sprintf ("Error removing block file at target path %v: %v, mounti error: %v" , targetPath , removeErr , err ))
@@ -190,6 +190,18 @@ func (ns *GCENodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePub
190190 return & csi.NodePublishVolumeResponse {}, nil
191191}
192192
193+ func makeFile (path string ) error {
194+ // Create file
195+ newFile , err := os .OpenFile (path , os .O_CREATE | os .O_RDWR , 0750 )
196+ if err != nil {
197+ return fmt .Errorf ("failed to open file %s: %v" , path , err )
198+ }
199+ if err := newFile .Close (); err != nil {
200+ return fmt .Errorf ("failed to close file %s: %v" , path , err )
201+ }
202+ return nil
203+ }
204+
193205func (ns * GCENodeServer ) NodeUnpublishVolume (ctx context.Context , req * csi.NodeUnpublishVolumeRequest ) (* csi.NodeUnpublishVolumeResponse , error ) {
194206 // Validate Arguments
195207 targetPath := req .GetTargetPath ()
@@ -264,7 +276,7 @@ func (ns *GCENodeServer) NodeStageVolume(ctx context.Context, req *csi.NodeStage
264276 notMnt , err := ns .Mounter .Interface .IsLikelyNotMountPoint (stagingTargetPath )
265277 if err != nil {
266278 if os .IsNotExist (err ) {
267- if err := ns . Mounter . Interface . MakeDir (stagingTargetPath ); err != nil {
279+ if err := os . MkdirAll (stagingTargetPath , 0750 ); err != nil {
268280 return nil , status .Error (codes .Internal , fmt .Sprintf ("Failed to create directory (%q): %v" , stagingTargetPath , err ))
269281 }
270282 notMnt = true
@@ -371,13 +383,13 @@ func (ns *GCENodeServer) NodeGetVolumeStats(ctx context.Context, req *csi.NodeGe
371383 return nil , status .Error (codes .InvalidArgument , "NodeGetVolumeStats volume path was empty" )
372384 }
373385
374- exists , err := ns . Mounter . Interface . ExistsPath (req .VolumePath )
386+ _ , err := os . Stat (req .VolumePath )
375387 if err != nil {
388+ if os .IsNotExist (err ) {
389+ return nil , status .Errorf (codes .NotFound , "path %s does not exist" , req .VolumePath )
390+ }
376391 return nil , status .Errorf (codes .Internal , "unknown error when stat on %s: %v" , req .VolumePath , err )
377392 }
378- if ! exists {
379- return nil , status .Errorf (codes .NotFound , "path %s does not exist" , req .VolumePath )
380- }
381393
382394 isBlock , err := ns .VolumeStatter .IsBlockDevice (req .VolumePath )
383395 if err != nil {
@@ -528,14 +540,14 @@ func (ns *GCENodeServer) getDevicePath(volumeID string, partition string) (strin
528540}
529541
530542func (ns * GCENodeServer ) getBlockSizeBytes (devicePath string ) (int64 , error ) {
531- output , err := ns .Mounter .Exec .Run ("blockdev" , "--getsize64" , devicePath )
543+ output , err := ns .Mounter .Exec .Command ("blockdev" , "--getsize64" , devicePath ). CombinedOutput ( )
532544 if err != nil {
533545 return - 1 , fmt .Errorf ("error when getting size of block volume at path %s: output: %s, err: %v" , devicePath , string (output ), err )
534546 }
535547 strOut := strings .TrimSpace (string (output ))
536548 gotSizeBytes , err := strconv .ParseInt (strOut , 10 , 64 )
537549 if err != nil {
538- return - 1 , fmt .Errorf ("failed to parse size %s into int a size" , strOut )
550+ return - 1 , fmt .Errorf ("failed to parse %s into an int size" , strOut )
539551 }
540552 return gotSizeBytes , nil
541553}
0 commit comments