mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 20:53:33 +00:00
kubelet: improve client url composition
Signed-off-by: Federico Simoncelli <fsimonce@redhat.com>
This commit is contained in:
parent
6ba53b112f
commit
eb0b6f2bcf
@ -22,6 +22,7 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||||
@ -85,28 +86,24 @@ func NewKubeletClient(config *KubeletConfig) (KubeletClient, error) {
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *HTTPKubeletClient) url(host string) string {
|
func (c *HTTPKubeletClient) url(host, path, query string) string {
|
||||||
scheme := "http://"
|
scheme := "http"
|
||||||
if c.EnableHttps {
|
if c.EnableHttps {
|
||||||
scheme = "https://"
|
scheme = "https"
|
||||||
}
|
}
|
||||||
|
|
||||||
return fmt.Sprintf(
|
return (&url.URL{
|
||||||
"%s%s",
|
Scheme: scheme,
|
||||||
scheme,
|
Host: net.JoinHostPort(host, strconv.FormatUint(uint64(c.Port), 10)),
|
||||||
net.JoinHostPort(host, strconv.FormatUint(uint64(c.Port), 10)))
|
Path: path,
|
||||||
|
RawQuery: query,
|
||||||
|
}).String()
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetPodInfo gets information about the specified pod.
|
// GetPodInfo gets information about the specified pod.
|
||||||
func (c *HTTPKubeletClient) GetPodStatus(host, podNamespace, podID string) (api.PodStatusResult, error) {
|
func (c *HTTPKubeletClient) GetPodStatus(host, podNamespace, podID string) (api.PodStatusResult, error) {
|
||||||
request, err := http.NewRequest(
|
query := url.Values{"podID": {podID}, "podNamespace": {podNamespace}}
|
||||||
"GET",
|
request, err := http.NewRequest("GET", c.url(host, "/api/v1beta1/podInfo", query.Encode()), nil)
|
||||||
fmt.Sprintf(
|
|
||||||
"%s/api/v1beta1/podInfo?podID=%s&podNamespace=%s",
|
|
||||||
c.url(host),
|
|
||||||
podID,
|
|
||||||
podNamespace),
|
|
||||||
nil)
|
|
||||||
status := api.PodStatusResult{}
|
status := api.PodStatusResult{}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return status, err
|
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) {
|
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
|
// FakeKubeletClient is a fake implementation of KubeletClient which returns an error
|
||||||
|
Loading…
Reference in New Issue
Block a user