From e80ad2be38d0ca1df4f47846f1be4c82bcbd66eb Mon Sep 17 00:00:00 2001 From: Yu-Ju Hong Date: Mon, 25 Jul 2016 15:47:41 -0700 Subject: [PATCH] dockershim: add support for legacy methods --- pkg/kubelet/dockershim/legacy.go | 5 +++-- pkg/kubelet/dockertools/docker_manager.go | 21 ++++++++++++++++----- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/pkg/kubelet/dockershim/legacy.go b/pkg/kubelet/dockershim/legacy.go index 5f1bbc46fae..2abeeca819d 100644 --- a/pkg/kubelet/dockershim/legacy.go +++ b/pkg/kubelet/dockershim/legacy.go @@ -22,6 +22,7 @@ import ( "k8s.io/kubernetes/pkg/api" kubecontainer "k8s.io/kubernetes/pkg/kubelet/container" + "k8s.io/kubernetes/pkg/kubelet/dockertools" "k8s.io/kubernetes/pkg/util/term" ) @@ -31,11 +32,11 @@ import ( // TODO: implement the methods in this file. func (ds *dockerService) AttachContainer(id kubecontainer.ContainerID, stdin io.Reader, stdout, stderr io.WriteCloser, tty bool, resize <-chan term.Size) (err error) { - return fmt.Errorf("not implemented") + return dockertools.AttachContainer(ds.client, id, stdin, stdout, stderr, tty, resize) } func (ds *dockerService) GetContainerLogs(pod *api.Pod, containerID kubecontainer.ContainerID, logOptions *api.PodLogOptions, stdout, stderr io.Writer) (err error) { - return fmt.Errorf("not implemented") + return dockertools.GetContainerLogs(ds.client, pod, containerID, logOptions, stdout, stderr) } func (ds *dockerService) PortForward(pod *kubecontainer.Pod, port uint16, stream io.ReadWriteCloser) error { diff --git a/pkg/kubelet/dockertools/docker_manager.go b/pkg/kubelet/dockertools/docker_manager.go index 0807e2ea7b1..d7b0dddd1a1 100644 --- a/pkg/kubelet/dockertools/docker_manager.go +++ b/pkg/kubelet/dockertools/docker_manager.go @@ -285,7 +285,13 @@ func NewDockerManager( // 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(pod *api.Pod, containerID kubecontainer.ContainerID, logOptions *api.PodLogOptions, stdout, stderr io.Writer) (err error) { +func (dm *DockerManager) GetContainerLogs(pod *api.Pod, containerID kubecontainer.ContainerID, logOptions *api.PodLogOptions, stdout, stderr io.Writer) error { + return GetContainerLogs(dm.client, pod, containerID, logOptions, stdout, stderr) +} + +// Temporarily export this function to share with dockershim. +// TODO: clean this up. +func GetContainerLogs(client DockerInterface, pod *api.Pod, containerID kubecontainer.ContainerID, logOptions *api.PodLogOptions, stdout, stderr io.Writer) error { var since int64 if logOptions.SinceSeconds != nil { t := unversioned.Now().Add(-time.Duration(*logOptions.SinceSeconds) * time.Second) @@ -309,8 +315,7 @@ func (dm *DockerManager) GetContainerLogs(pod *api.Pod, containerID kubecontaine ErrorStream: stderr, RawTerminal: false, } - err = dm.client.Logs(containerID.ID, opts, sopts) - return + return client.Logs(containerID.ID, opts, sopts) } var ( @@ -1123,10 +1128,16 @@ func (dm *DockerManager) ExecInContainer(containerID kubecontainer.ContainerID, } func (dm *DockerManager) AttachContainer(containerID kubecontainer.ContainerID, stdin io.Reader, stdout, stderr io.WriteCloser, tty bool, resize <-chan term.Size) error { + return AttachContainer(dm.client, containerID, stdin, stdout, stderr, tty, resize) +} + +// Temporarily export this function to share with dockershim. +// TODO: clean this up. +func AttachContainer(client DockerInterface, containerID kubecontainer.ContainerID, stdin io.Reader, stdout, stderr io.WriteCloser, tty bool, resize <-chan term.Size) error { // Have to start this before the call to client.AttachToContainer because client.AttachToContainer is a blocking // call :-( Otherwise, resize events don't get processed and the terminal never resizes. kubecontainer.HandleResizing(resize, func(size term.Size) { - dm.client.ResizeContainerTTY(containerID.ID, int(size.Height), int(size.Width)) + client.ResizeContainerTTY(containerID.ID, int(size.Height), int(size.Width)) }) // TODO(random-liu): Do we really use the *Logs* field here? @@ -1142,7 +1153,7 @@ func (dm *DockerManager) AttachContainer(containerID kubecontainer.ContainerID, ErrorStream: stderr, RawTerminal: tty, } - return dm.client.AttachToContainer(containerID.ID, opts, sopts) + return client.AttachToContainer(containerID.ID, opts, sopts) } func noPodInfraContainerError(podName, podNamespace string) error {