mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 17:30:00 +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, "/")
|
parts := strings.Split(u.Path, "/")
|
||||||
|
|
||||||
var podID, containerName string
|
// req URI: /containerLogs/<podNamespace>/<podID>/<containerName>
|
||||||
if len(parts) == 4 {
|
var podNamespace, podID, containerName string
|
||||||
podID = parts[2]
|
if len(parts) == 5 {
|
||||||
containerName = parts[3]
|
podNamespace = parts[2]
|
||||||
|
podID = parts[3]
|
||||||
|
containerName = parts[4]
|
||||||
} else {
|
} else {
|
||||||
http.Error(w, "Unexpected path for command running", http.StatusBadRequest)
|
http.Error(w, "Unexpected path for command running", http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
@ -192,6 +194,10 @@ func (s *Server) handleContainerLogs(w http.ResponseWriter, req *http.Request) {
|
|||||||
http.Error(w, `{"message": "Missing container name."}`, http.StatusBadRequest)
|
http.Error(w, `{"message": "Missing container name."}`, http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if len(podNamespace) == 0 {
|
||||||
|
http.Error(w, `{"message": "Missing podNamespace."}`, http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
uriValues := u.Query()
|
uriValues := u.Query()
|
||||||
follow, _ := strconv.ParseBool(uriValues.Get("follow"))
|
follow, _ := strconv.ParseBool(uriValues.Get("follow"))
|
||||||
@ -199,9 +205,8 @@ func (s *Server) handleContainerLogs(w http.ResponseWriter, req *http.Request) {
|
|||||||
|
|
||||||
podFullName := GetPodFullName(&api.BoundPod{
|
podFullName := GetPodFullName(&api.BoundPod{
|
||||||
TypeMeta: api.TypeMeta{
|
TypeMeta: api.TypeMeta{
|
||||||
ID: podID,
|
ID: podID,
|
||||||
// TODO: I am broken
|
Namespace: podNamespace,
|
||||||
Namespace: api.NamespaceDefault,
|
|
||||||
Annotations: map[string]string{ConfigSourceAnnotationKey: "etcd"},
|
Annotations: map[string]string{ConfigSourceAnnotationKey: "etcd"},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
@ -468,8 +468,9 @@ func TestServeRunInContainerWithUUID(t *testing.T) {
|
|||||||
func TestContainerLogs(t *testing.T) {
|
func TestContainerLogs(t *testing.T) {
|
||||||
fw := newServerTest()
|
fw := newServerTest()
|
||||||
output := "foo bar"
|
output := "foo bar"
|
||||||
|
podNamespace := "other"
|
||||||
podName := "foo"
|
podName := "foo"
|
||||||
expectedPodName := podName + ".default.etcd"
|
expectedPodName := podName + ".other.etcd"
|
||||||
expectedContainerName := "baz"
|
expectedContainerName := "baz"
|
||||||
expectedTail := ""
|
expectedTail := ""
|
||||||
expectedFollow := false
|
expectedFollow := false
|
||||||
@ -488,7 +489,7 @@ func TestContainerLogs(t *testing.T) {
|
|||||||
}
|
}
|
||||||
return nil
|
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 {
|
if err != nil {
|
||||||
t.Errorf("Got error GETing: %v", err)
|
t.Errorf("Got error GETing: %v", err)
|
||||||
}
|
}
|
||||||
@ -507,8 +508,9 @@ func TestContainerLogs(t *testing.T) {
|
|||||||
func TestContainerLogsWithTail(t *testing.T) {
|
func TestContainerLogsWithTail(t *testing.T) {
|
||||||
fw := newServerTest()
|
fw := newServerTest()
|
||||||
output := "foo bar"
|
output := "foo bar"
|
||||||
|
podNamespace := "other"
|
||||||
podName := "foo"
|
podName := "foo"
|
||||||
expectedPodName := podName + ".default.etcd"
|
expectedPodName := podName + ".other.etcd"
|
||||||
expectedContainerName := "baz"
|
expectedContainerName := "baz"
|
||||||
expectedTail := "5"
|
expectedTail := "5"
|
||||||
expectedFollow := false
|
expectedFollow := false
|
||||||
@ -527,7 +529,7 @@ func TestContainerLogsWithTail(t *testing.T) {
|
|||||||
}
|
}
|
||||||
return nil
|
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 {
|
if err != nil {
|
||||||
t.Errorf("Got error GETing: %v", err)
|
t.Errorf("Got error GETing: %v", err)
|
||||||
}
|
}
|
||||||
@ -546,8 +548,9 @@ func TestContainerLogsWithTail(t *testing.T) {
|
|||||||
func TestContainerLogsWithFollow(t *testing.T) {
|
func TestContainerLogsWithFollow(t *testing.T) {
|
||||||
fw := newServerTest()
|
fw := newServerTest()
|
||||||
output := "foo bar"
|
output := "foo bar"
|
||||||
|
podNamespace := "other"
|
||||||
podName := "foo"
|
podName := "foo"
|
||||||
expectedPodName := podName + ".default.etcd"
|
expectedPodName := podName + ".other.etcd"
|
||||||
expectedContainerName := "baz"
|
expectedContainerName := "baz"
|
||||||
expectedTail := ""
|
expectedTail := ""
|
||||||
expectedFollow := true
|
expectedFollow := true
|
||||||
@ -566,7 +569,7 @@ func TestContainerLogsWithFollow(t *testing.T) {
|
|||||||
}
|
}
|
||||||
return nil
|
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 {
|
if err != nil {
|
||||||
t.Errorf("Got error GETing: %v", err)
|
t.Errorf("Got error GETing: %v", err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user