Skip to content

Commit 8b880e3

Browse files
committed
address review comments
1 parent 996d296 commit 8b880e3

File tree

3 files changed

+23
-10
lines changed

3 files changed

+23
-10
lines changed

pkg/azuredisk/azure_controller_common.go

+15-4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"context"
2121
"errors"
2222
"fmt"
23+
"math"
2324
"regexp"
2425
"strings"
2526
"sync"
@@ -196,13 +197,22 @@ func (c *controllerCommon) AttachDisk(ctx context.Context, diskName, diskURI str
196197
time.Sleep(time.Duration(c.AttachDetachInitialDelayInMs) * time.Millisecond)
197198
}
198199

200+
numDisksAllowed := math.MaxInt
199201
_, instanceType, err := getNodeInfoFromLabels(ctx, string(nodeName), c.cloud.KubeClient)
200202
if err != nil {
201203
return -1, err
202204
}
203-
maxNumDisks := getMaxDataDiskCount(instanceType)
204-
numDisksAttached := len(occupiedLuns)
205-
numDisksAllowed := int(maxNumDisks) - numDisksAttached
205+
if instanceType != "" {
206+
maxNumDisks, instanceExists := getMaxDataDiskCount(instanceType)
207+
if instanceExists {
208+
attachedDisks, _, err := c.GetNodeDataDisks(ctx, nodeName, azcache.CacheReadTypeDefault)
209+
if err != nil {
210+
return -1, err
211+
}
212+
numDisksAttached := len(attachedDisks)
213+
numDisksAllowed = int(maxNumDisks) - numDisksAttached
214+
}
215+
}
206216

207217
diskMap, err := c.cleanAttachDiskRequests(node)
208218
if err != nil {
@@ -212,12 +222,13 @@ func (c *controllerCommon) AttachDisk(ctx context.Context, diskName, diskURI str
212222
// Remove some disks from the batch if the number is more than the max number of disks allowed
213223
removeDisks := len(diskMap) - numDisksAllowed
214224
if removeDisks > 0 {
215-
klog.V(2).Infof("azureDisk - too many disks to attach, remove %d disks from the request", removeDisks)
225+
klog.V(2).Infof("too many disks to attach, remove %d disks from the request", removeDisks)
216226
for diskURI, options := range diskMap {
217227
if removeDisks == 0 {
218228
break
219229
}
220230
if options != nil {
231+
klog.V(2).Infof("remove disk(%s) from attach request", diskURI)
221232
delete(diskMap, diskURI)
222233
}
223234
removeDisks--

pkg/azuredisk/nodeserver.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,8 @@ func (d *Driver) NodeGetInfo(ctx context.Context, _ *csi.NodeGetInfoRequest) (*c
412412
if instanceType == "" {
413413
instanceType = instanceTypeFromLabels
414414
}
415-
maxDataDiskCount = getMaxDataDiskCount(instanceType) - d.ReservedDataDiskSlotNum
415+
totalDiskDataCount, _ := getMaxDataDiskCount(instanceType)
416+
maxDataDiskCount = totalDiskDataCount - d.ReservedDataDiskSlotNum
416417
}
417418

418419
nodeID := d.NodeID
@@ -444,16 +445,16 @@ func (d *Driver) NodeGetInfo(ctx context.Context, _ *csi.NodeGetInfoRequest) (*c
444445
}, nil
445446
}
446447

447-
func getMaxDataDiskCount(instanceType string) int64 {
448+
func getMaxDataDiskCount(instanceType string) (int64, bool) {
448449
vmsize := strings.ToUpper(instanceType)
449450
maxDataDiskCount, exists := maxDataDiskCountMap[vmsize]
450451
if exists {
451452
klog.V(5).Infof("got a matching size in getMaxDataDiskCount, VM Size: %s, MaxDataDiskCount: %d", vmsize, maxDataDiskCount)
452-
return maxDataDiskCount
453+
return maxDataDiskCount, true
453454
}
454455

455456
klog.V(5).Infof("not found a matching size in getMaxDataDiskCount, VM Size: %s, use default volume limit: %d", vmsize, defaultAzureVolumeLimit)
456-
return defaultAzureVolumeLimit
457+
return defaultAzureVolumeLimit, false
457458
}
458459

459460
func (d *Driver) NodeGetVolumeStats(ctx context.Context, req *csi.NodeGetVolumeStatsRequest) (*csi.NodeGetVolumeStatsResponse, error) {

pkg/azuredisk/nodeserver_test.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ func TestGetMaxDataDiskCount(t *testing.T) {
144144
}
145145

146146
for _, test := range tests {
147-
result := getMaxDataDiskCount(test.instanceType)
147+
result, _ := getMaxDataDiskCount(test.instanceType)
148148
assert.Equal(t, test.expectResult, result)
149149
}
150150
}
@@ -262,7 +262,8 @@ func TestNodeGetInfo(t *testing.T) {
262262
},
263263
validateFunc: func(t *testing.T, resp *csi.NodeGetInfoResponse) {
264264
assert.Equal(t, testVMName, resp.NodeId)
265-
assert.Equal(t, getMaxDataDiskCount(string(testVMSize)), resp.MaxVolumesPerNode)
265+
maxDiskdataCount, _ := getMaxDataDiskCount(string(testVMSize))
266+
assert.Equal(t, maxDiskdataCount, resp.MaxVolumesPerNode)
266267
assert.Len(t, resp.AccessibleTopology.Segments, 2)
267268
},
268269
},

0 commit comments

Comments
 (0)