Skip to content

Commit

Permalink
Merge pull request kubernetes#7659 from vmarmol/runtime-switch
Browse files Browse the repository at this point in the history
Have rkt implement the container Runtime interface
  • Loading branch information
yujuhong committed May 4, 2015
2 parents 36977ec + ba7e940 commit 7cf7b09
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 8 deletions.
3 changes: 2 additions & 1 deletion pkg/kubelet/container/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(pod *api.Pod, containerID, tail string, follow bool, stdout, stderr io.Writer) (err error)
}

// Customizable hooks injected into container runtimes.
Expand Down
2 changes: 1 addition & 1 deletion pkg/kubelet/dockertools/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 6 additions & 1 deletion pkg/kubelet/kubelet.go
Original file line number Diff line number Diff line change
Expand Up @@ -1369,6 +1369,7 @@ func (kl *Kubelet) validateContainerStatus(podStatus *api.PodStatus, containerNa
// TODO: this method is returning logs of random container attempts, when it should be returning the most recent attempt
// or all of them.
func (kl *Kubelet) GetKubeletContainerLogs(podFullName, containerName, tail string, follow bool, stdout, stderr io.Writer) error {
// TODO(vmarmol): Refactor to not need the pod status and verification.
podStatus, err := kl.GetPodStatus(podFullName)
if err != nil {
return fmt.Errorf("failed to get status for pod %q - %v", podFullName, err)
Expand All @@ -1383,7 +1384,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.
Expand Down
6 changes: 3 additions & 3 deletions pkg/kubelet/rkt/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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")
Expand Down
9 changes: 9 additions & 0 deletions pkg/kubelet/rkt/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"path"
"strings"

kubecontainer "github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/container"
"github.com/docker/docker/pkg/parsers"
docker "github.com/fsouza/go-dockerclient"
"github.com/golang/glog"
Expand Down Expand Up @@ -108,3 +109,11 @@ func (r *Runtime) IsImagePresent(img string) (bool, error) {
}
return true, nil
}

func (r *Runtime) ListImages() ([]kubecontainer.Image, error) {
return []kubecontainer.Image{}, fmt.Errorf("rkt: ListImages unimplemented")
}

func (r *Runtime) RemoveImage(image string) error {
return fmt.Errorf("rkt: RemoveImages unimplemented")
}
2 changes: 2 additions & 0 deletions pkg/kubelet/rkt/rkt.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ type Runtime struct {
dockerKeyring credentialprovider.DockerKeyring
}

var _ kubecontainer.Runtime = &Runtime{}

// New creates the rkt container runtime which implements the container runtime interface.
// It will test if the rkt binary is in the $PATH, and whether we can get the
// version of it. If so, creates the rkt container runtime, otherwise returns an error.
Expand Down
4 changes: 2 additions & 2 deletions pkg/kubelet/rkt/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func (r *Runtime) ExecInContainer(containerID string, cmd []string, stdin io.Rea
// findRktID returns the rkt uuid for the pod.
// TODO(yifan): This is unefficient which require us to list
// all the unit files.
func (r *Runtime) findRktID(pod kubecontainer.Pod) (string, error) {
func (r *Runtime) findRktID(pod *kubecontainer.Pod) (string, error) {
units, err := r.systemd.ListUnits()
if err != nil {
return "", err
Expand Down Expand Up @@ -150,7 +150,7 @@ func (r *Runtime) findRktID(pod kubecontainer.Pod) (string, error) {
// - should we support nsenter + socat in a container, running with elevated privs and --pid=host?
//
// TODO(yifan): Merge with the same function in dockertools.
func (r *Runtime) PortForward(pod kubecontainer.Pod, port uint16, stream io.ReadWriteCloser) error {
func (r *Runtime) PortForward(pod *kubecontainer.Pod, port uint16, stream io.ReadWriteCloser) error {
glog.V(4).Infof("Rkt port forwarding in container.")

podInfos, err := r.getPodInfos()
Expand Down

0 comments on commit 7cf7b09

Please sign in to comment.