From 1697543a7c7f618a22a7038836f156c1e4754ac2 Mon Sep 17 00:00:00 2001 From: oliviassss Date: Wed, 8 Nov 2023 11:22:35 -0800 Subject: [PATCH 1/7] change default warm_ip_target to 1 --- README.md | 11 +++++++---- cmd/aws-vpc-cni/main.go | 12 +++++++++--- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 0fa6d2552b..6919fb9510 100644 --- a/README.md +++ b/README.md @@ -288,9 +288,9 @@ If `WARM_IP_TARGET` is set, then this environment variable is ignored and the `W Type: Integer -Default: None +Default: `1` -Specifies the number of free IP addresses that the `ipamd` daemon should attempt to keep available for pod assignment on the node. Setting this to a non-positive value is the same as setting this to 0 or not setting the variable. +Specifies the number of free IP addresses that the `ipamd` daemon should attempt to keep available for pod assignment on the node. Setting this to a non-positive value is the same as setting this to 0. With `ENABLE_PREFIX_DELEGATION` set to `true` then `ipamd` daemon will check if the existing (/28) prefixes are enough to maintain the `WARM_IP_TARGET` if it is not sufficient then more prefixes will be attached. @@ -323,8 +323,8 @@ Specifies the number of total IP addresses that the `ipamd` daemon should attemp addresses to keep available at all times, it sets a target number for a floor on how many total IP addresses are allocated. Setting to a non-positive value is same as setting this to 0 or not setting the variable. -`MINIMUM_IP_TARGET` is for pre-scaling, `WARM_IP_TARGET` is for dynamic scaling. For example, suppose a cluster has an -expected pod density of approximately 30 pods per node. If `WARM_IP_TARGET` is set to 30 to ensure there are enough IPs +`MINIMUM_IP_TARGET` is for pre-scaling, `WARM_IP_TARGET` is for dynamic scaling, and when `MINIMUM_IP_TARGET` is set, it is required that `WARM_IP_TARGET` is also set to positive value. +For example, suppose a cluster has an expected pod density of approximately 30 pods per node. If `WARM_IP_TARGET` is set to 30 to ensure there are enough IPs allocated up front by the CNI, then 30 pods are deployed to the node, the CNI will allocate an additional 30 IPs, for a total of 60, accelerating IP exhaustion in the relevant subnets. If instead `MINIMUM_IP_TARGET` is set to 30 and `WARM_IP_TARGET` to 2, after the 30 pods are deployed the CNI would allocate an additional 2 IPs. This still provides @@ -333,6 +333,9 @@ elasticity, but uses roughly half as many IPs as using WARM_IP_TARGET alone (32 This also improves the reliability of the EKS cluster by reducing the number of calls necessary to allocate or deallocate private IPs, which may be throttled, especially at scaling-related times. +Setting both `WARM_IP_TARGET` and `MINIMUM_IP_TARGET` will override `WARM_PREFIX_TARGET`. For a detailed explanation, see +[`WARM_PREFIX_TARGET`, `WARM_IP_TARGET` and `MINIMUM_IP_TARGET`](https://github.com/aws/amazon-vpc-cni-k8s/blob/master/docs/prefix-and-ip-target.md). + #### `MAX_ENI` Type: Integer diff --git a/cmd/aws-vpc-cni/main.go b/cmd/aws-vpc-cni/main.go index 686b2dd3e9..9da946b602 100644 --- a/cmd/aws-vpc-cni/main.go +++ b/cmd/aws-vpc-cni/main.go @@ -83,6 +83,9 @@ const ( defaultEnPrefixDelegation = false defaultIPCooldownPeriod = 30 defaultDisablePodV6 = false + defaultWarmIPTarget = "1" + defaultMinIPTarget = "0" + defaultWarmPrefixTarget = "0" envHostCniBinPath = "HOST_CNI_BIN_PATH" envHostCniConfDirPath = "HOST_CNI_CONFDIR_PATH" @@ -384,14 +387,17 @@ func validateEnvVars() bool { } prefixDelegationEn := utils.GetBoolAsStringEnvVar(envEnPrefixDelegation, defaultEnPrefixDelegation) - warmIPTarget := utils.GetEnv(envWarmIPTarget, "0") - warmPrefixTarget := utils.GetEnv(envWarmPrefixTarget, "0") - minimumIPTarget := utils.GetEnv(envMinIPTarget, "0") + warmIPTarget := utils.GetEnv(envWarmIPTarget, defaultWarmIPTarget) + warmPrefixTarget := utils.GetEnv(envWarmPrefixTarget, defaultWarmPrefixTarget) + minimumIPTarget := utils.GetEnv(envMinIPTarget, defaultMinIPTarget) // Note that these string values should probably be cast to integers, but the comparison for values greater than 0 works either way if prefixDelegationEn && (warmIPTarget <= "0" && warmPrefixTarget <= "0" && minimumIPTarget <= "0") { log.Errorf("Setting WARM_PREFIX_TARGET = 0 is not supported while WARM_IP_TARGET/MINIMUM_IP_TARGET is not set. Please configure either one of the WARM_{PREFIX/IP}_TARGET or MINIMUM_IP_TARGET env variables") return false + } else if warmIPTarget <= "0" && minimumIPTarget > "0" { + log.Errorf("Setting WARM_IP_TARGET = 0 is not supported while MINIMUM_IP_TARGET is set. Please configure properly") + return false } return true } From 7fb1d8c61ee84b84aa486808e01944a0bb337d60 Mon Sep 17 00:00:00 2001 From: oliviassss Date: Wed, 8 Nov 2023 15:11:54 -0800 Subject: [PATCH 2/7] change type from string to int, update doc --- README.md | 2 +- cmd/aws-vpc-cni/main.go | 29 +++++++++++++++++++---------- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 6919fb9510..8cca3fcd4f 100644 --- a/README.md +++ b/README.md @@ -288,7 +288,7 @@ If `WARM_IP_TARGET` is set, then this environment variable is ignored and the `W Type: Integer -Default: `1` +Default: None Specifies the number of free IP addresses that the `ipamd` daemon should attempt to keep available for pod assignment on the node. Setting this to a non-positive value is the same as setting this to 0. With `ENABLE_PREFIX_DELEGATION` set to `true` then `ipamd` daemon will check if the existing (/28) prefixes are enough to maintain the diff --git a/cmd/aws-vpc-cni/main.go b/cmd/aws-vpc-cni/main.go index 9da946b602..ca6beb406d 100644 --- a/cmd/aws-vpc-cni/main.go +++ b/cmd/aws-vpc-cni/main.go @@ -83,9 +83,9 @@ const ( defaultEnPrefixDelegation = false defaultIPCooldownPeriod = 30 defaultDisablePodV6 = false - defaultWarmIPTarget = "1" - defaultMinIPTarget = "0" - defaultWarmPrefixTarget = "0" + defaultWarmIPTarget = 1 + defaultMinIPTarget = 0 + defaultWarmPrefixTarget = 0 envHostCniBinPath = "HOST_CNI_BIN_PATH" envHostCniConfDirPath = "HOST_CNI_CONFDIR_PATH" @@ -387,17 +387,26 @@ func validateEnvVars() bool { } prefixDelegationEn := utils.GetBoolAsStringEnvVar(envEnPrefixDelegation, defaultEnPrefixDelegation) - warmIPTarget := utils.GetEnv(envWarmIPTarget, defaultWarmIPTarget) - warmPrefixTarget := utils.GetEnv(envWarmPrefixTarget, defaultWarmPrefixTarget) - minimumIPTarget := utils.GetEnv(envMinIPTarget, defaultMinIPTarget) + warmIPTarget, err, input := utils.GetIntFromStringEnvVar(envWarmIPTarget, defaultWarmIPTarget) + if err != nil { + log.Errorf("error when trying to get envWarmIPTarget: %s; input is %v", err, input) + return false + } + warmPrefixTarget, err, input := utils.GetIntFromStringEnvVar(envWarmPrefixTarget, defaultWarmPrefixTarget) + if err != nil { + log.Errorf("error when trying to get envWarmPrefixTarget: %s; input is %v", err, input) + return false + } + minimumIPTarget, err, input := utils.GetIntFromStringEnvVar(envMinIPTarget, defaultMinIPTarget) + if err != nil { + log.Errorf("error when trying to get envMinIPTarget: %s; input is %v", err, input) + return false + } // Note that these string values should probably be cast to integers, but the comparison for values greater than 0 works either way - if prefixDelegationEn && (warmIPTarget <= "0" && warmPrefixTarget <= "0" && minimumIPTarget <= "0") { + if prefixDelegationEn && (warmIPTarget <= 0 && warmPrefixTarget <= 0 && minimumIPTarget <= 0) { log.Errorf("Setting WARM_PREFIX_TARGET = 0 is not supported while WARM_IP_TARGET/MINIMUM_IP_TARGET is not set. Please configure either one of the WARM_{PREFIX/IP}_TARGET or MINIMUM_IP_TARGET env variables") return false - } else if warmIPTarget <= "0" && minimumIPTarget > "0" { - log.Errorf("Setting WARM_IP_TARGET = 0 is not supported while MINIMUM_IP_TARGET is set. Please configure properly") - return false } return true } From dc182e78f8fe90e54089b99ca8a71e8ce0d31aae Mon Sep 17 00:00:00 2001 From: oliviassss Date: Thu, 9 Nov 2023 10:13:11 -0800 Subject: [PATCH 3/7] change the default warm_ip_target back to one, add config check --- README.md | 2 +- cmd/aws-vpc-cni/main.go | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 8cca3fcd4f..fad9b091be 100644 --- a/README.md +++ b/README.md @@ -290,7 +290,7 @@ Type: Integer Default: None -Specifies the number of free IP addresses that the `ipamd` daemon should attempt to keep available for pod assignment on the node. Setting this to a non-positive value is the same as setting this to 0. +Specifies the number of free IP addresses that the `ipamd` daemon should attempt to keep available for pod assignment on the node. Setting this to a non-positive value is the same as setting this to 0 or not setting the variable. With `ENABLE_PREFIX_DELEGATION` set to `true` then `ipamd` daemon will check if the existing (/28) prefixes are enough to maintain the `WARM_IP_TARGET` if it is not sufficient then more prefixes will be attached. diff --git a/cmd/aws-vpc-cni/main.go b/cmd/aws-vpc-cni/main.go index ca6beb406d..e97c90cec0 100644 --- a/cmd/aws-vpc-cni/main.go +++ b/cmd/aws-vpc-cni/main.go @@ -83,7 +83,7 @@ const ( defaultEnPrefixDelegation = false defaultIPCooldownPeriod = 30 defaultDisablePodV6 = false - defaultWarmIPTarget = 1 + defaultWarmIPTarget = 0 defaultMinIPTarget = 0 defaultWarmPrefixTarget = 0 @@ -389,17 +389,17 @@ func validateEnvVars() bool { prefixDelegationEn := utils.GetBoolAsStringEnvVar(envEnPrefixDelegation, defaultEnPrefixDelegation) warmIPTarget, err, input := utils.GetIntFromStringEnvVar(envWarmIPTarget, defaultWarmIPTarget) if err != nil { - log.Errorf("error when trying to get envWarmIPTarget: %s; input is %v", err, input) + log.Errorf("error when trying to get env WARM_IP_TARGET: %s; input is %v", err, input) return false } warmPrefixTarget, err, input := utils.GetIntFromStringEnvVar(envWarmPrefixTarget, defaultWarmPrefixTarget) if err != nil { - log.Errorf("error when trying to get envWarmPrefixTarget: %s; input is %v", err, input) + log.Errorf("error when trying to get env WARM_PREFIX_TARGET: %s; input is %v", err, input) return false } minimumIPTarget, err, input := utils.GetIntFromStringEnvVar(envMinIPTarget, defaultMinIPTarget) if err != nil { - log.Errorf("error when trying to get envMinIPTarget: %s; input is %v", err, input) + log.Errorf("error when trying to get env MINIMUM_IP_TARGET: %s; input is %v", err, input) return false } @@ -407,6 +407,9 @@ func validateEnvVars() bool { if prefixDelegationEn && (warmIPTarget <= 0 && warmPrefixTarget <= 0 && minimumIPTarget <= 0) { log.Errorf("Setting WARM_PREFIX_TARGET = 0 is not supported while WARM_IP_TARGET/MINIMUM_IP_TARGET is not set. Please configure either one of the WARM_{PREFIX/IP}_TARGET or MINIMUM_IP_TARGET env variables") return false + } else if warmIPTarget <= 0 && minimumIPTarget > 0 { + log.Errorf("Setting WARM_IP_TARGET = 0 is not supported while MINIMUM_IP_TARGET is set, as it leads to no new ENIs being allocated after minimum threshold is meet, please configure properly") + return false } return true } From 2fed2d7a863a0cb7516ef2eab93d82d821d20683 Mon Sep 17 00:00:00 2001 From: oliviassss Date: Fri, 10 Nov 2023 09:27:12 -0800 Subject: [PATCH 4/7] change to check whether the env is set --- cmd/aws-vpc-cni/main.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/cmd/aws-vpc-cni/main.go b/cmd/aws-vpc-cni/main.go index e97c90cec0..f1b2c89a77 100644 --- a/cmd/aws-vpc-cni/main.go +++ b/cmd/aws-vpc-cni/main.go @@ -387,19 +387,19 @@ func validateEnvVars() bool { } prefixDelegationEn := utils.GetBoolAsStringEnvVar(envEnPrefixDelegation, defaultEnPrefixDelegation) - warmIPTarget, err, input := utils.GetIntFromStringEnvVar(envWarmIPTarget, defaultWarmIPTarget) + warmIPTarget, err, inputWarmIP := utils.GetIntFromStringEnvVar(envWarmIPTarget, defaultWarmIPTarget) if err != nil { - log.Errorf("error when trying to get env WARM_IP_TARGET: %s; input is %v", err, input) + log.Errorf("error when trying to get env WARM_IP_TARGET: %s; input is %v", err, inputWarmIP) return false } - warmPrefixTarget, err, input := utils.GetIntFromStringEnvVar(envWarmPrefixTarget, defaultWarmPrefixTarget) + warmPrefixTarget, err, inputWarmPrefix := utils.GetIntFromStringEnvVar(envWarmPrefixTarget, defaultWarmPrefixTarget) if err != nil { - log.Errorf("error when trying to get env WARM_PREFIX_TARGET: %s; input is %v", err, input) + log.Errorf("error when trying to get env WARM_PREFIX_TARGET: %s; input is %v", err, inputWarmPrefix) return false } - minimumIPTarget, err, input := utils.GetIntFromStringEnvVar(envMinIPTarget, defaultMinIPTarget) + minimumIPTarget, err, inputMinIP := utils.GetIntFromStringEnvVar(envMinIPTarget, defaultMinIPTarget) if err != nil { - log.Errorf("error when trying to get env MINIMUM_IP_TARGET: %s; input is %v", err, input) + log.Errorf("error when trying to get env MINIMUM_IP_TARGET: %s; input is %v", err, inputMinIP) return false } @@ -407,8 +407,8 @@ func validateEnvVars() bool { if prefixDelegationEn && (warmIPTarget <= 0 && warmPrefixTarget <= 0 && minimumIPTarget <= 0) { log.Errorf("Setting WARM_PREFIX_TARGET = 0 is not supported while WARM_IP_TARGET/MINIMUM_IP_TARGET is not set. Please configure either one of the WARM_{PREFIX/IP}_TARGET or MINIMUM_IP_TARGET env variables") return false - } else if warmIPTarget <= 0 && minimumIPTarget > 0 { - log.Errorf("Setting WARM_IP_TARGET = 0 is not supported while MINIMUM_IP_TARGET is set, as it leads to no new ENIs being allocated after minimum threshold is meet, please configure properly") + } else if inputWarmIP == "" && inputMinIP != "" { + log.Errorf("WARM_IP_TARGET should be set while MINIMUM_IP_TARGET is set, in order to avoid no new ENIs being allocated after minimum threshold is meet, please configure properly") return false } return true From 8339c3592a6c122da34fadd568b2f186b20498fb Mon Sep 17 00:00:00 2001 From: oliviassss Date: Tue, 14 Nov 2023 09:57:41 -0800 Subject: [PATCH 5/7] reword error message, clean up comments --- cmd/aws-vpc-cni/main.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/cmd/aws-vpc-cni/main.go b/cmd/aws-vpc-cni/main.go index f1b2c89a77..6905b9a0b6 100644 --- a/cmd/aws-vpc-cni/main.go +++ b/cmd/aws-vpc-cni/main.go @@ -403,12 +403,11 @@ func validateEnvVars() bool { return false } - // Note that these string values should probably be cast to integers, but the comparison for values greater than 0 works either way - if prefixDelegationEn && (warmIPTarget <= 0 && warmPrefixTarget <= 0 && minimumIPTarget <= 0) { + if prefixDelegationEn && (warmIPTarget == 0 && warmPrefixTarget == 0 && minimumIPTarget == 0) { log.Errorf("Setting WARM_PREFIX_TARGET = 0 is not supported while WARM_IP_TARGET/MINIMUM_IP_TARGET is not set. Please configure either one of the WARM_{PREFIX/IP}_TARGET or MINIMUM_IP_TARGET env variables") return false } else if inputWarmIP == "" && inputMinIP != "" { - log.Errorf("WARM_IP_TARGET should be set while MINIMUM_IP_TARGET is set, in order to avoid no new ENIs being allocated after minimum threshold is meet, please configure properly") + log.Errorf("WARM_IP_TARGET MUST be set when MINIMUM_IP_TARGET is set. Please configure both environment variables.") return false } return true From 6cec4afabc3f82fe15e3820bbf4daca4eaf9381b Mon Sep 17 00:00:00 2001 From: oliviassss Date: Wed, 15 Nov 2023 11:29:13 -0800 Subject: [PATCH 6/7] rename GetIntFromStringEnvVar to GetEnvVar, rename output var --- cmd/aws-vpc-cni/main.go | 18 +++++++++--------- pkg/ipamd/datastore/data_store.go | 2 +- utils/utils.go | 2 +- utils/utils_test.go | 6 +++--- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/cmd/aws-vpc-cni/main.go b/cmd/aws-vpc-cni/main.go index 6905b9a0b6..e0736b178c 100644 --- a/cmd/aws-vpc-cni/main.go +++ b/cmd/aws-vpc-cni/main.go @@ -380,33 +380,33 @@ func validateEnvVars() bool { } // Validate that IP_COOLDOWN_PERIOD is a valid integer - ipCooldownPeriod, err, input := utils.GetIntFromStringEnvVar(envIPCooldownPeriod, defaultIPCooldownPeriod) + ipCooldownPeriod, err, ipCooldownPeriodStr := utils.GetEnvVar(envIPCooldownPeriod, defaultIPCooldownPeriod) if err != nil || ipCooldownPeriod < 0 { - log.Errorf("IP_COOLDOWN_PERIOD MUST be a valid positive integer. %s is invalid", input) + log.Errorf("IP_COOLDOWN_PERIOD MUST be a valid positive integer. %s is invalid", ipCooldownPeriodStr) return false } prefixDelegationEn := utils.GetBoolAsStringEnvVar(envEnPrefixDelegation, defaultEnPrefixDelegation) - warmIPTarget, err, inputWarmIP := utils.GetIntFromStringEnvVar(envWarmIPTarget, defaultWarmIPTarget) + warmIPTarget, err, warmIPTargetStr := utils.GetEnvVar(envWarmIPTarget, defaultWarmIPTarget) if err != nil { - log.Errorf("error when trying to get env WARM_IP_TARGET: %s; input is %v", err, inputWarmIP) + log.Errorf("error when trying to get env WARM_IP_TARGET: %s; input is %v", err, warmIPTargetStr) return false } - warmPrefixTarget, err, inputWarmPrefix := utils.GetIntFromStringEnvVar(envWarmPrefixTarget, defaultWarmPrefixTarget) + warmPrefixTarget, err, warmPrefixTargetStr := utils.GetEnvVar(envWarmPrefixTarget, defaultWarmPrefixTarget) if err != nil { - log.Errorf("error when trying to get env WARM_PREFIX_TARGET: %s; input is %v", err, inputWarmPrefix) + log.Errorf("error when trying to get env WARM_PREFIX_TARGET: %s; input is %v", err, warmPrefixTargetStr) return false } - minimumIPTarget, err, inputMinIP := utils.GetIntFromStringEnvVar(envMinIPTarget, defaultMinIPTarget) + minimumIPTarget, err, minimumIPTargetStr := utils.GetEnvVar(envMinIPTarget, defaultMinIPTarget) if err != nil { - log.Errorf("error when trying to get env MINIMUM_IP_TARGET: %s; input is %v", err, inputMinIP) + log.Errorf("error when trying to get env MINIMUM_IP_TARGET: %s; input is %v", err, minimumIPTargetStr) return false } if prefixDelegationEn && (warmIPTarget == 0 && warmPrefixTarget == 0 && minimumIPTarget == 0) { log.Errorf("Setting WARM_PREFIX_TARGET = 0 is not supported while WARM_IP_TARGET/MINIMUM_IP_TARGET is not set. Please configure either one of the WARM_{PREFIX/IP}_TARGET or MINIMUM_IP_TARGET env variables") return false - } else if inputWarmIP == "" && inputMinIP != "" { + } else if warmIPTargetStr == "" && minimumIPTargetStr != "" { log.Errorf("WARM_IP_TARGET MUST be set when MINIMUM_IP_TARGET is set. Please configure both environment variables.") return false } diff --git a/pkg/ipamd/datastore/data_store.go b/pkg/ipamd/datastore/data_store.go index b85b58510b..78eed1a042 100644 --- a/pkg/ipamd/datastore/data_store.go +++ b/pkg/ipamd/datastore/data_store.go @@ -222,7 +222,7 @@ func (addr AddressInfo) Assigned() bool { // getCooldownPeriod returns the time duration in seconds configured by the IP_COOLDOWN_PERIOD env variable func getCooldownPeriod() time.Duration { - cooldownVal, err, _ := utils.GetIntFromStringEnvVar(envIPCooldownPeriod, 30) + cooldownVal, err, _ := utils.GetEnvVar(envIPCooldownPeriod, 30) if err != nil { return 30 * time.Second } diff --git a/utils/utils.go b/utils/utils.go index d121b29162..09afef326e 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -22,7 +22,7 @@ func GetBoolAsStringEnvVar(env string, defaultVal bool) bool { } // Parse environment variable and return integer representation of string, or default value if environment variable is unset -func GetIntFromStringEnvVar(env string, defaultVal int) (int, error, string) { +func GetEnvVar(env string, defaultVal int) (int, error, string) { if val, ok := os.LookupEnv(env); ok { parsedVal, err := strconv.Atoi(val) if err == nil { diff --git a/utils/utils_test.go b/utils/utils_test.go index bfd16de476..343b3b6438 100644 --- a/utils/utils_test.go +++ b/utils/utils_test.go @@ -51,17 +51,17 @@ func TestGetEnv(t *testing.T) { // Validate that GetIntFromStringEnvVar runs against acceptable format input without error func TestGetIntFromStringEnvVar(t *testing.T) { // Test environment flag variable not set - tmp, _, _ := GetIntFromStringEnvVar(envInt, defaultIntEnv) + tmp, _, _ := GetEnvVar(envInt, defaultIntEnv) assert.Equal(t, tmp, defaultIntEnv) // Test basic Integer as string set with acceptable format os.Setenv(envInt, "20") - tmp, _, _ = GetIntFromStringEnvVar(envInt, defaultIntEnv) + tmp, _, _ = GetEnvVar(envInt, defaultIntEnv) assert.Equal(t, tmp, 20) // Test basic Integer as string set with unacceptable format os.Setenv(envInt, "2O") defer os.Unsetenv(envInt) - tmp, _, _ = GetIntFromStringEnvVar(envInt, defaultIntEnv) + tmp, _, _ = GetEnvVar(envInt, defaultIntEnv) assert.Equal(t, tmp, -1) } From 90384822a17aaf2bd3a01d9592dd708d9e2e340a Mon Sep 17 00:00:00 2001 From: Joseph Chen Date: Tue, 19 Dec 2023 19:57:27 +0000 Subject: [PATCH 7/7] fix --- README.md | 2 +- cmd/aws-vpc-cni/main.go | 8 ++++---- pkg/ipamd/datastore/data_store.go | 2 +- utils/utils.go | 2 +- utils/utils_test.go | 8 ++++---- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index fad9b091be..4c54c1a8cd 100644 --- a/README.md +++ b/README.md @@ -333,7 +333,7 @@ elasticity, but uses roughly half as many IPs as using WARM_IP_TARGET alone (32 This also improves the reliability of the EKS cluster by reducing the number of calls necessary to allocate or deallocate private IPs, which may be throttled, especially at scaling-related times. -Setting both `WARM_IP_TARGET` and `MINIMUM_IP_TARGET` will override `WARM_PREFIX_TARGET`. For a detailed explanation, see +Setting both `WARM_IP_TARGET` and `MINIMUM_IP_TARGET` will override `WARM_PREFIX_TARGET` and `WARM_ENI_TARGET`. For a detailed explanation, see [`WARM_PREFIX_TARGET`, `WARM_IP_TARGET` and `MINIMUM_IP_TARGET`](https://github.com/aws/amazon-vpc-cni-k8s/blob/master/docs/prefix-and-ip-target.md). #### `MAX_ENI` diff --git a/cmd/aws-vpc-cni/main.go b/cmd/aws-vpc-cni/main.go index e0736b178c..936f257778 100644 --- a/cmd/aws-vpc-cni/main.go +++ b/cmd/aws-vpc-cni/main.go @@ -380,24 +380,24 @@ func validateEnvVars() bool { } // Validate that IP_COOLDOWN_PERIOD is a valid integer - ipCooldownPeriod, err, ipCooldownPeriodStr := utils.GetEnvVar(envIPCooldownPeriod, defaultIPCooldownPeriod) + ipCooldownPeriod, err, ipCooldownPeriodStr := utils.GetIntEnvVar(envIPCooldownPeriod, defaultIPCooldownPeriod) if err != nil || ipCooldownPeriod < 0 { log.Errorf("IP_COOLDOWN_PERIOD MUST be a valid positive integer. %s is invalid", ipCooldownPeriodStr) return false } prefixDelegationEn := utils.GetBoolAsStringEnvVar(envEnPrefixDelegation, defaultEnPrefixDelegation) - warmIPTarget, err, warmIPTargetStr := utils.GetEnvVar(envWarmIPTarget, defaultWarmIPTarget) + warmIPTarget, err, warmIPTargetStr := utils.GetIntEnvVar(envWarmIPTarget, defaultWarmIPTarget) if err != nil { log.Errorf("error when trying to get env WARM_IP_TARGET: %s; input is %v", err, warmIPTargetStr) return false } - warmPrefixTarget, err, warmPrefixTargetStr := utils.GetEnvVar(envWarmPrefixTarget, defaultWarmPrefixTarget) + warmPrefixTarget, err, warmPrefixTargetStr := utils.GetIntEnvVar(envWarmPrefixTarget, defaultWarmPrefixTarget) if err != nil { log.Errorf("error when trying to get env WARM_PREFIX_TARGET: %s; input is %v", err, warmPrefixTargetStr) return false } - minimumIPTarget, err, minimumIPTargetStr := utils.GetEnvVar(envMinIPTarget, defaultMinIPTarget) + minimumIPTarget, err, minimumIPTargetStr := utils.GetIntEnvVar(envMinIPTarget, defaultMinIPTarget) if err != nil { log.Errorf("error when trying to get env MINIMUM_IP_TARGET: %s; input is %v", err, minimumIPTargetStr) return false diff --git a/pkg/ipamd/datastore/data_store.go b/pkg/ipamd/datastore/data_store.go index 78eed1a042..1e20d9cfd3 100644 --- a/pkg/ipamd/datastore/data_store.go +++ b/pkg/ipamd/datastore/data_store.go @@ -222,7 +222,7 @@ func (addr AddressInfo) Assigned() bool { // getCooldownPeriod returns the time duration in seconds configured by the IP_COOLDOWN_PERIOD env variable func getCooldownPeriod() time.Duration { - cooldownVal, err, _ := utils.GetEnvVar(envIPCooldownPeriod, 30) + cooldownVal, err, _ := utils.GetIntEnvVar(envIPCooldownPeriod, 30) if err != nil { return 30 * time.Second } diff --git a/utils/utils.go b/utils/utils.go index 09afef326e..cac6ea3eb1 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -22,7 +22,7 @@ func GetBoolAsStringEnvVar(env string, defaultVal bool) bool { } // Parse environment variable and return integer representation of string, or default value if environment variable is unset -func GetEnvVar(env string, defaultVal int) (int, error, string) { +func GetIntEnvVar(env string, defaultVal int) (int, error, string) { if val, ok := os.LookupEnv(env); ok { parsedVal, err := strconv.Atoi(val) if err == nil { diff --git a/utils/utils_test.go b/utils/utils_test.go index 343b3b6438..05be71ed22 100644 --- a/utils/utils_test.go +++ b/utils/utils_test.go @@ -49,19 +49,19 @@ func TestGetEnv(t *testing.T) { } // Validate that GetIntFromStringEnvVar runs against acceptable format input without error -func TestGetIntFromStringEnvVar(t *testing.T) { +func TestGetIntEnvVar(t *testing.T) { // Test environment flag variable not set - tmp, _, _ := GetEnvVar(envInt, defaultIntEnv) + tmp, _, _ := GetIntEnvVar(envInt, defaultIntEnv) assert.Equal(t, tmp, defaultIntEnv) // Test basic Integer as string set with acceptable format os.Setenv(envInt, "20") - tmp, _, _ = GetEnvVar(envInt, defaultIntEnv) + tmp, _, _ = GetIntEnvVar(envInt, defaultIntEnv) assert.Equal(t, tmp, 20) // Test basic Integer as string set with unacceptable format os.Setenv(envInt, "2O") defer os.Unsetenv(envInt) - tmp, _, _ = GetEnvVar(envInt, defaultIntEnv) + tmp, _, _ = GetIntEnvVar(envInt, defaultIntEnv) assert.Equal(t, tmp, -1) }