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:
JieJhih Jhang
2019-04-09 15:30:11 +08:00
parent b8b7ab39ec
commit 08e320fa4e
7 changed files with 181 additions and 40 deletions

View File

@@ -396,3 +396,50 @@ func TestGetNodeAddressses(t *testing.T) {
}
}
}
func TestAppendPortIfNeeded(t *testing.T) {
testCases := []struct {
name string
addr string
port int32
expect string
}{
{
name: "IPv4 all-zeros bind address has port",
addr: "0.0.0.0:12345",
port: 23456,
expect: "0.0.0.0:12345",
},
{
name: "non-zeros IPv4 config",
addr: "9.8.7.6",
port: 12345,
expect: "9.8.7.6:12345",
},
{
name: "IPv6 \"[::]\" bind address has port",
addr: "[::]:12345",
port: 23456,
expect: "[::]:12345",
},
{
name: "IPv6 config",
addr: "fd00:1::5",
port: 23456,
expect: "[fd00:1::5]:23456",
},
{
name: "Invalid IPv6 Config",
addr: "[fd00:1::5]",
port: 12345,
expect: "[fd00:1::5]",
},
}
for i := range testCases {
got := AppendPortIfNeeded(testCases[i].addr, testCases[i].port)
if testCases[i].expect != got {
t.Errorf("case %s: expected %v, got %v", testCases[i].name, testCases[i].expect, got)
}
}
}