mirror of https://github.com/k3s-io/k3s
pkg/kubelet: minor fixes in server.go
parent
6f84bdaba8
commit
6b91901bd3
|
@ -130,18 +130,14 @@ func isValidDockerVersion(ver []uint) (bool, string) {
|
|||
func (s *Server) handleHealthz(w http.ResponseWriter, req *http.Request) {
|
||||
versions, err := s.host.GetDockerVersion()
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
w.Write([]byte("unknown Docker version"))
|
||||
s.error(w, errors.New("unknown Docker version"))
|
||||
return
|
||||
}
|
||||
valid, version := isValidDockerVersion(versions)
|
||||
if !valid {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
msg := "Docker version is too old (" + version + ")"
|
||||
w.Write([]byte(msg))
|
||||
s.error(w, errors.New("Docker version is too old ("+version+")"))
|
||||
return
|
||||
}
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.Write([]byte("ok"))
|
||||
}
|
||||
|
||||
|
@ -230,7 +226,6 @@ func (s *Server) handleBoundPods(w http.ResponseWriter, req *http.Request) {
|
|||
s.error(w, err)
|
||||
return
|
||||
}
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.Header().Add("Content-type", "application/json")
|
||||
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"))
|
||||
podNamespace := u.Query().Get("podNamespace")
|
||||
if len(podID) == 0 {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
http.Error(w, "Missing 'podID=' query entry.", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
if len(podNamespace) == 0 {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
http.Error(w, "Missing 'podNamespace=' query entry.", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
@ -278,7 +271,6 @@ func (s *Server) handlePodStatus(w http.ResponseWriter, req *http.Request, versi
|
|||
s.error(w, err)
|
||||
return
|
||||
}
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.Header().Add("Content-type", "application/json")
|
||||
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.Write(data)
|
||||
|
||||
}
|
||||
|
||||
// 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:
|
||||
// pod stats
|
||||
// TODO(monnand) Implement this
|
||||
errors.New("pod level status currently unimplemented")
|
||||
err = errors.New("pod level status currently unimplemented")
|
||||
case 3:
|
||||
// Backward compatibility without uid information, does not support namespace
|
||||
pod, ok := s.host.GetPodByName(api.NamespaceDefault, components[1])
|
||||
|
@ -405,7 +396,6 @@ func (s *Server) serveStats(w http.ResponseWriter, req *http.Request) {
|
|||
return
|
||||
}
|
||||
if stats == nil {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
fmt.Fprint(w, "{}")
|
||||
return
|
||||
}
|
||||
|
@ -414,7 +404,6 @@ func (s *Server) serveStats(w http.ResponseWriter, req *http.Request) {
|
|||
s.error(w, err)
|
||||
return
|
||||
}
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.Header().Add("Content-type", "application/json")
|
||||
w.Write(data)
|
||||
return
|
||||
|
|
|
@ -380,6 +380,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) {
|
||||
fw.fakeKubelet.podByNameFunc = func(namespace, name string) (*api.BoundPod, bool) {
|
||||
return &api.BoundPod{
|
||||
|
|
Loading…
Reference in New Issue