Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

func parseEndpointWithFallbackProtocol should check if protocol of endpoint is empty #46846

Merged
merged 1 commit into from
Jun 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion pkg/kubelet/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ func parseEndpoint(endpoint string) (string, string, error) {
return "tcp", u.Host, nil
} else if u.Scheme == "unix" {
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 {
return "", "", fmt.Errorf("protocol %q not supported", u.Scheme)
return u.Scheme, "", fmt.Errorf("protocol %q not supported", u.Scheme)
}
}
4 changes: 2 additions & 2 deletions pkg/kubelet/util/util_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
if protocol, addr, err = parseEndpoint(endpoint); err != nil {
if protocol, addr, err = parseEndpoint(endpoint); err != nil && protocol == "" {
fallbackEndpoint := fallbackProtocol + "://" + endpoint
protocol, addr, err = parseEndpoint(fallbackEndpoint)
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
Expand Down
7 changes: 4 additions & 3 deletions pkg/kubelet/util/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ func TestParseEndpoint(t *testing.T) {
expectedAddr: "localhost:15880",
},
{
endpoint: "tcp1://abc",
expectError: true,
endpoint: "tcp1://abc",
expectedProtocol: "tcp1",
expectError: true,
},
{
endpoint: "a b c",
Expand All @@ -51,12 +52,12 @@ func TestParseEndpoint(t *testing.T) {

for _, test := range tests {
protocol, addr, err := parseEndpoint(test.endpoint)
assert.Equal(t, test.expectedProtocol, protocol)
if test.expectError {
assert.NotNil(t, err, "Expect error during parsing %q", test.endpoint)
continue
}
assert.Nil(t, err, "Expect no error during parsing %q", test.endpoint)
assert.Equal(t, test.expectedProtocol, protocol)
assert.Equal(t, test.expectedAddr, addr)
}

Expand Down