@@ -67,6 +67,7 @@ const (
6767
6868type DiskAttachDetach struct {
6969 slots AttachDetachSlots
70+ ecs cloud.ECSInterface
7071 waiter waitstatus.StatusWaiter [ecs.Disk ]
7172 batcher batcher.Batcher [ecs.Disk ]
7273
@@ -167,7 +168,6 @@ func (ad *DiskAttachDetach) attachDisk(ctx context.Context, diskID, nodeID strin
167168 logger := klog .FromContext (ctx )
168169 logger .V (2 ).Info ("Starting Do AttachDisk" , "instanceID" , nodeID , "region" , GlobalConfigVar .Region )
169170
170- ecsClient := GlobalConfigVar .EcsClient
171171 // Step 1: check disk status
172172 disk , err := ad .findDiskByID (ctx , diskID )
173173 if err != nil {
@@ -192,7 +192,7 @@ func (ad *DiskAttachDetach) attachDisk(ctx context.Context, diskID, nodeID strin
192192
193193 // tag disk as k8s.aliyun.com=true
194194 if GlobalConfigVar .DiskTagEnable {
195- tagDiskAsK8sAttached (diskID , ecsClient )
195+ tagDiskAsK8sAttached (diskID , GlobalConfigVar . EcsClient )
196196 }
197197
198198 cate , ok := AllCategories [Category (disk .Category )]
@@ -237,7 +237,7 @@ func (ad *DiskAttachDetach) attachDisk(ctx context.Context, diskID, nodeID strin
237237 }
238238
239239 if GlobalConfigVar .DiskBdfEnable {
240- if allowed , err := forceDetachAllowed (ecsClient , disk ); err != nil {
240+ if allowed , err := forceDetachAllowed (GlobalConfigVar . EcsClient , disk ); err != nil {
241241 return "" , status .Errorf (codes .Aborted , "forceDetachAllowed failed: %v" , err )
242242 } else if ! allowed {
243243 return "" , status .Errorf (codes .Aborted , "AttachDisk: Disk %s is already attached to instance %s, and depend bdf, reject force detach" , disk .DiskId , disk .InstanceId )
@@ -257,7 +257,7 @@ func (ad *DiskAttachDetach) attachDisk(ctx context.Context, diskID, nodeID strin
257257 for key , value := range GlobalConfigVar .RequestBaseInfo {
258258 detachRequest .AppendUserAgent (key , value )
259259 }
260- _ , err = ecsClient .DetachDisk (detachRequest )
260+ _ , err = ad . ecs .DetachDisk (detachRequest )
261261 if err != nil {
262262 klog .Errorf ("AttachDisk: Can't Detach disk %s from instance %s: with error: %v" , diskID , disk .InstanceId , err )
263263 return "" , status .Errorf (codes .Aborted , "AttachDisk: Can't Detach disk %s from instance %s: with error: %v" , diskID , disk .InstanceId , err )
@@ -297,7 +297,7 @@ func (ad *DiskAttachDetach) attachDisk(ctx context.Context, diskID, nodeID strin
297297 for key , value := range GlobalConfigVar .RequestBaseInfo {
298298 attachRequest .AppendUserAgent (key , value )
299299 }
300- response , err := throttle .Throttled (ad .attachThrottler , ecsClient .AttachDisk )(ctx , attachRequest )
300+ response , err := throttle .Throttled (ad .attachThrottler , ad . ecs .AttachDisk )(ctx , attachRequest )
301301 if err != nil {
302302 var aliErr * alicloudErr.ServerError
303303 if errors .As (err , & aliErr ) {
@@ -338,7 +338,6 @@ func (ad *DiskAttachDetach) attachDisk(ctx context.Context, diskID, nodeID strin
338338func (ad * DiskAttachDetach ) attachMultiAttachDisk (ctx context.Context , diskID , nodeID string ) (string , error ) {
339339 klog .Infof ("AttachDisk: Starting Do AttachMultiAttachDisk: DiskId: %s, InstanceId: %s, Region: %v" , diskID , nodeID , GlobalConfigVar .Region )
340340
341- ecsClient := GlobalConfigVar .EcsClient
342341 // Step 1: check disk status
343342 disk , err := ad .findDiskByID (ctx , diskID )
344343 if err != nil {
@@ -360,7 +359,7 @@ func (ad *DiskAttachDetach) attachMultiAttachDisk(ctx context.Context, diskID, n
360359 attachRequest := ecs .CreateAttachDiskRequest ()
361360 attachRequest .InstanceId = nodeID
362361 attachRequest .DiskId = diskID
363- response , err := ecsClient .AttachDisk (attachRequest )
362+ response , err := ad . ecs .AttachDisk (attachRequest )
364363 if err != nil {
365364 if strings .Contains (err .Error (), DiskLimitExceeded ) {
366365 return "" , status .Error (codes .Internal , err .Error ()+ ", Node(" + nodeID + ")exceed the limit attachments of disk" )
0 commit comments