support ipv6 in bind address
use split host port func instead trim specific character add unit test for metrics and healthz bind address recover import package refactor set default kube proxy configuration fix ipv4 condition fix set default port condition rewrite call function occasion to reduce error set ipv6 default value move get GetBindAddressHostPort to util use one func to handle deprecated series update bazel define address type return earlier in the error case refactor set default kube proxy configuration logic recover import package preserve some of the original comments add get default address func add append port if needed unit test rewrite unit test for deprecated flags remove unused codes
This commit is contained in:
@@ -214,3 +214,24 @@ func filterWithCondition(strs []string, expectedCondition bool, conditionFunc fu
|
||||
}
|
||||
return corrects, incorrects
|
||||
}
|
||||
|
||||
// AppendPortIfNeeded appends the given port to IP address unless it is already in
|
||||
// "ipv4:port" or "[ipv6]:port" format.
|
||||
func AppendPortIfNeeded(addr string, port int32) string {
|
||||
// Return if address is already in "ipv4:port" or "[ipv6]:port" format.
|
||||
if _, _, err := net.SplitHostPort(addr); err == nil {
|
||||
return addr
|
||||
}
|
||||
|
||||
// Simply return for invalid case. This should be caught by validation instead.
|
||||
ip := net.ParseIP(addr)
|
||||
if ip == nil {
|
||||
return addr
|
||||
}
|
||||
|
||||
// Append port to address.
|
||||
if ip.To4() != nil {
|
||||
return fmt.Sprintf("%s:%d", addr, port)
|
||||
}
|
||||
return fmt.Sprintf("[%s]:%d", addr, port)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user