mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +00:00
Merge pull request #4473 from xiang90/server
pkg/kubelet/server.go: minor fixes
This commit is contained in:
commit
8022c74b55
@ -130,18 +130,14 @@ func isValidDockerVersion(ver []uint) (bool, string) {
|
|||||||
func (s *Server) handleHealthz(w http.ResponseWriter, req *http.Request) {
|
func (s *Server) handleHealthz(w http.ResponseWriter, req *http.Request) {
|
||||||
versions, err := s.host.GetDockerVersion()
|
versions, err := s.host.GetDockerVersion()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
s.error(w, errors.New("unknown Docker version"))
|
||||||
w.Write([]byte("unknown Docker version"))
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
valid, version := isValidDockerVersion(versions)
|
valid, version := isValidDockerVersion(versions)
|
||||||
if !valid {
|
if !valid {
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
s.error(w, errors.New("Docker version is too old ("+version+")"))
|
||||||
msg := "Docker version is too old (" + version + ")"
|
|
||||||
w.Write([]byte(msg))
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
w.Write([]byte("ok"))
|
w.Write([]byte("ok"))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -230,7 +226,6 @@ func (s *Server) handleBoundPods(w http.ResponseWriter, req *http.Request) {
|
|||||||
s.error(w, err)
|
s.error(w, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
w.Header().Add("Content-type", "application/json")
|
w.Header().Add("Content-type", "application/json")
|
||||||
w.Write(data)
|
w.Write(data)
|
||||||
}
|
}
|
||||||
@ -254,12 +249,10 @@ func (s *Server) handlePodStatus(w http.ResponseWriter, req *http.Request, versi
|
|||||||
podUID := types.UID(u.Query().Get("UUID"))
|
podUID := types.UID(u.Query().Get("UUID"))
|
||||||
podNamespace := u.Query().Get("podNamespace")
|
podNamespace := u.Query().Get("podNamespace")
|
||||||
if len(podID) == 0 {
|
if len(podID) == 0 {
|
||||||
w.WriteHeader(http.StatusBadRequest)
|
|
||||||
http.Error(w, "Missing 'podID=' query entry.", http.StatusBadRequest)
|
http.Error(w, "Missing 'podID=' query entry.", http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if len(podNamespace) == 0 {
|
if len(podNamespace) == 0 {
|
||||||
w.WriteHeader(http.StatusBadRequest)
|
|
||||||
http.Error(w, "Missing 'podNamespace=' query entry.", http.StatusBadRequest)
|
http.Error(w, "Missing 'podNamespace=' query entry.", http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -278,7 +271,6 @@ func (s *Server) handlePodStatus(w http.ResponseWriter, req *http.Request, versi
|
|||||||
s.error(w, err)
|
s.error(w, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
w.Header().Add("Content-type", "application/json")
|
w.Header().Add("Content-type", "application/json")
|
||||||
w.Write(data)
|
w.Write(data)
|
||||||
}
|
}
|
||||||
@ -307,7 +299,6 @@ func (s *Server) handleSpec(w http.ResponseWriter, req *http.Request) {
|
|||||||
}
|
}
|
||||||
w.Header().Add("Content-type", "application/json")
|
w.Header().Add("Content-type", "application/json")
|
||||||
w.Write(data)
|
w.Write(data)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// handleRun handles requests to run a command inside a container.
|
// handleRun handles requests to run a command inside a container.
|
||||||
@ -380,7 +371,7 @@ func (s *Server) serveStats(w http.ResponseWriter, req *http.Request) {
|
|||||||
case 2:
|
case 2:
|
||||||
// pod stats
|
// pod stats
|
||||||
// TODO(monnand) Implement this
|
// TODO(monnand) Implement this
|
||||||
errors.New("pod level status currently unimplemented")
|
err = errors.New("pod level status currently unimplemented")
|
||||||
case 3:
|
case 3:
|
||||||
// Backward compatibility without uid information, does not support namespace
|
// Backward compatibility without uid information, does not support namespace
|
||||||
pod, ok := s.host.GetPodByName(api.NamespaceDefault, components[1])
|
pod, ok := s.host.GetPodByName(api.NamespaceDefault, components[1])
|
||||||
@ -411,7 +402,6 @@ func (s *Server) serveStats(w http.ResponseWriter, req *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if stats == nil {
|
if stats == nil {
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
fmt.Fprint(w, "{}")
|
fmt.Fprint(w, "{}")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -420,7 +410,6 @@ func (s *Server) serveStats(w http.ResponseWriter, req *http.Request) {
|
|||||||
s.error(w, err)
|
s.error(w, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
w.Header().Add("Content-type", "application/json")
|
w.Header().Add("Content-type", "application/json")
|
||||||
w.Write(data)
|
w.Write(data)
|
||||||
return
|
return
|
||||||
|
@ -399,6 +399,29 @@ func TestServeRunInContainerWithUID(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: fix me when pod level stats get implemented
|
||||||
|
func TestPodsInfo(t *testing.T) {
|
||||||
|
fw := newServerTest()
|
||||||
|
|
||||||
|
resp, err := http.Get(fw.testHTTPServer.URL + "/stats/goodpod")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Got error GETing: %v", err)
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
if resp.StatusCode != http.StatusInternalServerError {
|
||||||
|
t.Errorf("expected status code %d, got %d", http.StatusInternalServerError, resp.StatusCode)
|
||||||
|
}
|
||||||
|
body, err := ioutil.ReadAll(resp.Body)
|
||||||
|
if err != nil {
|
||||||
|
// copying the response body did not work
|
||||||
|
t.Fatalf("Cannot copy resp: %#v", err)
|
||||||
|
}
|
||||||
|
result := string(body)
|
||||||
|
if !strings.Contains(result, "pod level status currently unimplemented") {
|
||||||
|
t.Errorf("expected body contains %s, got %d", "pod level status currently unimplemented", result)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func setPodByNameFunc(fw *serverTestFramework, namespace, pod, container string) {
|
func setPodByNameFunc(fw *serverTestFramework, namespace, pod, container string) {
|
||||||
fw.fakeKubelet.podByNameFunc = func(namespace, name string) (*api.BoundPod, bool) {
|
fw.fakeKubelet.podByNameFunc = func(namespace, name string) (*api.BoundPod, bool) {
|
||||||
return &api.BoundPod{
|
return &api.BoundPod{
|
||||||
|
Loading…
Reference in New Issue
Block a user