mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 17:30:00 +00:00
func parseEndpointWithFallbackProtocol should check if protocol of endpoint is empty.
This commit is contained in:
parent
3837d95191
commit
7831085e13
@ -39,7 +39,9 @@ func parseEndpoint(endpoint string) (string, string, error) {
|
|||||||
return "tcp", u.Host, nil
|
return "tcp", u.Host, nil
|
||||||
} else if u.Scheme == "unix" {
|
} else if u.Scheme == "unix" {
|
||||||
return "unix", u.Path, nil
|
return "unix", u.Path, nil
|
||||||
|
} else if u.Scheme == "" {
|
||||||
|
return "", "", fmt.Errorf("Using %q as endpoint is deprecated, please consider using full url format", endpoint)
|
||||||
} else {
|
} else {
|
||||||
return "", "", fmt.Errorf("protocol %q not supported", u.Scheme)
|
return u.Scheme, "", fmt.Errorf("protocol %q not supported", u.Scheme)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -68,11 +68,11 @@ func dial(addr string, timeout time.Duration) (net.Conn, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func parseEndpointWithFallbackProtocol(endpoint string, fallbackProtocol string) (protocol string, addr string, err error) {
|
func parseEndpointWithFallbackProtocol(endpoint string, fallbackProtocol string) (protocol string, addr string, err error) {
|
||||||
if protocol, addr, err = parseEndpoint(endpoint); err != nil {
|
if protocol, addr, err = parseEndpoint(endpoint); err != nil && protocol == "" {
|
||||||
fallbackEndpoint := fallbackProtocol + "://" + endpoint
|
fallbackEndpoint := fallbackProtocol + "://" + endpoint
|
||||||
protocol, addr, err = parseEndpoint(fallbackEndpoint)
|
protocol, addr, err = parseEndpoint(fallbackEndpoint)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
glog.Warningf("Using %q as endpoint is depercated, please consider using full url format %q.", endpoint, fallbackEndpoint)
|
glog.Warningf("Using %q as endpoint is deprecated, please consider using full url format %q.", endpoint, fallbackEndpoint)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
@ -41,6 +41,7 @@ func TestParseEndpoint(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
endpoint: "tcp1://abc",
|
endpoint: "tcp1://abc",
|
||||||
|
expectedProtocol: "tcp1",
|
||||||
expectError: true,
|
expectError: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -51,12 +52,12 @@ func TestParseEndpoint(t *testing.T) {
|
|||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
protocol, addr, err := parseEndpoint(test.endpoint)
|
protocol, addr, err := parseEndpoint(test.endpoint)
|
||||||
|
assert.Equal(t, test.expectedProtocol, protocol)
|
||||||
if test.expectError {
|
if test.expectError {
|
||||||
assert.NotNil(t, err, "Expect error during parsing %q", test.endpoint)
|
assert.NotNil(t, err, "Expect error during parsing %q", test.endpoint)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
assert.Nil(t, err, "Expect no error during parsing %q", test.endpoint)
|
assert.Nil(t, err, "Expect no error during parsing %q", test.endpoint)
|
||||||
assert.Equal(t, test.expectedProtocol, protocol)
|
|
||||||
assert.Equal(t, test.expectedAddr, addr)
|
assert.Equal(t, test.expectedAddr, addr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user