@@ -28,12 +28,12 @@ import (
28
28
csi "github.com/container-storage-interface/spec/lib/go/csi"
29
29
30
30
"k8s.io/klog"
31
- "k8s.io/kubernetes/pkg/util/mount"
32
- "k8s.io/kubernetes/pkg/util/resizefs"
31
+ "k8s.io/utils/mount"
33
32
34
33
"sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/pkg/common"
35
34
metadataservice "sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/pkg/gce-cloud-provider/metadata"
36
35
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"
37
37
)
38
38
39
39
type GCENodeServer struct {
@@ -130,7 +130,7 @@ func (ns *GCENodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePub
130
130
131
131
sourcePath = stagingTargetPath
132
132
133
- if err := ns . Mounter . Interface . MakeDir (targetPath ); err != nil {
133
+ if err := os . MkdirAll (targetPath , 0750 ); err != nil {
134
134
return nil , status .Error (codes .Internal , fmt .Sprintf ("mkdir failed on disk %s (%v)" , targetPath , err ))
135
135
}
136
136
} else if blk := volumeCapability .GetBlock (); blk != nil {
@@ -147,7 +147,7 @@ func (ns *GCENodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePub
147
147
}
148
148
149
149
// Expose block volume as file at target path
150
- err = ns . Mounter . MakeFile (targetPath )
150
+ err = makeFile (targetPath )
151
151
if err != nil {
152
152
if removeErr := os .Remove (targetPath ); removeErr != nil {
153
153
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
190
190
return & csi.NodePublishVolumeResponse {}, nil
191
191
}
192
192
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
+
193
205
func (ns * GCENodeServer ) NodeUnpublishVolume (ctx context.Context , req * csi.NodeUnpublishVolumeRequest ) (* csi.NodeUnpublishVolumeResponse , error ) {
194
206
// Validate Arguments
195
207
targetPath := req .GetTargetPath ()
@@ -264,7 +276,7 @@ func (ns *GCENodeServer) NodeStageVolume(ctx context.Context, req *csi.NodeStage
264
276
notMnt , err := ns .Mounter .Interface .IsLikelyNotMountPoint (stagingTargetPath )
265
277
if err != nil {
266
278
if os .IsNotExist (err ) {
267
- if err := ns . Mounter . Interface . MakeDir (stagingTargetPath ); err != nil {
279
+ if err := os . MkdirAll (stagingTargetPath , 0750 ); err != nil {
268
280
return nil , status .Error (codes .Internal , fmt .Sprintf ("Failed to create directory (%q): %v" , stagingTargetPath , err ))
269
281
}
270
282
notMnt = true
@@ -371,13 +383,13 @@ func (ns *GCENodeServer) NodeGetVolumeStats(ctx context.Context, req *csi.NodeGe
371
383
return nil , status .Error (codes .InvalidArgument , "NodeGetVolumeStats volume path was empty" )
372
384
}
373
385
374
- exists , err := ns . Mounter . Interface . ExistsPath (req .VolumePath )
386
+ _ , err := os . Stat (req .VolumePath )
375
387
if err != nil {
388
+ if os .IsNotExist (err ) {
389
+ return nil , status .Errorf (codes .NotFound , "path %s does not exist" , req .VolumePath )
390
+ }
376
391
return nil , status .Errorf (codes .Internal , "unknown error when stat on %s: %v" , req .VolumePath , err )
377
392
}
378
- if ! exists {
379
- return nil , status .Errorf (codes .NotFound , "path %s does not exist" , req .VolumePath )
380
- }
381
393
382
394
isBlock , err := ns .VolumeStatter .IsBlockDevice (req .VolumePath )
383
395
if err != nil {
@@ -528,14 +540,14 @@ func (ns *GCENodeServer) getDevicePath(volumeID string, partition string) (strin
528
540
}
529
541
530
542
func (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 ( )
532
544
if err != nil {
533
545
return - 1 , fmt .Errorf ("error when getting size of block volume at path %s: output: %s, err: %v" , devicePath , string (output ), err )
534
546
}
535
547
strOut := strings .TrimSpace (string (output ))
536
548
gotSizeBytes , err := strconv .ParseInt (strOut , 10 , 64 )
537
549
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 )
539
551
}
540
552
return gotSizeBytes , nil
541
553
}
0 commit comments