Skip to content

Commit

Permalink
change to check whether the env is set
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviassss authored and jdn5126 committed Nov 13, 2023
1 parent 7ce073b commit 74987dd
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions cmd/aws-vpc-cni/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,28 +387,28 @@ 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
}

// 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, 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
Expand Down

0 comments on commit 74987dd

Please sign in to comment.