mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-09 12:07:47 +00:00
stdout/stderr container log stream
This commit is contained in:
parent
960f1b2693
commit
9ba71528e4
@ -208,13 +208,13 @@ func GetRecentDockerContainersWithNameAndUUID(client DockerInterface, podFullNam
|
|||||||
// By default the function will return snapshot of the container log
|
// By default the function will return snapshot of the container log
|
||||||
// Log streaming is possible if 'follow' param is set to true
|
// Log streaming is possible if 'follow' param is set to true
|
||||||
// Log tailing is possible when number of tailed lines are set and only if 'follow' is false
|
// Log tailing is possible when number of tailed lines are set and only if 'follow' is false
|
||||||
func GetKubeletDockerContainerLogs(client DockerInterface, containerID, tail string, follow bool, writer io.Writer) (err error) {
|
func GetKubeletDockerContainerLogs(client DockerInterface, containerID, tail string, follow bool, stdout, stderr io.Writer) (err error) {
|
||||||
opts := docker.LogsOptions{
|
opts := docker.LogsOptions{
|
||||||
Container: containerID,
|
Container: containerID,
|
||||||
Stdout: true,
|
Stdout: true,
|
||||||
Stderr: true,
|
Stderr: true,
|
||||||
OutputStream: writer,
|
OutputStream: stdout,
|
||||||
ErrorStream: writer,
|
ErrorStream: stderr,
|
||||||
Timestamps: true,
|
Timestamps: true,
|
||||||
RawTerminal: true,
|
RawTerminal: true,
|
||||||
Follow: follow,
|
Follow: follow,
|
||||||
|
@ -753,7 +753,7 @@ func (kl *Kubelet) statsFromContainerPath(containerPath string, req *info.Contai
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetKubeletContainerLogs returns logs from the container
|
// GetKubeletContainerLogs returns logs from the container
|
||||||
func (kl *Kubelet) GetKubeletContainerLogs(podFullName, containerName, tail string, follow bool, writer io.Writer) error {
|
func (kl *Kubelet) GetKubeletContainerLogs(podFullName, containerName, tail string, follow bool, stdout, stderr io.Writer) error {
|
||||||
dockerContainers, err := dockertools.GetKubeletDockerContainers(kl.dockerClient)
|
dockerContainers, err := dockertools.GetKubeletDockerContainers(kl.dockerClient)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -763,7 +763,7 @@ func (kl *Kubelet) GetKubeletContainerLogs(podFullName, containerName, tail stri
|
|||||||
if !found {
|
if !found {
|
||||||
return fmt.Errorf("container not found (%s)\n", containerName)
|
return fmt.Errorf("container not found (%s)\n", containerName)
|
||||||
}
|
}
|
||||||
return dockertools.GetKubeletDockerContainerLogs(kl.dockerClient, dockerContainer.ID, tail , follow, writer)
|
return dockertools.GetKubeletDockerContainerLogs(kl.dockerClient, dockerContainer.ID, tail , follow, stdout, stderr)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetPodInfo returns information from Docker about the containers in a pod
|
// GetPodInfo returns information from Docker about the containers in a pod
|
||||||
|
@ -68,7 +68,7 @@ type HostInterface interface {
|
|||||||
GetMachineInfo() (*info.MachineInfo, error)
|
GetMachineInfo() (*info.MachineInfo, error)
|
||||||
GetPodInfo(name, uuid string) (api.PodInfo, error)
|
GetPodInfo(name, uuid string) (api.PodInfo, error)
|
||||||
RunInContainer(name, uuid, container string, cmd []string) ([]byte, error)
|
RunInContainer(name, uuid, container string, cmd []string) ([]byte, error)
|
||||||
GetKubeletContainerLogs(podFullName, containerName, tail string, follow bool, writer io.Writer) error
|
GetKubeletContainerLogs(podFullName, containerName, tail string, follow bool, stdout, stderr io.Writer) error
|
||||||
ServeLogs(w http.ResponseWriter, req *http.Request)
|
ServeLogs(w http.ResponseWriter, req *http.Request)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -185,7 +185,7 @@ func (s *Server) handleContainerLogs(w http.ResponseWriter, req *http.Request) {
|
|||||||
}
|
}
|
||||||
w.Header().Set("Transfer-Encoding", "chunked")
|
w.Header().Set("Transfer-Encoding", "chunked")
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
err = s.host.GetKubeletContainerLogs(podFullName, containerName, tail, follow, &fw)
|
err = s.host.GetKubeletContainerLogs(podFullName, containerName, tail, follow, &fw, &fw)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.error(w, err)
|
s.error(w, err)
|
||||||
return
|
return
|
||||||
|
@ -42,7 +42,7 @@ type fakeKubelet struct {
|
|||||||
machineInfoFunc func() (*info.MachineInfo, error)
|
machineInfoFunc func() (*info.MachineInfo, error)
|
||||||
logFunc func(w http.ResponseWriter, req *http.Request)
|
logFunc func(w http.ResponseWriter, req *http.Request)
|
||||||
runFunc func(podFullName, uuid, containerName string, cmd []string) ([]byte, error)
|
runFunc func(podFullName, uuid, containerName string, cmd []string) ([]byte, error)
|
||||||
containerLogsFunc func(podFullName, containerName, tail string, follow bool, writer io.Writer) error
|
containerLogsFunc func(podFullName, containerName, tail string, follow bool, stdout, stderr io.Writer) error
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fk *fakeKubelet) GetPodInfo(name, uuid string) (api.PodInfo, error) {
|
func (fk *fakeKubelet) GetPodInfo(name, uuid string) (api.PodInfo, error) {
|
||||||
@ -65,8 +65,8 @@ func (fk *fakeKubelet) ServeLogs(w http.ResponseWriter, req *http.Request) {
|
|||||||
fk.logFunc(w, req)
|
fk.logFunc(w, req)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fk *fakeKubelet) GetKubeletContainerLogs(podFullName, containerName, tail string, follow bool, writer io.Writer) error {
|
func (fk *fakeKubelet) GetKubeletContainerLogs(podFullName, containerName, tail string, follow bool, stdout, stderr io.Writer) error {
|
||||||
return fk.containerLogsFunc(podFullName, containerName, tail, follow, writer)
|
return fk.containerLogsFunc(podFullName, containerName, tail, follow, stdout, stderr)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fk *fakeKubelet) RunInContainer(podFullName, uuid, containerName string, cmd []string) ([]byte, error) {
|
func (fk *fakeKubelet) RunInContainer(podFullName, uuid, containerName string, cmd []string) ([]byte, error) {
|
||||||
@ -391,7 +391,7 @@ func TestContainerLogs(t *testing.T) {
|
|||||||
expectedTail := ""
|
expectedTail := ""
|
||||||
expectedFollow := false
|
expectedFollow := false
|
||||||
// expected := api.Container{"goodpod": docker.Container{ID: "myContainerID"}}
|
// expected := api.Container{"goodpod": docker.Container{ID: "myContainerID"}}
|
||||||
fw.fakeKubelet.containerLogsFunc = func(podFullName, containerName, tail string, follow bool, writer io.Writer) error {
|
fw.fakeKubelet.containerLogsFunc = func(podFullName, containerName, tail string, follow bool, stdout, stderr io.Writer) error {
|
||||||
if podFullName != expectedPodName {
|
if podFullName != expectedPodName {
|
||||||
t.Errorf("expected %s, got %s", expectedPodName, podFullName)
|
t.Errorf("expected %s, got %s", expectedPodName, podFullName)
|
||||||
}
|
}
|
||||||
@ -430,7 +430,7 @@ func TestContainerLogsWithTail(t *testing.T) {
|
|||||||
expectedContainerName := "baz"
|
expectedContainerName := "baz"
|
||||||
expectedTail := "5"
|
expectedTail := "5"
|
||||||
expectedFollow := false
|
expectedFollow := false
|
||||||
fw.fakeKubelet.containerLogsFunc = func(podFullName, containerName, tail string, follow bool, writer io.Writer) error {
|
fw.fakeKubelet.containerLogsFunc = func(podFullName, containerName, tail string, follow bool, stdout, stderr io.Writer) error {
|
||||||
if podFullName != expectedPodName {
|
if podFullName != expectedPodName {
|
||||||
t.Errorf("expected %s, got %s", expectedPodName, podFullName)
|
t.Errorf("expected %s, got %s", expectedPodName, podFullName)
|
||||||
}
|
}
|
||||||
@ -469,7 +469,7 @@ func TestContainerLogsWithFollow(t *testing.T) {
|
|||||||
expectedContainerName := "baz"
|
expectedContainerName := "baz"
|
||||||
expectedTail := ""
|
expectedTail := ""
|
||||||
expectedFollow := true
|
expectedFollow := true
|
||||||
fw.fakeKubelet.containerLogsFunc = func(podFullName, containerName, tail string, follow bool, writer io.Writer) error {
|
fw.fakeKubelet.containerLogsFunc = func(podFullName, containerName, tail string, follow bool, stdout, stderr io.Writer) error {
|
||||||
if podFullName != expectedPodName {
|
if podFullName != expectedPodName {
|
||||||
t.Errorf("expected %s, got %s", expectedPodName, podFullName)
|
t.Errorf("expected %s, got %s", expectedPodName, podFullName)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user