Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkg/kubelet/server.go: minor fixes #4473

Merged
merged 1 commit into from
Feb 18, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 3 additions & 14 deletions pkg/kubelet/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
}

Expand Down Expand Up @@ -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)
}
Expand All @@ -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
}
Expand All @@ -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)
}
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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])
Expand All @@ -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
}
Expand All @@ -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
Expand Down
23 changes: 23 additions & 0 deletions pkg/kubelet/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down