@@ -38,6 +38,7 @@ import (
38
38
"k8s.io/utils/ptr"
39
39
40
40
"sigs.k8s.io/azuredisk-csi-driver/pkg/azureutils"
41
+ "sigs.k8s.io/azuredisk-csi-driver/pkg/util"
41
42
"sigs.k8s.io/cloud-provider-azure/pkg/azclient"
42
43
azcache "sigs.k8s.io/cloud-provider-azure/pkg/cache"
43
44
"sigs.k8s.io/cloud-provider-azure/pkg/consts"
@@ -100,6 +101,8 @@ type controllerCommon struct {
100
101
ForceDetachBackoff bool
101
102
WaitForDetach bool
102
103
CheckDiskCountForBatching bool
104
+ // a timed cache for disk attach hitting max data disk count, <nodeName, "">
105
+ hitMaxDataDiskCountCache azcache.Resource
103
106
}
104
107
105
108
// ExtendedLocation contains additional info about the location of resources.
@@ -193,7 +196,7 @@ func (c *controllerCommon) AttachDisk(ctx context.Context, diskName, diskURI str
193
196
}
194
197
195
198
var waitForDetachHappened bool
196
- if c .WaitForDetach {
199
+ if c .WaitForDetach && c . isMaxDataDiskCountExceeded ( ctx , string ( nodeName )) {
197
200
// wait for disk detach to finish first on the same node
198
201
if err = wait .PollUntilContextTimeout (ctx , 2 * time .Second , 30 * time .Second , true , func (context.Context ) (bool , error ) {
199
202
detachDiskReqeustNum , err := c .getDetachDiskRequestNum (node )
@@ -296,7 +299,11 @@ func (c *controllerCommon) AttachDisk(ctx context.Context, diskName, diskURI str
296
299
297
300
err = vmset .AttachDisk (ctx , nodeName , diskMap )
298
301
if err != nil {
299
- if IsOperationPreempted (err ) {
302
+ if strings .Contains (err .Error (), util .MaximumDataDiskExceededMsg ) {
303
+ klog .Warningf ("hit max data disk count when attaching disk %s, set cache for node(%s)" , diskName , nodeName )
304
+ c .hitMaxDataDiskCountCache .Set (node , "" )
305
+ }
306
+ if strings .Contains (err .Error (), "OperationPreempted" ) {
300
307
klog .Errorf ("Retry VM Update on node (%s) due to error (%v)" , nodeName , err )
301
308
err = vmset .UpdateVM (ctx , nodeName )
302
309
}
@@ -618,8 +625,14 @@ func (c *controllerCommon) SetDiskLun(ctx context.Context, nodeName types.NodeNa
618
625
return lun , nil
619
626
}
620
627
621
- func IsOperationPreempted (err error ) bool {
622
- return strings .Contains (err .Error (), "OperationPreempted" )
628
+ // isMaxDataDiskCountExceeded checks if the max data disk count is exceeded
629
+ func (c * controllerCommon ) isMaxDataDiskCountExceeded (ctx context.Context , nodeName string ) bool {
630
+ _ , err := c .hitMaxDataDiskCountCache .Get (ctx , nodeName , azcache .CacheReadTypeDefault )
631
+ if err != nil {
632
+ klog .Warningf ("isMaxDataDiskCountExceeded(%s) return with error: %s" , nodeName , err )
633
+ return false
634
+ }
635
+ return true
623
636
}
624
637
625
638
func getValidCreationData (subscriptionID , resourceGroup string , options * ManagedDiskOptions ) (armcompute.CreationData , error ) {
0 commit comments