diff --git a/pkg/kubelet/server.go b/pkg/kubelet/server.go index 93a37fa119c..3840598fe4c 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 f54f89532af..9d53cff7653 100644 --- a/pkg/kubelet/server_test.go +++ b/pkg/kubelet/server_test.go @@ -470,8 +470,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 @@ -490,7 +491,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) } @@ -509,8 +510,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 @@ -529,7 +531,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) } @@ -548,8 +550,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 @@ -568,7 +571,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) }