From 79fc8bee34caf2afda59aff092cc4127bd7da290 Mon Sep 17 00:00:00 2001 From: Victor Marmol Date: Fri, 1 May 2015 16:07:05 -0700 Subject: [PATCH] Change GetContainerLogs() signature. This works for both runtimes. We need to eventually unify the ID scheme for this method. --- pkg/kubelet/container/runtime.go | 3 ++- pkg/kubelet/dockertools/manager.go | 2 +- pkg/kubelet/kubelet.go | 6 +++++- pkg/kubelet/rkt/log.go | 6 +++--- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/pkg/kubelet/container/runtime.go b/pkg/kubelet/container/runtime.go index a30ab71321e..9ec71176d8a 100644 --- a/pkg/kubelet/container/runtime.go +++ b/pkg/kubelet/container/runtime.go @@ -69,11 +69,12 @@ type Runtime interface { ListImages() ([]Image, error) // Removes the specified image. RemoveImage(image string) error + // TODO(vmarmol): Unify pod and containerID args. // GetContainerLogs returns logs of a specific container. By // default, it returns a snapshot of the container log. Set 'follow' to true to // stream the log. Set 'follow' to false and specify the number of lines (e.g. // "100" or "all") to tail the log. - GetContainerLogs(containerID, tail string, follow bool, stdout, stderr io.Writer) (err error) + GetContainerLogs(podUID *api.Pod, containerID, tail string, follow bool, stdout, stderr io.Writer) (err error) } // Customizable hooks injected into container runtimes. diff --git a/pkg/kubelet/dockertools/manager.go b/pkg/kubelet/dockertools/manager.go index 20113701925..24129d52922 100644 --- a/pkg/kubelet/dockertools/manager.go +++ b/pkg/kubelet/dockertools/manager.go @@ -209,7 +209,7 @@ func (sc *stringCache) Get(uid types.UID, name string) (string, bool) { // stream the log. Set 'follow' to false and specify the number of lines (e.g. // "100" or "all") to tail the log. // TODO: Make 'RawTerminal' option flagable. -func (dm *DockerManager) GetContainerLogs(containerID, tail string, follow bool, stdout, stderr io.Writer) (err error) { +func (dm *DockerManager) GetContainerLogs(pod *api.Pod, containerID, tail string, follow bool, stdout, stderr io.Writer) (err error) { opts := docker.LogsOptions{ Container: containerID, Stdout: true, diff --git a/pkg/kubelet/kubelet.go b/pkg/kubelet/kubelet.go index e599f7422c0..3073e4f340c 100644 --- a/pkg/kubelet/kubelet.go +++ b/pkg/kubelet/kubelet.go @@ -1383,7 +1383,11 @@ func (kl *Kubelet) GetKubeletContainerLogs(podFullName, containerName, tail stri // waiting state. return err } - return kl.containerRuntime.GetContainerLogs(containerID, tail, follow, stdout, stderr) + pod, ok := kl.GetPodByFullName(podFullName) + if !ok { + return fmt.Errorf("unable to get logs for container %q in pod %q: unable to find pod", containerName, podFullName) + } + return kl.containerRuntime.GetContainerLogs(pod, containerID, tail, follow, stdout, stderr) } // GetHostname Returns the hostname as the kubelet sees it. diff --git a/pkg/kubelet/rkt/log.go b/pkg/kubelet/rkt/log.go index da49b75e469..89b0baef0ea 100644 --- a/pkg/kubelet/rkt/log.go +++ b/pkg/kubelet/rkt/log.go @@ -21,7 +21,7 @@ import ( "os/exec" "strconv" - kubecontainer "github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/container" + "github.com/GoogleCloudPlatform/kubernetes/pkg/api" ) // GetContainerLogs uses journalctl to get the logs of the container. @@ -31,8 +31,8 @@ import ( // TODO(yifan): Currently, it fetches all the containers' log within a pod. We will // be able to fetch individual container's log once https://github.com/coreos/rkt/pull/841 // landed. -func (r *Runtime) GetContainerLogs(pod kubecontainer.Pod, tail string, follow bool, stdout, stderr io.Writer) error { - unitName := makePodServiceFileName(pod.ID) +func (r *Runtime) GetContainerLogs(pod *api.Pod, containerID string, tail string, follow bool, stdout, stderr io.Writer) error { + unitName := makePodServiceFileName(pod.UID) cmd := exec.Command("journalctl", "-u", unitName) if follow { cmd.Args = append(cmd.Args, "-f")