diff --git a/pkg/kubelet/server.go b/pkg/kubelet/server.go index 16d7f689342..61f981d5dd1 100644 --- a/pkg/kubelet/server.go +++ b/pkg/kubelet/server.go @@ -175,10 +175,12 @@ func (s *Server) handleContainerLogs(w http.ResponseWriter, req *http.Request) { } parts := strings.Split(u.Path, "/") - var podID, containerName string - if len(parts) == 4 { - podID = parts[2] - containerName = parts[3] + // req URI: /containerLogs/// + var podNamespace, podID, containerName string + if len(parts) == 5 { + podNamespace = parts[2] + podID = parts[3] + containerName = parts[4] } else { http.Error(w, "Unexpected path for command running", http.StatusBadRequest) return @@ -192,6 +194,10 @@ func (s *Server) handleContainerLogs(w http.ResponseWriter, req *http.Request) { http.Error(w, `{"message": "Missing container name."}`, http.StatusBadRequest) return } + if len(podNamespace) == 0 { + http.Error(w, `{"message": "Missing podNamespace."}`, http.StatusBadRequest) + return + } uriValues := u.Query() follow, _ := strconv.ParseBool(uriValues.Get("follow")) @@ -199,9 +205,8 @@ func (s *Server) handleContainerLogs(w http.ResponseWriter, req *http.Request) { podFullName := GetPodFullName(&api.BoundPod{ TypeMeta: api.TypeMeta{ - ID: podID, - // TODO: I am broken - Namespace: api.NamespaceDefault, + ID: podID, + Namespace: podNamespace, Annotations: map[string]string{ConfigSourceAnnotationKey: "etcd"}, }, }) diff --git a/pkg/kubelet/server_test.go b/pkg/kubelet/server_test.go index 3261337c47c..23ae7628016 100644 --- a/pkg/kubelet/server_test.go +++ b/pkg/kubelet/server_test.go @@ -468,8 +468,9 @@ func TestServeRunInContainerWithUUID(t *testing.T) { func TestContainerLogs(t *testing.T) { fw := newServerTest() output := "foo bar" + podNamespace := "other" podName := "foo" - expectedPodName := podName + ".default.etcd" + expectedPodName := podName + ".other.etcd" expectedContainerName := "baz" expectedTail := "" expectedFollow := false @@ -488,7 +489,7 @@ func TestContainerLogs(t *testing.T) { } return nil } - resp, err := http.Get(fw.testHTTPServer.URL + "/containerLogs/" + podName + "/" + expectedContainerName) + resp, err := http.Get(fw.testHTTPServer.URL + "/containerLogs/" + podNamespace + "/" + podName + "/" + expectedContainerName) if err != nil { t.Errorf("Got error GETing: %v", err) } @@ -507,8 +508,9 @@ func TestContainerLogs(t *testing.T) { func TestContainerLogsWithTail(t *testing.T) { fw := newServerTest() output := "foo bar" + podNamespace := "other" podName := "foo" - expectedPodName := podName + ".default.etcd" + expectedPodName := podName + ".other.etcd" expectedContainerName := "baz" expectedTail := "5" expectedFollow := false @@ -527,7 +529,7 @@ func TestContainerLogsWithTail(t *testing.T) { } return nil } - resp, err := http.Get(fw.testHTTPServer.URL + "/containerLogs/" + podName + "/" + expectedContainerName + "?tail=5") + resp, err := http.Get(fw.testHTTPServer.URL + "/containerLogs/" + podNamespace + "/" + podName + "/" + expectedContainerName + "?tail=5") if err != nil { t.Errorf("Got error GETing: %v", err) } @@ -546,8 +548,9 @@ func TestContainerLogsWithTail(t *testing.T) { func TestContainerLogsWithFollow(t *testing.T) { fw := newServerTest() output := "foo bar" + podNamespace := "other" podName := "foo" - expectedPodName := podName + ".default.etcd" + expectedPodName := podName + ".other.etcd" expectedContainerName := "baz" expectedTail := "" expectedFollow := true @@ -566,7 +569,7 @@ func TestContainerLogsWithFollow(t *testing.T) { } return nil } - resp, err := http.Get(fw.testHTTPServer.URL + "/containerLogs/" + podName + "/" + expectedContainerName + "?follow=1") + resp, err := http.Get(fw.testHTTPServer.URL + "/containerLogs/" + podNamespace + "/" + podName + "/" + expectedContainerName + "?follow=1") if err != nil { t.Errorf("Got error GETing: %v", err) }