diff --git a/pkg/kubelet/prober/prober.go b/pkg/kubelet/prober/prober.go index e322b54c407..749085308e9 100644 --- a/pkg/kubelet/prober/prober.go +++ b/pkg/kubelet/prober/prober.go @@ -206,11 +206,16 @@ func findPortByName(container api.Container, portName string) (int, error) { // formatURL formats a URL from args. For testability. func formatURL(scheme string, host string, port int, path string) *url.URL { - return &url.URL{ - Scheme: scheme, - Host: net.JoinHostPort(host, strconv.Itoa(port)), - Path: path, + u, err := url.Parse(path) + // Something is busted with the path, but it's too late to reject it. Pass it along as is. + if err != nil { + u = &url.URL{ + Path: path, + } } + u.Scheme = scheme + u.Host = net.JoinHostPort(host, strconv.Itoa(port)) + return u } type execInContainer struct { diff --git a/pkg/kubelet/prober/prober_test.go b/pkg/kubelet/prober/prober_test.go index add29804f22..b3cff1410e2 100644 --- a/pkg/kubelet/prober/prober_test.go +++ b/pkg/kubelet/prober/prober_test.go @@ -41,6 +41,8 @@ func TestFormatURL(t *testing.T) { }{ {"http", "localhost", 93, "", "http://localhost:93"}, {"https", "localhost", 93, "/path", "https://localhost:93/path"}, + {"http", "localhost", 93, "?foo", "http://localhost:93?foo"}, + {"https", "localhost", 93, "/path?bar", "https://localhost:93/path?bar"}, } for _, test := range testCases { url := formatURL(test.scheme, test.host, test.port, test.path)