From 0dc4cd72c6f96f0a7a44fc63abc17261086d4674 Mon Sep 17 00:00:00 2001 From: oliviassss Date: Wed, 15 Nov 2023 11:29:13 -0800 Subject: [PATCH] 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) }