mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-30 06:54:01 +00:00
handleContainerLogs needs a namespace to address a pod
This commit is contained in:
parent
99e1e2fd25
commit
897f1b3ab5
@ -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/<podNamespace>/<podID>/<containerName>
|
||||
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"},
|
||||
},
|
||||
})
|
||||
|
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user