@@ -211,13 +211,12 @@ func chooseAttachAction(disk *ecs.Disk, instanceID string) (attachAction, error)
211211// Returns device path if fromNode, disk serial number otherwise.
212212func (ad * DiskAttachDetach ) attachDisk (ctx context.Context , diskID , nodeID string , fromNode bool ) (string , error ) {
213213 logger := klog .FromContext (ctx )
214- logger .V (2 ).Info ("Starting Do AttachDisk" , "instanceID" , nodeID , "region" , GlobalConfigVar . Region )
214+ logger .V (2 ).Info ("Starting Do AttachDisk" )
215215
216216 // Step 1: check disk status
217217 disk , err := ad .findDiskByID (ctx , diskID )
218218 if err != nil {
219- klog .Errorf ("AttachDisk: find disk: %s with error: %s" , diskID , err .Error ())
220- return "" , status .Errorf (codes .Internal , "AttachDisk: find disk: %s with error: %s" , diskID , err .Error ())
219+ return "" , status .Errorf (codes .Internal , "AttachDisk: find disk: %s with error: %v" , diskID , err )
221220 }
222221 if disk == nil {
223222 return "" , status .Errorf (codes .NotFound , "AttachDisk: csi can't find disk: %s in region: %s, Please check if the cloud disk exists, if the region is correct, or if the csi permissions are correct" , diskID , GlobalConfigVar .Region )
@@ -279,29 +278,29 @@ func (ad *DiskAttachDetach) attachDisk(ctx context.Context, diskID, nodeID strin
279278 switch action {
280279 case alreadyAttached :
281280 if ! fromNode {
282- klog . Infof ( "AttachDisk: Disk %s is already attached to Instance %s , skipping", diskID , disk . InstanceId )
281+ logger . V ( 2 ). Info ( " already attached, skipping" )
283282 return disk .SerialNumber , nil
284283 }
285284 deviceName , err := GetVolumeDeviceName (diskID )
286285 if err == nil && deviceName != "" && IsFileExisting (deviceName ) {
287- klog . Infof ( "AttachDisk: Disk %s is already attached to self Instance %s, and device is: %s" , diskID , disk . InstanceId , deviceName )
286+ logger . V ( 2 ). Info ( " already attached" , " device" , deviceName )
288287 return deviceName , nil
289288 } else if disk .SerialNumber != "" {
290289 // wait for pci attach ready
291290 time .Sleep (5 * time .Second )
292- klog . Infof ( "AttachDisk: find disk dev after 5 seconds" )
291+ logger . V ( 2 ). Info ( " find disk dev after 5 seconds" )
293292 deviceName , err := GetVolumeDeviceName (diskID )
294293 if err == nil && deviceName != "" && IsFileExisting (deviceName ) {
295- klog . Infof ( "AttachDisk: Disk %s is already attached to self Instance %s, and device is: %s" , diskID , disk . InstanceId , deviceName )
294+ logger . V ( 2 ). Info ( " already attached (after 5s)" , " device" , deviceName )
296295 return deviceName , nil
297296 }
298297 err = fmt .Errorf ("AttachDisk: disk device cannot be found in node, diskid: %s, deviceName: %s, err: %+v" , diskID , deviceName , err )
299298 return "" , err
300299 }
301- klog . Warningf ( "AttachDisk: Disk ( no serial) %s is already attached to instance %s , but device unknown, will be detached and try again", diskID , disk . InstanceId )
300+ logger . V ( 1 ). Info ( "disk has no serial, but device unknown, will be detached and try again" )
302301 fallthrough
303302 case detachFirst :
304- klog . Infof ( "AttachDisk: Disk %s is already attached to instance %s , will be detached" , diskID , disk .InstanceId )
303+ logger . V ( 1 ). Info ( " already attached to another instance , will be detached" , "from" , disk .InstanceId )
305304 detachRequest := ecs .CreateDetachDiskRequest ()
306305 detachRequest .InstanceId = disk .InstanceId
307306 detachRequest .DiskId = disk .DiskId
@@ -310,10 +309,9 @@ func (ad *DiskAttachDetach) attachDisk(ctx context.Context, diskID, nodeID strin
310309 }
311310 _ , err = ad .ecs .DetachDisk (detachRequest )
312311 if err != nil {
313- klog .Errorf ("AttachDisk: Can't Detach disk %s from instance %s: with error: %v" , diskID , disk .InstanceId , err )
314312 return "" , status .Errorf (codes .Aborted , "AttachDisk: Can't Detach disk %s from instance %s: with error: %v" , diskID , disk .InstanceId , err )
315313 }
316- klog . Infof ( "AttachDisk: Wait for disk %s to be detached", diskID )
314+ logger . V ( 2 ). Info ( "Waiting for disk to be detached" )
317315 if err := ad .waitForDiskDetached (ctx , diskID , nodeID ); err != nil {
318316 return "" , err
319317 }
@@ -333,7 +331,7 @@ func (ad *DiskAttachDetach) attachDisk(ctx context.Context, diskID, nodeID strin
333331 attachRequest .DiskId = diskID
334332 if action == forceAttach {
335333 attachRequest .Force = requests .NewBoolean (true )
336- logger .V (1 ).Info ("try force attach" , "from" , disk .InstanceId , "to" , nodeID )
334+ logger .V (1 ).Info ("try force attach" , "from" , disk .InstanceId )
337335 }
338336 if cate .SingleInstance {
339337 attachRequest .DeleteWithInstance = requests .NewBoolean (true )
@@ -360,7 +358,7 @@ func (ad *DiskAttachDetach) attachDisk(ctx context.Context, diskID, nodeID strin
360358 }
361359
362360 // Step 4: wait for disk attached
363- klog . Infof ( "AttachDisk: Waiting for Disk %s is Attached to instance %s with RequestId: %s " , diskID , nodeID , response .RequestId )
361+ logger . V ( 2 ). Info ( "waiting for disk to attach " , "requestID" , response .RequestId )
364362 if err := ad .waitForDiskAttached (ctx , diskID , nodeID ); err != nil {
365363 return "" , err
366364 }
@@ -374,7 +372,7 @@ func (ad *DiskAttachDetach) attachDisk(ctx context.Context, diskID, nodeID strin
374372 return device , nil
375373 }
376374
377- klog . Infof ( "AttachDisk: Successful attach disk %s to node %s" , diskID , nodeID )
375+ logger . V ( 2 ). Info ( "Successfully attached disk" )
378376 return disk .SerialNumber , nil
379377}
380378
0 commit comments