mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-07 11:13:48 +00:00
Merge pull request #7659 from vmarmol/runtime-switch
Have rkt implement the container Runtime interface
This commit is contained in:
commit
7cf7b093a4
@ -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.
|
||||
|
@ -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,
|
||||
|
@ -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)
|
||||
@ -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.
|
||||
|
@ -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")
|
||||
|
@ -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"
|
||||
@ -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")
|
||||
}
|
||||
|
@ -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.
|
||||
|
@ -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
|
||||
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user