From 6e587606fa9ecc3d36049665ec458afb94efa4d1 Mon Sep 17 00:00:00 2001 From: pavanipt Date: Wed, 21 Aug 2024 20:25:50 -0700 Subject: [PATCH] Fix max-pods-calculator to consider only network card 0 (#1930) --- templates/al2/runtime/max-pods-calculator.sh | 9 ++--- templates/test/cases/max-pods-cni-1-18-0.sh | 21 +++++++++++ .../c6in-32xlarge.json | 36 +++++++++++++++++++ .../describe-instance-types/m4-xlarge.json | 24 +++++++++++-- .../describe-instance-types/m5-8xlarge.json | 24 +++++++++++-- 5 files changed, 106 insertions(+), 8 deletions(-) create mode 100755 templates/test/cases/max-pods-cni-1-18-0.sh create mode 100644 templates/test/mocks/describe-instance-types/c6in-32xlarge.json diff --git a/templates/al2/runtime/max-pods-calculator.sh b/templates/al2/runtime/max-pods-calculator.sh index c52c5d8d5..eedc66317 100755 --- a/templates/al2/runtime/max-pods-calculator.sh +++ b/templates/al2/runtime/max-pods-calculator.sh @@ -116,15 +116,16 @@ if [[ "$CNI_MAJOR_VERSION" -gt 1 ]] || ([[ "$CNI_MAJOR_VERSION" = 1 ]] && [[ "$C PREFIX_DELEGATION_SUPPORTED=true fi -DESCRIBE_INSTANCES_RESULT=$(aws ec2 describe-instance-types --instance-type "${INSTANCE_TYPE}" --query 'InstanceTypes[0].{Hypervisor: Hypervisor, EniCount: NetworkInfo.MaximumNetworkInterfaces, PodsPerEniCount: NetworkInfo.Ipv4AddressesPerInterface, CpuCount: VCpuInfo.DefaultVCpus}' --output json) - +DESCRIBE_INSTANCES_RESULT=$(aws ec2 describe-instance-types --instance-type "${INSTANCE_TYPE}" --query 'InstanceTypes[0].{Hypervisor: Hypervisor, NetworkInfo: NetworkInfo, CpuCount: VCpuInfo.DefaultVCpus}' --output json) HYPERVISOR_TYPE=$(echo $DESCRIBE_INSTANCES_RESULT | jq -r '.Hypervisor') IS_NITRO=false if [[ "$HYPERVISOR_TYPE" == "nitro" ]]; then IS_NITRO=true fi -INSTANCE_MAX_ENIS=$(echo $DESCRIBE_INSTANCES_RESULT | jq -r '.EniCount') -INSTANCE_MAX_ENIS_IPS=$(echo $DESCRIBE_INSTANCES_RESULT | jq -r '.PodsPerEniCount') +# Only one network card is used for pods, the default network card which is usually the network card 0 +DEFAULT_NETWORK_CARD_INDEX=$(echo $DESCRIBE_INSTANCES_RESULT | jq -r '.NetworkInfo.DefaultNetworkCardIndex') +INSTANCE_MAX_ENIS=$(echo $DESCRIBE_INSTANCES_RESULT | jq -r ".NetworkInfo.NetworkCards[$DEFAULT_NETWORK_CARD_INDEX].MaximumNetworkInterfaces") +INSTANCE_MAX_ENIS_IPS=$(echo $DESCRIBE_INSTANCES_RESULT | jq -r '.NetworkInfo.Ipv4AddressesPerInterface') if [ -z "$CNI_MAX_ENI" ]; then enis_for_pods=$INSTANCE_MAX_ENIS diff --git a/templates/test/cases/max-pods-cni-1-18-0.sh b/templates/test/cases/max-pods-cni-1-18-0.sh new file mode 100755 index 000000000..cddf133f6 --- /dev/null +++ b/templates/test/cases/max-pods-cni-1-18-0.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash +set -euo pipefail + +echo "-> Should calc max-pods successfully for c6in.32xlarge VPC CNI 1.18.0" +exit_code=0 +out=$(/etc/eks/max-pods-calculator.sh \ + --instance-type c6in.32xlarge \ + --cni-version 1.18.0 \ + --show-max-allowed || exit_code=$?) +echo $out + +if [[ ${exit_code} -ne 0 ]]; then + echo "❌ Test Failed: expected a non-zero exit code but got '${exit_code}'" + exit 1 +fi +expected_max_pods="394" +actual_max_pods=$(grep -o '[0-9]\+' <<< ${out}) +if [[ ${actual_max_pods} -ne ${expected_max_pods} ]]; then + echo "❌ Test Failed: expected max-pods for c6in.32xlarge w/ CNI 1.18.5 to be '${expected_max_pods}', but got '${actual_max_pods}'" + exit 1 +fi diff --git a/templates/test/mocks/describe-instance-types/c6in-32xlarge.json b/templates/test/mocks/describe-instance-types/c6in-32xlarge.json new file mode 100644 index 000000000..d05f1435a --- /dev/null +++ b/templates/test/mocks/describe-instance-types/c6in-32xlarge.json @@ -0,0 +1,36 @@ +{ + "Hypervisor": "nitro", + "NetworkInfo": { + "NetworkPerformance": "200 Gigabit", + "MaximumNetworkInterfaces": 16, + "MaximumNetworkCards": 2, + "DefaultNetworkCardIndex": 0, + "NetworkCards": [ + { + "NetworkCardIndex": 0, + "NetworkPerformance": "Up to 170 Gigabit", + "MaximumNetworkInterfaces": 8, + "BaselineBandwidthInGbps": 200.0, + "PeakBandwidthInGbps": 200.0 + }, + { + "NetworkCardIndex": 1, + "NetworkPerformance": "Up to 170 Gigabit", + "MaximumNetworkInterfaces": 8, + "BaselineBandwidthInGbps": 200.0, + "PeakBandwidthInGbps": 200.0 + } + ], + "Ipv4AddressesPerInterface": 50, + "Ipv6AddressesPerInterface": 50, + "Ipv6Supported": true, + "EnaSupport": "required", + "EfaSupported": true, + "EfaInfo": { + "MaximumEfaInterfaces": 2 + }, + "EncryptionInTransitSupported": true, + "EnaSrdSupported": false + }, + "CpuCount": 128 +} \ No newline at end of file diff --git a/templates/test/mocks/describe-instance-types/m4-xlarge.json b/templates/test/mocks/describe-instance-types/m4-xlarge.json index 0239966bc..ba8d85484 100644 --- a/templates/test/mocks/describe-instance-types/m4-xlarge.json +++ b/templates/test/mocks/describe-instance-types/m4-xlarge.json @@ -1,6 +1,26 @@ { "Hypervisor": "xen", - "EniCount": 4, - "PodsPerEniCount": 15, + "NetworkInfo": { + "NetworkPerformance": "High", + "MaximumNetworkInterfaces": 4, + "MaximumNetworkCards": 1, + "DefaultNetworkCardIndex": 0, + "NetworkCards": [ + { + "NetworkCardIndex": 0, + "NetworkPerformance": "High", + "MaximumNetworkInterfaces": 4, + "BaselineBandwidthInGbps": 0.75, + "PeakBandwidthInGbps": 2.8 + } + ], + "Ipv4AddressesPerInterface": 15, + "Ipv6AddressesPerInterface": 15, + "Ipv6Supported": true, + "EnaSupport": "unsupported", + "EfaSupported": false, + "EncryptionInTransitSupported": false, + "EnaSrdSupported": false + }, "CpuCount": 4 } diff --git a/templates/test/mocks/describe-instance-types/m5-8xlarge.json b/templates/test/mocks/describe-instance-types/m5-8xlarge.json index 840091225..1b03044d7 100644 --- a/templates/test/mocks/describe-instance-types/m5-8xlarge.json +++ b/templates/test/mocks/describe-instance-types/m5-8xlarge.json @@ -1,6 +1,26 @@ { "Hypervisor": "nitro", - "EniCount": 8, - "PodsPerEniCount": 30, + "NetworkInfo": { + "NetworkPerformance": "10 Gigabit", + "MaximumNetworkInterfaces": 8, + "MaximumNetworkCards": 1, + "DefaultNetworkCardIndex": 0, + "NetworkCards": [ + { + "NetworkCardIndex": 0, + "NetworkPerformance": "10 Gigabit", + "MaximumNetworkInterfaces": 8, + "BaselineBandwidthInGbps": 10.0, + "PeakBandwidthInGbps": 10.0 + } + ], + "Ipv4AddressesPerInterface": 30, + "Ipv6AddressesPerInterface": 30, + "Ipv6Supported": true, + "EnaSupport": "required", + "EfaSupported": false, + "EncryptionInTransitSupported": false, + "EnaSrdSupported": false + }, "CpuCount": 32 }