mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 03:11:40 +00:00
Merge pull request #98136 from chymy/kubeadm-ep
kubeadm: APIEndpointFromString verifies ip
This commit is contained in:
commit
cf2fceb11f
@ -29,6 +29,9 @@ func APIEndpointFromString(apiEndpoint string) (APIEndpoint, error) {
|
||||
if err != nil {
|
||||
return APIEndpoint{}, errors.Wrapf(err, "invalid advertise address endpoint: %s", apiEndpoint)
|
||||
}
|
||||
if net.ParseIP(apiEndpointHost) == nil {
|
||||
return APIEndpoint{}, errors.Errorf("invalid API endpoint IP: %s", apiEndpointHost)
|
||||
}
|
||||
apiEndpointPort, err := net.LookupPort("tcp", apiEndpointPortStr)
|
||||
if err != nil {
|
||||
return APIEndpoint{}, errors.Wrapf(err, "invalid advertise address endpoint port: %s", apiEndpointPortStr)
|
||||
|
@ -31,10 +31,12 @@ func TestAPIEndpointFromString(t *testing.T) {
|
||||
{apiEndpoint: "1.2.3.4:-1", expectedErr: true},
|
||||
{apiEndpoint: "1.2.::1234", expectedErr: true},
|
||||
{apiEndpoint: "1.2.3.4:65536", expectedErr: true},
|
||||
{apiEndpoint: "1.2.3.456:1234", expectedErr: true},
|
||||
{apiEndpoint: "[::1]:1234", expectedEndpoint: APIEndpoint{AdvertiseAddress: "::1", BindPort: 1234}},
|
||||
{apiEndpoint: "[::1]:-1", expectedErr: true},
|
||||
{apiEndpoint: "[::1]:65536", expectedErr: true},
|
||||
{apiEndpoint: "[::1:1234", expectedErr: true},
|
||||
{apiEndpoint: "[::g]:1234", expectedErr: true},
|
||||
}
|
||||
for _, rt := range tests {
|
||||
t.Run(rt.apiEndpoint, func(t *testing.T) {
|
||||
|
Loading…
Reference in New Issue
Block a user