Skip to content

Commit

Permalink
Adding logs On How We Calculate CSINode.allocatables in NodeGetInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
mdzraf committed Feb 27, 2025
1 parent fd95d0a commit 2f3d31a
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
1 change: 0 additions & 1 deletion pkg/cloud/metadata/ec2.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ func EC2MetadataInstanceInfo(svc EC2Metadata, regionFromSession string) (*Metada
return nil, fmt.Errorf("could not read ENIs metadata content: %w", err)
}
attachedENIs := util.CountMACAddresses(string(enis))
klog.V(4).InfoS("Number of attached ENIs", "attachedENIs", attachedENIs)

blockDevMappings := 0
if !util.IsSBE(doc.Region) {
Expand Down
51 changes: 50 additions & 1 deletion pkg/driver/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,56 @@ func (d *NodeService) NodeGetInfo(ctx context.Context, req *csi.NodeGetInfoReque
zone := d.metadata.GetAvailabilityZone()
osType := runtime.GOOS

if d.options.VolumeAttachLimit >= 0 {
klog.V(4).InfoS("NodeGetInfo: VolumeAttachLimit manually set to", d.options.VolumeAttachLimit, "overriding the default value")
} else {
instanceType := d.metadata.GetInstanceType()
isNitro := cloud.IsNitroInstanceType(instanceType)
availableAttachments := cloud.GetMaxAttachments(isNitro)

reservedVolumeAttachments := d.options.ReservedVolumeAttachments
if reservedVolumeAttachments == -1 {
reservedVolumeAttachments = d.metadata.GetNumBlockDeviceMappings() + 1 // +1 for the root device
}
dedicatedLimit := cloud.GetDedicatedLimitForInstanceType(instanceType)
maxEBSAttachments, hasMaxVolumeLimit := cloud.GetEBSLimitForInstanceType(instanceType)
reservedSlots := cloud.GetReservedSlotsForInstanceType(instanceType)
if hasMaxVolumeLimit {
availableAttachments = min(maxEBSAttachments, availableAttachments)
}
if dedicatedLimit != 0 {
availableAttachments = dedicatedLimit
} else if isNitro {
enis := d.metadata.GetNumAttachedENIs()
if hasMaxVolumeLimit {
availableAttachments = availableAttachments - (enis - 1) - reservedSlots
} else {
availableAttachments = availableAttachments - enis - reservedSlots
}
}
availableAttachments -= reservedVolumeAttachments
if availableAttachments <= 0 {
availableAttachments = 1
}
enis := d.metadata.GetNumAttachedENIs()
maxAttachments := maxEBSAttachments
if !hasMaxVolumeLimit {
maxAttachments = cloud.GetMaxAttachments(isNitro)
}
if dedicatedLimit != 0 {
maxAttachments = dedicatedLimit
}
klog.V(4).InfoS("NodeGetInfo: Inputs used to calculate CSI Node Allocatable Info",
"instanceType", instanceType,
"maxAttachments", maxAttachments,
"numENIs", enis,
"reservedVolumeAttachments", reservedVolumeAttachments,
"reservedSlots", reservedSlots,
"numBlockDevices", d.metadata.GetNumBlockDeviceMappings(),
)
klog.V(4).InfoS("Node Allocatables", "count", availableAttachments)
}

segments := map[string]string{
ZoneTopologyKey: zone,
WellKnownZoneTopologyKey: zone,
Expand Down Expand Up @@ -803,7 +853,6 @@ func (d *NodeService) getVolumesLimit() int64 {
if availableAttachments <= 0 {
availableAttachments = 1
}

return int64(availableAttachments)
}

Expand Down

0 comments on commit 2f3d31a

Please sign in to comment.