Change GetContainerLogs() signature.

This works for both runtimes. We need to eventually unify the ID scheme
for this method.
This commit is contained in:
Victor Marmol 2015-05-01 16:07:05 -07:00
parent 60a77221f5
commit 79fc8bee34
4 changed files with 11 additions and 6 deletions

View File

@ -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.

View File

@ -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,

View File

@ -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.

View File

@ -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")