From eb0b6f2bcfe3029f25316087d3e4ca9b3fcf8f8f Mon Sep 17 00:00:00 2001 From: Federico Simoncelli Date: Mon, 2 Mar 2015 04:39:12 -0500 Subject: [PATCH] kubelet: improve client url composition Signed-off-by: Federico Simoncelli --- pkg/client/kubelet.go | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/pkg/client/kubelet.go b/pkg/client/kubelet.go index 72882b5af7a..5f7c8ae1112 100644 --- a/pkg/client/kubelet.go +++ b/pkg/client/kubelet.go @@ -22,6 +22,7 @@ import ( "io/ioutil" "net" "net/http" + "net/url" "strconv" "github.com/GoogleCloudPlatform/kubernetes/pkg/api" @@ -85,28 +86,24 @@ func NewKubeletClient(config *KubeletConfig) (KubeletClient, error) { }, nil } -func (c *HTTPKubeletClient) url(host string) string { - scheme := "http://" +func (c *HTTPKubeletClient) url(host, path, query string) string { + scheme := "http" if c.EnableHttps { - scheme = "https://" + scheme = "https" } - return fmt.Sprintf( - "%s%s", - scheme, - net.JoinHostPort(host, strconv.FormatUint(uint64(c.Port), 10))) + return (&url.URL{ + Scheme: scheme, + Host: net.JoinHostPort(host, strconv.FormatUint(uint64(c.Port), 10)), + Path: path, + RawQuery: query, + }).String() } // GetPodInfo gets information about the specified pod. func (c *HTTPKubeletClient) GetPodStatus(host, podNamespace, podID string) (api.PodStatusResult, error) { - request, err := http.NewRequest( - "GET", - fmt.Sprintf( - "%s/api/v1beta1/podInfo?podID=%s&podNamespace=%s", - c.url(host), - podID, - podNamespace), - nil) + query := url.Values{"podID": {podID}, "podNamespace": {podNamespace}} + request, err := http.NewRequest("GET", c.url(host, "/api/v1beta1/podInfo", query.Encode()), nil) status := api.PodStatusResult{} if err != nil { return status, err @@ -135,7 +132,7 @@ func (c *HTTPKubeletClient) GetPodStatus(host, podNamespace, podID string) (api. } func (c *HTTPKubeletClient) HealthCheck(host string) (probe.Result, error) { - return httprobe.DoHTTPProbe(fmt.Sprintf("%s/healthz", c.url(host)), c.Client) + return httprobe.DoHTTPProbe(c.url(host, "/healthz", ""), c.Client) } // FakeKubeletClient is a fake implementation of KubeletClient which returns an error