Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix volume attachment limit calculation #1561

Merged
merged 1 commit into from
Apr 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions pkg/cloud/metadata_ec2.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,14 @@ func EC2MetadataInstanceInfo(svc EC2Metadata, regionFromSession string) (*Metada
}

attachedENIs := strings.Count(enis, "\n") + 1

//As block device mapping contains 1 volume for the AMI.
blockDevMappings := 1
blockDevMappings := 0

if !util.IsSBE(doc.Region) {
mappings, mapErr := svc.GetMetadata(blockDevicesEndpoint)
// The output contains 1 volume for the AMI. Any other block device contributes to the attachment limit
blockDevMappings = strings.Count(mappings, "\n")
if mapErr != nil {
return nil, fmt.Errorf("could not get number of block device mappings: %w", err)
}
blockDevMappings = strings.Count(mappings, "ebs")
gtxu marked this conversation as resolved.
Show resolved Hide resolved
}

instanceInfo := Metadata{
Expand Down
4 changes: 2 additions & 2 deletions pkg/cloud/metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ func TestNewMetadataService(t *testing.T) {
imdsENIOutput: "00:00:00:00:00:00",
expectedENIs: 1,
imdsBlockDeviceOutput: "ami\nroot\nebs1\nebs2",
expectedBlockDevices: 3,
expectedBlockDevices: 2,
},
{
name: "success: region from session is snow",
Expand All @@ -344,7 +344,7 @@ func TestNewMetadataService(t *testing.T) {
imdsENIOutput: "00:00:00:00:00:00",
expectedENIs: 1,
regionFromSession: snowRegion,
expectedBlockDevices: 1,
expectedBlockDevices: 0,
},
}

Expand Down
3 changes: 1 addition & 2 deletions pkg/driver/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -747,8 +747,7 @@ func (d *nodeService) getVolumesLimit() int64 {
nvmeInstanceStoreVolumes := cloud.GetNVMeInstanceStoreVolumesForInstanceType(instanceType)
availableAttachments = availableAttachments - enis - nvmeInstanceStoreVolumes
}
availableAttachments = availableAttachments - blockVolumes

availableAttachments = availableAttachments - blockVolumes - 1 // -1 for root device
if availableAttachments < 0 {
availableAttachments = 0
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/driver/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1941,7 +1941,7 @@ func TestNodeGetInfo(t *testing.T) {
availabilityZone: "us-west-2b",
region: "us-west-2",
volumeAttachLimit: -1,
expMaxVolumes: 39,
expMaxVolumes: 38,
attachedENIs: 1,
outpostArn: emptyOutpostArn,
},
Expand All @@ -1963,7 +1963,7 @@ func TestNodeGetInfo(t *testing.T) {
region: "us-west-2",
volumeAttachLimit: -1,
attachedENIs: 2,
expMaxVolumes: 26, // 28 (max) - 2 (enis)
expMaxVolumes: 25, // 28 (max) - 2 (enis) - 1 (root)
outpostArn: emptyOutpostArn,
},
{
Expand All @@ -1974,7 +1974,7 @@ func TestNodeGetInfo(t *testing.T) {
region: "us-west-2",
volumeAttachLimit: -1,
attachedENIs: 2,
expMaxVolumes: 25,
expMaxVolumes: 24,
outpostArn: emptyOutpostArn,
},
{
Expand Down Expand Up @@ -2005,7 +2005,7 @@ func TestNodeGetInfo(t *testing.T) {
region: "us-west-2",
volumeAttachLimit: -1,
attachedENIs: 1,
expMaxVolumes: 27, // 28 (max) - 1 (eni)
expMaxVolumes: 26, // 28 (max) - 1 (eni) - 1 (root)
outpostArn: emptyOutpostArn,
},
{
Expand Down Expand Up @@ -2050,7 +2050,7 @@ func TestNodeGetInfo(t *testing.T) {
volumeAttachLimit: -1,
attachedENIs: 1,
blockDevices: 2,
expMaxVolumes: 25,
expMaxVolumes: 24,
outpostArn: emptyOutpostArn,
},
{
Expand Down