kubernetes: github.com/erimatnor/kubernetes/pkg/kubelet/dockertools Index | Files

package dockertools

import "github.com/erimatnor/kubernetes/pkg/kubelet/dockertools"

Index

Package Files

convert.go docker.go fake_docker_client.go fake_manager.go instrumented_docker.go manager.go pty_linux.go

Constants

const (
    PodInfraContainerName  = leaky.PodInfraContainerName
    DockerPrefix           = "docker://"
    PodInfraContainerImage = "gcr.io/google_containers/pause:0.8.0"
)

Variables

var (
    // ErrNoContainersInPod is returned when there are no containers for a given pod
    ErrNoContainersInPod = errors.New("no containers exist for this pod")

    // ErrNoPodInfraContainerInPod is returned when there is no pod infra container for a given pod
    ErrNoPodInfraContainerInPod = errors.New("No pod infra container exists for this pod")

    // ErrContainerCannotRun is returned when a container is created, but cannot run properly
    ErrContainerCannotRun = errors.New("Container cannot run")
)

func BuildDockerName Uses

func BuildDockerName(dockerName KubeletContainerName, container *api.Container) string

Creates a name which can be reversed to identify both full pod name and container name.

func HashContainer Uses

func HashContainer(container *api.Container) uint64

func NewVersion Uses

func NewVersion(input string) (dockerVersion, error)

func StartPty Uses

func StartPty(c *exec.Cmd) (*os.File, error)

type DockerContainers Uses

type DockerContainers map[kubeletTypes.DockerID]*docker.APIContainers

DockerContainers is a map of containers

func GetKubeletDockerContainers Uses

func GetKubeletDockerContainers(client DockerInterface, allContainers bool) (DockerContainers, error)

GetKubeletDockerContainers lists all container or just the running ones. Returns a map of docker containers that we manage, keyed by container ID. TODO: Move this function with dockerCache to DockerManager.

func (DockerContainers) FindPodContainer Uses

func (c DockerContainers) FindPodContainer(podFullName string, uid types.UID, containerName string) (*docker.APIContainers, bool, uint64)

type DockerInterface Uses

type DockerInterface interface {
    ListContainers(options docker.ListContainersOptions) ([]docker.APIContainers, error)
    InspectContainer(id string) (*docker.Container, error)
    CreateContainer(docker.CreateContainerOptions) (*docker.Container, error)
    StartContainer(id string, hostConfig *docker.HostConfig) error
    StopContainer(id string, timeout uint) error
    RemoveContainer(opts docker.RemoveContainerOptions) error
    InspectImage(image string) (*docker.Image, error)
    ListImages(opts docker.ListImagesOptions) ([]docker.APIImages, error)
    PullImage(opts docker.PullImageOptions, auth docker.AuthConfiguration) error
    RemoveImage(image string) error
    Logs(opts docker.LogsOptions) error
    Version() (*docker.Env, error)
    Info() (*docker.Env, error)
    CreateExec(docker.CreateExecOptions) (*docker.Exec, error)
    StartExec(string, docker.StartExecOptions) error
}

DockerInterface is an abstract interface for testability. It abstracts the interface of docker.Client.

func ConnectToDockerOrDie Uses

func ConnectToDockerOrDie(dockerEndpoint string) DockerInterface

func NewInstrumentedDockerInterface Uses

func NewInstrumentedDockerInterface(dockerClient DockerInterface) DockerInterface

Creates an instrumented DockerInterface from an existing DockerInterface.

type DockerManager Uses

type DockerManager struct {

    // TODO(yifan): PodInfraContainerImage can be unexported once
    // we move createPodInfraContainer into dockertools.
    PodInfraContainerImage string

    // TODO(yifan): We export this for testability, so when we have a fake
    // container manager, then we can unexport this. Also at that time, we
    // use the concrete type so that we can record the pull failure and eliminate
    // the image checking in GetPodStatus().
    Puller DockerPuller
    // contains filtered or unexported fields
}

func NewDockerManager Uses

func NewDockerManager(
    client DockerInterface,
    recorder record.EventRecorder,
    readinessManager *kubecontainer.ReadinessManager,
    containerRefManager *kubecontainer.RefManager,
    podInfraContainerImage string,
    qps float32,
    burst int,
    containerLogsDir string,
    osInterface kubecontainer.OSInterface,
    networkPlugin network.NetworkPlugin,
    generator kubecontainer.RunContainerOptionsGenerator,
    httpClient kubeletTypes.HttpGetter,
    runtimeHooks kubecontainer.RuntimeHooks) *DockerManager

func NewFakeDockerManager Uses

func NewFakeDockerManager(
    client DockerInterface,
    recorder record.EventRecorder,
    readinessManager *kubecontainer.ReadinessManager,
    containerRefManager *kubecontainer.RefManager,
    podInfraContainerImage string,
    qps float32,
    burst int,
    containerLogsDir string,
    osInterface kubecontainer.OSInterface,
    networkPlugin network.NetworkPlugin,
    generator kubecontainer.RunContainerOptionsGenerator,
    httpClient kubeletTypes.HttpGetter,
    runtimeHooks kubecontainer.RuntimeHooks) *DockerManager

func (*DockerManager) ExecInContainer Uses

func (dm *DockerManager) ExecInContainer(containerId string, cmd []string, stdin io.Reader, stdout, stderr io.WriteCloser, tty bool) error

ExecInContainer uses nsenter to run the command inside the container identified by containerID.

TODO:

- match cgroups of container
- should we support `docker exec`?
- should we support nsenter in a container, running with elevated privs and --pid=host?
- use strong type for containerId

func (*DockerManager) GetContainerLogs Uses

func (dm *DockerManager) GetContainerLogs(pod *api.Pod, containerID, tail string, follow bool, stdout, stderr io.Writer) (err error)

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. TODO: Make 'RawTerminal' option flagable.

func (*DockerManager) GetContainers Uses

func (dm *DockerManager) GetContainers(all bool) ([]*kubecontainer.Container, error)

GetContainers returns a list of running containers if |all| is false; otherwise, it returns all containers.

func (*DockerManager) GetPodInfraContainer Uses

func (dm *DockerManager) GetPodInfraContainer(pod kubecontainer.Pod) (kubecontainer.Container, error)

func (*DockerManager) GetPodStatus Uses

func (dm *DockerManager) GetPodStatus(pod *api.Pod) (*api.PodStatus, error)

GetPodStatus returns docker related status for all containers in the pod as well as the infrastructure container.

func (*DockerManager) GetPods Uses

func (dm *DockerManager) GetPods(all bool) ([]*kubecontainer.Pod, error)

func (*DockerManager) IsImagePresent Uses

func (dm *DockerManager) IsImagePresent(image string) (bool, error)

IsImagePresent checks whether the container image is already in the local storage.

func (*DockerManager) KillContainer Uses

func (dm *DockerManager) KillContainer(containerID types.UID) error

TODO(vmarmol): Unexport this as it is no longer used externally. KillContainer kills a container identified by containerID. Internally, it invokes docker's StopContainer API with a timeout of 10s. TODO: Deprecate this function in favor of KillContainerInPod.

func (*DockerManager) KillContainerInPod Uses

func (dm *DockerManager) KillContainerInPod(container api.Container, pod *api.Pod) error

KillContainerInPod kills a container in the pod.

func (*DockerManager) KillPod Uses

func (dm *DockerManager) KillPod(pod kubecontainer.Pod) error

Kills all containers in the specified pod

func (*DockerManager) ListImages Uses

func (dm *DockerManager) ListImages() ([]kubecontainer.Image, error)

List all images in the local storage.

func (*DockerManager) PortForward Uses

func (dm *DockerManager) PortForward(pod *kubecontainer.Pod, port uint16, stream io.ReadWriteCloser) error

PortForward executes socat in the pod's network namespace and copies data between stream (representing the user's local connection on their computer) and the specified port in the container.

TODO:

- match cgroups of container
- should we support nsenter + socat on the host? (current impl)
- should we support nsenter + socat in a container, running with elevated privs and --pid=host?

func (*DockerManager) PullImage Uses

func (dm *DockerManager) PullImage(image string) error

TODO(vmarmol): Consider unexporting. PullImage pulls an image from network to local storage.

func (*DockerManager) RemoveImage Uses

func (dm *DockerManager) RemoveImage(image string) error

Removes the specified image.

func (*DockerManager) RunContainer Uses

func (dm *DockerManager) RunContainer(pod *api.Pod, container *api.Container, netMode, ipcMode string) (kubeletTypes.DockerID, error)

TODO(vmarmol): Unexport this as it is no longer used externally. Run a single container from a pod. Returns the docker container ID

func (*DockerManager) RunInContainer Uses

func (dm *DockerManager) RunInContainer(containerID string, cmd []string) ([]byte, error)

RunInContainer uses nsinit to run the command inside the container identified by containerID TODO(yifan): Use strong type for containerID.

func (*DockerManager) SyncPod Uses

func (dm *DockerManager) SyncPod(pod *api.Pod, runningPod kubecontainer.Pod, podStatus api.PodStatus) error

Sync the running pod to match the specified desired pod.

func (*DockerManager) Version Uses

func (dm *DockerManager) Version() (kubecontainer.Version, error)

type DockerPuller Uses

type DockerPuller interface {
    Pull(image string) error
    IsImagePresent(image string) (bool, error)
}

DockerPuller is an abstract interface for testability. It abstracts image pull operations.

type FakeDockerClient Uses

type FakeDockerClient struct {
    sync.Mutex
    ContainerList       []docker.APIContainers
    ExitedContainerList []docker.APIContainers
    Container           *docker.Container
    ContainerMap        map[string]*docker.Container
    Image               *docker.Image
    Images              []docker.APIImages
    Errors              map[string]error

    Stopped []string

    Created       []string
    Removed       []string
    RemovedImages util.StringSet
    VersionInfo   docker.Env
    Information   docker.Env
    // contains filtered or unexported fields
}

FakeDockerClient is a simple fake docker client, so that kubelet can be run for testing without requiring a real docker setup.

func (*FakeDockerClient) AssertCalls Uses

func (f *FakeDockerClient) AssertCalls(calls []string) (err error)

func (*FakeDockerClient) AssertCreated Uses

func (f *FakeDockerClient) AssertCreated(created []string) error

func (*FakeDockerClient) AssertStopped Uses

func (f *FakeDockerClient) AssertStopped(stopped []string) error

func (*FakeDockerClient) AssertUnorderedCalls Uses

func (f *FakeDockerClient) AssertUnorderedCalls(calls []string) (err error)

func (*FakeDockerClient) ClearCalls Uses

func (f *FakeDockerClient) ClearCalls()

func (*FakeDockerClient) CreateContainer Uses

func (f *FakeDockerClient) CreateContainer(c docker.CreateContainerOptions) (*docker.Container, error)

CreateContainer is a test-spy implementation of DockerInterface.CreateContainer. It adds an entry "create" to the internal method call record.

func (*FakeDockerClient) CreateExec Uses

func (f *FakeDockerClient) CreateExec(_ docker.CreateExecOptions) (*docker.Exec, error)

func (*FakeDockerClient) Info Uses

func (f *FakeDockerClient) Info() (*docker.Env, error)

func (*FakeDockerClient) InspectContainer Uses

func (f *FakeDockerClient) InspectContainer(id string) (*docker.Container, error)

InspectContainer is a test-spy implementation of DockerInterface.InspectContainer. It adds an entry "inspect" to the internal method call record.

func (*FakeDockerClient) InspectImage Uses

func (f *FakeDockerClient) InspectImage(name string) (*docker.Image, error)

InspectImage is a test-spy implementation of DockerInterface.InspectImage. It adds an entry "inspect" to the internal method call record.

func (*FakeDockerClient) ListContainers Uses

func (f *FakeDockerClient) ListContainers(options docker.ListContainersOptions) ([]docker.APIContainers, error)

ListContainers is a test-spy implementation of DockerInterface.ListContainers. It adds an entry "list" to the internal method call record.

func (*FakeDockerClient) ListImages Uses

func (f *FakeDockerClient) ListImages(opts docker.ListImagesOptions) ([]docker.APIImages, error)

func (*FakeDockerClient) Logs Uses

func (f *FakeDockerClient) Logs(opts docker.LogsOptions) error

Logs is a test-spy implementation of DockerInterface.Logs. It adds an entry "logs" to the internal method call record.

func (*FakeDockerClient) PullImage Uses

func (f *FakeDockerClient) PullImage(opts docker.PullImageOptions, auth docker.AuthConfiguration) error

PullImage is a test-spy implementation of DockerInterface.StopContainer. It adds an entry "pull" to the internal method call record.

func (*FakeDockerClient) RemoveContainer Uses

func (f *FakeDockerClient) RemoveContainer(opts docker.RemoveContainerOptions) error

func (*FakeDockerClient) RemoveImage Uses

func (f *FakeDockerClient) RemoveImage(image string) error

func (*FakeDockerClient) StartContainer Uses

func (f *FakeDockerClient) StartContainer(id string, hostConfig *docker.HostConfig) error

StartContainer is a test-spy implementation of DockerInterface.StartContainer. It adds an entry "start" to the internal method call record.

func (*FakeDockerClient) StartExec Uses

func (f *FakeDockerClient) StartExec(_ string, _ docker.StartExecOptions) error

func (*FakeDockerClient) StopContainer Uses

func (f *FakeDockerClient) StopContainer(id string, timeout uint) error

StopContainer is a test-spy implementation of DockerInterface.StopContainer. It adds an entry "stop" to the internal method call record.

func (*FakeDockerClient) Version Uses

func (f *FakeDockerClient) Version() (*docker.Env, error)

type FakeDockerPuller Uses

type FakeDockerPuller struct {
    sync.Mutex

    HasImages    []string
    ImagesPulled []string

    // Every pull will return the first error here, and then reslice
    // to remove it. Will give nil errors if this slice is empty.
    ErrorsToInject []error
}

FakeDockerPuller is a stub implementation of DockerPuller.

func (*FakeDockerPuller) IsImagePresent Uses

func (f *FakeDockerPuller) IsImagePresent(name string) (bool, error)

func (*FakeDockerPuller) Pull Uses

func (f *FakeDockerPuller) Pull(image string) (err error)

Pull records the image pull attempt, and optionally injects an error.

type KubeletContainerName Uses

type KubeletContainerName struct {
    PodFullName   string
    PodUID        types.UID
    ContainerName string
}

KubeletContainerName encapsulates a pod name and a Kubernetes container name.

func ParseDockerName Uses

func ParseDockerName(name string) (dockerName *KubeletContainerName, hash uint64, err error)

Unpacks a container name, returning the pod full name and container name we would have used to construct the docker name. If we are unable to parse the name, an error is returned.

type PodContainerChangesSpec Uses

type PodContainerChangesSpec struct {
    StartInfraContainer bool
    InfraContainerId    kubeletTypes.DockerID
    ContainersToStart   map[int]empty
    ContainersToKeep    map[kubeletTypes.DockerID]int
}

Package dockertools imports 36 packages (graph). Updated 2017-05-11. Refresh now. Tools for package owners.