From 7831085e131926007786f83d76271c750c1da89a Mon Sep 17 00:00:00 2001 From: carlory Date: Fri, 2 Jun 2017 18:09:03 +0800 Subject: [PATCH] func parseEndpointWithFallbackProtocol should check if protocol of endpoint is empty. --- pkg/kubelet/util/util.go | 4 +++- pkg/kubelet/util/util_linux.go | 4 ++-- pkg/kubelet/util/util_test.go | 7 ++++--- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/pkg/kubelet/util/util.go b/pkg/kubelet/util/util.go index 911e99538f..eb7cf14275 100644 --- a/pkg/kubelet/util/util.go +++ b/pkg/kubelet/util/util.go @@ -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) } } diff --git a/pkg/kubelet/util/util_linux.go b/pkg/kubelet/util/util_linux.go index 1d780b24f9..49b5345dda 100644 --- a/pkg/kubelet/util/util_linux.go +++ b/pkg/kubelet/util/util_linux.go @@ -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 diff --git a/pkg/kubelet/util/util_test.go b/pkg/kubelet/util/util_test.go index ad9f0e7970..f2853b3c30 100644 --- a/pkg/kubelet/util/util_test.go +++ b/pkg/kubelet/util/util_test.go @@ -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", @@ -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) }