From 2f3d31a69a94000b4a5bf150a7d3c8b77500536d Mon Sep 17 00:00:00 2001 From: Rafael Mendez Date: Thu, 27 Feb 2025 19:41:39 +0000 Subject: [PATCH] Adding logs On How We Calculate CSINode.allocatables in NodeGetInfo --- pkg/cloud/metadata/ec2.go | 1 - pkg/driver/node.go | 51 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/pkg/cloud/metadata/ec2.go b/pkg/cloud/metadata/ec2.go index b0c39a6b48..0a7346d5db 100644 --- a/pkg/cloud/metadata/ec2.go +++ b/pkg/cloud/metadata/ec2.go @@ -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) { diff --git a/pkg/driver/node.go b/pkg/driver/node.go index ef7ae326d9..cc93188bf5 100644 --- a/pkg/driver/node.go +++ b/pkg/driver/node.go @@ -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, @@ -803,7 +853,6 @@ func (d *NodeService) getVolumesLimit() int64 { if availableAttachments <= 0 { availableAttachments = 1 } - return int64(availableAttachments) }