Skip to content

Commit

Permalink
Merge pull request kubernetes-sigs#1542 from gtxu/volme_attach_count
Browse files Browse the repository at this point in the history
Add non-negative check on getVolumeLimit()
  • Loading branch information
k8s-ci-robot authored Mar 23, 2023
2 parents d889329 + f66f30a commit 5d75bf4
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
10 changes: 7 additions & 3 deletions pkg/driver/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -743,10 +743,14 @@ func (d *nodeService) getVolumesLimit() int64 {
if isNitro {
enis := d.metadata.GetNumAttachedENIs()
nvmeInstanceStoreVolumes := cloud.GetNVMeInstanceStoreVolumesForInstanceType(instanceType)
availableAttachments = availableAttachments - enis - blockVolumes - nvmeInstanceStoreVolumes
} else {
availableAttachments -= blockVolumes
availableAttachments = availableAttachments - enis - nvmeInstanceStoreVolumes
}
availableAttachments = availableAttachments - blockVolumes

if availableAttachments < 0 {
availableAttachments = 0
}

maxEBSAttachments, ok := cloud.GetEBSLimitForInstanceType(instanceType)
if ok {
availableAttachments = min(maxEBSAttachments, availableAttachments)
Expand Down
36 changes: 36 additions & 0 deletions pkg/driver/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2053,6 +2053,42 @@ func TestNodeGetInfo(t *testing.T) {
expMaxVolumes: 25,
outpostArn: emptyOutpostArn,
},
{
name: "nitro instance already attached max EBS volumes",
instanceID: "i-123456789abcdef01",
instanceType: "t3.xlarge",
availabilityZone: "us-west-2b",
region: "us-west-2",
volumeAttachLimit: -1,
attachedENIs: 1,
blockDevices: 27,
expMaxVolumes: 0,
outpostArn: emptyOutpostArn,
},
{
name: "non-nitro instance already attached max EBS volumes",
instanceID: "i-123456789abcdef01",
instanceType: "m5.xlarge",
availabilityZone: "us-west-2b",
region: "us-west-2",
volumeAttachLimit: -1,
attachedENIs: 1,
blockDevices: 39,
expMaxVolumes: 0,
outpostArn: emptyOutpostArn,
},
{
name: "nitro instance already attached max ENIs",
instanceID: "i-123456789abcdef01",
instanceType: "t3.xlarge",
availabilityZone: "us-west-2b",
region: "us-west-2",
volumeAttachLimit: -1,
attachedENIs: 27,
blockDevices: 1,
expMaxVolumes: 0,
outpostArn: emptyOutpostArn,
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
Expand Down

0 comments on commit 5d75bf4

Please sign in to comment.