Skip to content

Commit

Permalink
Merge pull request #1561 from torredil/windows-csinode
Browse files Browse the repository at this point in the history
Fix volume attachment limit calculation
  • Loading branch information
k8s-ci-robot authored Apr 11, 2023
2 parents 89b1594 + 2001925 commit 4e96fd3
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 14 deletions.
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")
}

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

0 comments on commit 4e96fd3

Please sign in to comment.