diff --git a/pkg/kubelet/container/runtime.go b/pkg/kubelet/container/runtime.go index e4f16dc892b..61dfd5cc346 100644 --- a/pkg/kubelet/container/runtime.go +++ b/pkg/kubelet/container/runtime.go @@ -58,17 +58,6 @@ type Runtime interface { // GetPodStatus retrieves the status of the pod, including the information of // all containers in the pod. GetPodStatus(*api.Pod) (*api.PodStatus, error) - // TODO(vmarmol): Merge RunInContainer and ExecInContainer. - // Runs the command in the container of the specified pod using nsinit. - // TODO(yifan): Use strong type for containerID. - RunInContainer(containerID string, cmd []string) ([]byte, error) - // Runs the command in the container of the specified pod using nsenter. - // Attaches the processes stdin, stdout, and stderr. Optionally uses a - // tty. - // TODO(yifan): Use strong type for containerID. - ExecInContainer(containerID string, cmd []string, stdin io.Reader, stdout, stderr io.WriteCloser, tty bool) error - // Forward the specified port from the specified pod to the stream. - PortForward(pod *Pod, port uint16, stream io.ReadWriteCloser) error // PullImage pulls an image from the network to local storage using the supplied // secrets if necessary. PullImage(image ImageSpec, secrets []api.Secret) error @@ -84,6 +73,23 @@ type Runtime interface { // stream the log. Set 'follow' to false and specify the number of lines (e.g. // "100" or "all") to tail the log. GetContainerLogs(pod *api.Pod, containerID, tail string, follow bool, stdout, stderr io.Writer) (err error) + // ContainerCommandRunner encapsulates the command runner interfaces for testability. + ContainerCommandRunner +} + +// CommandRunner encapsulates the command runner interfaces for testability. +type ContainerCommandRunner interface { + // TODO(vmarmol): Merge RunInContainer and ExecInContainer. + // Runs the command in the container of the specified pod using nsinit. + // TODO(yifan): Use strong type for containerID. + RunInContainer(containerID string, cmd []string) ([]byte, error) + // Runs the command in the container of the specified pod using nsenter. + // Attaches the processes stdin, stdout, and stderr. Optionally uses a + // tty. + // TODO(yifan): Use strong type for containerID. + ExecInContainer(containerID string, cmd []string, stdin io.Reader, stdout, stderr io.WriteCloser, tty bool) error + // Forward the specified port from the specified pod to the stream. + PortForward(pod *Pod, port uint16, stream io.ReadWriteCloser) error } // Customizable hooks injected into container runtimes. diff --git a/pkg/kubelet/kubelet.go b/pkg/kubelet/kubelet.go index 1c23b291101..3a9b8eed540 100644 --- a/pkg/kubelet/kubelet.go +++ b/pkg/kubelet/kubelet.go @@ -44,7 +44,6 @@ import ( "github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/envvars" "github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/metrics" "github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/network" - "github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/prober" "github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/rkt" kubeletTypes "github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/types" "github.com/GoogleCloudPlatform/kubernetes/pkg/labels" @@ -345,7 +344,7 @@ type Kubelet struct { // Optional, defaults to /logs/ from /var/log logServer http.Handler // Optional, defaults to simple Docker implementation - runner prober.ContainerCommandRunner + runner kubecontainer.ContainerCommandRunner // Optional, client for http requests, defaults to empty client httpClient kubeletTypes.HttpGetter @@ -1781,9 +1780,6 @@ func (kl *Kubelet) findContainer(podFullName string, podUID types.UID, container func (kl *Kubelet) RunInContainer(podFullName string, podUID types.UID, containerName string, cmd []string) ([]byte, error) { podUID = kl.podManager.TranslatePodUID(podUID) - if kl.runner == nil { - return nil, fmt.Errorf("no runner specified.") - } container, err := kl.findContainer(podFullName, podUID, containerName) if err != nil { return nil, err @@ -1799,9 +1795,6 @@ func (kl *Kubelet) RunInContainer(podFullName string, podUID types.UID, containe func (kl *Kubelet) ExecInContainer(podFullName string, podUID types.UID, containerName string, cmd []string, stdin io.Reader, stdout, stderr io.WriteCloser, tty bool) error { podUID = kl.podManager.TranslatePodUID(podUID) - if kl.runner == nil { - return fmt.Errorf("no runner specified.") - } container, err := kl.findContainer(podFullName, podUID, containerName) if err != nil { return err @@ -1817,10 +1810,6 @@ func (kl *Kubelet) ExecInContainer(podFullName string, podUID types.UID, contain func (kl *Kubelet) PortForward(podFullName string, podUID types.UID, port uint16, stream io.ReadWriteCloser) error { podUID = kl.podManager.TranslatePodUID(podUID) - if kl.runner == nil { - return fmt.Errorf("no runner specified.") - } - pods, err := kl.containerRuntime.GetPods(false) if err != nil { return err diff --git a/pkg/kubelet/kubelet_test.go b/pkg/kubelet/kubelet_test.go index 229cf74c288..f6af95b80ed 100644 --- a/pkg/kubelet/kubelet_test.go +++ b/pkg/kubelet/kubelet_test.go @@ -1570,6 +1570,7 @@ func (f *fakeContainerCommandRunner) PortForward(pod *kubecontainer.Pod, port ui f.Stream = stream return nil } + func TestRunInContainerNoSuchPod(t *testing.T) { fakeCommandRunner := fakeContainerCommandRunner{} testKubelet := newTestKubelet(t) diff --git a/pkg/kubelet/lifecycle/handlers.go b/pkg/kubelet/lifecycle/handlers.go index 579b1afee1c..be44b3aa439 100644 --- a/pkg/kubelet/lifecycle/handlers.go +++ b/pkg/kubelet/lifecycle/handlers.go @@ -23,7 +23,6 @@ import ( "github.com/GoogleCloudPlatform/kubernetes/pkg/api" kubecontainer "github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/container" - "github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/prober" kubeletTypes "github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/types" "github.com/GoogleCloudPlatform/kubernetes/pkg/util" "github.com/golang/glog" @@ -31,7 +30,7 @@ import ( type HandlerRunner struct { httpGetter kubeletTypes.HttpGetter - commandRunner prober.ContainerCommandRunner + commandRunner kubecontainer.ContainerCommandRunner containerManager podStatusProvider } @@ -39,8 +38,7 @@ type podStatusProvider interface { GetPodStatus(pod *api.Pod) (*api.PodStatus, error) } -// TODO(yifan): Merge commandRunner and containerManager once containerManager implements the ContainerCommandRunner interface. -func NewHandlerRunner(httpGetter kubeletTypes.HttpGetter, commandRunner prober.ContainerCommandRunner, containerManager podStatusProvider) kubecontainer.HandlerRunner { +func NewHandlerRunner(httpGetter kubeletTypes.HttpGetter, commandRunner kubecontainer.ContainerCommandRunner, containerManager podStatusProvider) kubecontainer.HandlerRunner { return &HandlerRunner{ httpGetter: httpGetter, commandRunner: commandRunner, diff --git a/pkg/kubelet/prober/prober.go b/pkg/kubelet/prober/prober.go index efc2c0520b1..03d67ae42bc 100644 --- a/pkg/kubelet/prober/prober.go +++ b/pkg/kubelet/prober/prober.go @@ -18,7 +18,6 @@ package prober import ( "fmt" - "io" "strconv" "time" @@ -42,19 +41,12 @@ type Prober interface { Probe(pod *api.Pod, status api.PodStatus, container api.Container, containerID string, createdAt int64) (probe.Result, error) } -type ContainerCommandRunner interface { - RunInContainer(containerID string, cmd []string) ([]byte, error) - ExecInContainer(containerID string, cmd []string, in io.Reader, out, err io.WriteCloser, tty bool) error - PortForward(pod *kubecontainer.Pod, port uint16, stream io.ReadWriteCloser) error -} - // Prober helps to check the liveness/readiness of a container. type prober struct { - exec execprobe.ExecProber - http httprobe.HTTPProber - tcp tcprobe.TCPProber - // TODO(vmarmol): Remove when we remove the circular dependency to DockerManager. - Runner ContainerCommandRunner + exec execprobe.ExecProber + http httprobe.HTTPProber + tcp tcprobe.TCPProber + runner kubecontainer.ContainerCommandRunner readinessManager *kubecontainer.ReadinessManager refManager *kubecontainer.RefManager @@ -64,7 +56,7 @@ type prober struct { // NewProber creates a Prober, it takes a command runner and // several container info managers. func New( - runner ContainerCommandRunner, + runner kubecontainer.ContainerCommandRunner, readinessManager *kubecontainer.ReadinessManager, refManager *kubecontainer.RefManager, recorder record.EventRecorder) Prober { @@ -73,7 +65,7 @@ func New( exec: execprobe.New(), http: httprobe.New(), tcp: tcprobe.New(), - Runner: runner, + runner: runner, readinessManager: readinessManager, refManager: refManager, @@ -256,7 +248,7 @@ type execInContainer struct { func (p *prober) newExecInContainer(pod *api.Pod, container api.Container, containerID string, cmd []string) exec.Cmd { return execInContainer{func() ([]byte, error) { - return p.Runner.RunInContainer(containerID, cmd) + return p.runner.RunInContainer(containerID, cmd) }} }