dockertools

package
v1.2.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 8, 2016 License: Apache-2.0 Imports: 50 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PodInfraContainerName = leaky.PodInfraContainerName
	DockerPrefix          = "docker://"
	LogSuffix             = "log"
)
View Source
const (
	DockerType = "docker"

	DockerNetnsFmt = "/proc/%v/ns/net"
)

Variables

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

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

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

Functions

func BuildDockerName

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

Creates a name which can be reversed to identify both full pod name and container name. This function returns stable name, unique name and an unique id. Although rand.Uint32() is not really unique, but it's enough for us because error will only occur when instances of the same container in the same pod have the same UID. The chance is really slim.

func GetContainerName added in v1.2.0

func GetContainerName(labels map[string]string) string

func GetKubeletDockerContainers

func GetKubeletDockerContainers(client DockerInterface, allContainers bool) ([]*docker.APIContainers, error)

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

func GetPodName added in v1.2.0

func GetPodName(labels map[string]string) string

func GetPodNamespace added in v1.2.0

func GetPodNamespace(labels map[string]string) string

func GetPodUID added in v1.2.0

func GetPodUID(labels map[string]string) string
func LogSymlink(containerLogsDir, podFullName, containerName, dockerId string) string

func NewContainerGC added in v1.2.0

func NewContainerGC(client DockerInterface, podGetter podGetter, containerLogsDir string) *containerGC

func PodInfraContainerEnv added in v1.2.0

func PodInfraContainerEnv(env map[string]string) kubecontainer.Option

func SetContainerNamePrefix added in v1.2.0

func SetContainerNamePrefix(prefix string)

SetContainerNamePrefix allows the container prefix name for this process to be changed. This is intended to support testing and bootstrapping experimentation. It cannot be changed once the Kubelet starts.

Types

type DockerInterface

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
	InspectExec(id string) (*docker.ExecInspect, error)
	AttachToContainer(opts docker.AttachToContainerOptions) error
}

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

func ConnectToDockerOrDie added in v0.11.0

func ConnectToDockerOrDie(dockerEndpoint string) DockerInterface

func NewInstrumentedDockerInterface added in v0.16.0

func NewInstrumentedDockerInterface(dockerClient DockerInterface) DockerInterface

Creates an instrumented DockerInterface from an existing DockerInterface.

type DockerManager added in v0.15.0

type DockerManager struct {
	// contains filtered or unexported fields
}

func NewDockerManager added in v0.15.0

func NewDockerManager(
	client DockerInterface,
	recorder record.EventRecorder,
	livenessManager proberesults.Manager,
	containerRefManager *kubecontainer.RefManager,
	podGetter podGetter,
	machineInfo *cadvisorapi.MachineInfo,
	podInfraContainerImage string,
	qps float32,
	burst int,
	containerLogsDir string,
	osInterface kubecontainer.OSInterface,
	networkPlugin network.NetworkPlugin,
	runtimeHelper kubecontainer.RuntimeHelper,
	httpClient kubetypes.HttpGetter,
	execHandler ExecHandler,
	oomAdjuster *oom.OOMAdjuster,
	procFs procfs.ProcFSInterface,
	cpuCFSQuota bool,
	imageBackOff *util.Backoff,
	serializeImagePulls bool,
	enableCustomMetrics bool,
	hairpinMode bool,
	options ...kubecontainer.Option) *DockerManager

func NewFakeDockerManager added in v0.17.0

func NewFakeDockerManager(
	client DockerInterface,
	recorder record.EventRecorder,
	livenessManager proberesults.Manager,
	containerRefManager *kubecontainer.RefManager,
	machineInfo *cadvisorapi.MachineInfo,
	podInfraContainerImage string,
	qps float32,
	burst int,
	containerLogsDir string,
	osInterface kubecontainer.OSInterface,
	networkPlugin network.NetworkPlugin,
	runtimeHelper kubecontainer.RuntimeHelper,
	httpClient kubetypes.HttpGetter, imageBackOff *util.Backoff) *DockerManager

func (*DockerManager) APIVersion added in v1.2.0

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

func (*DockerManager) AttachContainer added in v1.1.0

func (dm *DockerManager) AttachContainer(containerID kubecontainer.ContainerID, stdin io.Reader, stdout, stderr io.WriteCloser, tty bool) error

func (*DockerManager) ExecInContainer added in v0.16.0

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

ExecInContainer runs the command inside the container identified by containerID.

func (*DockerManager) GarbageCollect added in v1.2.0

func (dm *DockerManager) GarbageCollect(gcPolicy kubecontainer.ContainerGCPolicy) error

Garbage collection of dead containers

func (*DockerManager) GetContainerIP added in v1.1.1

func (dm *DockerManager) GetContainerIP(containerID, interfaceName string) (string, error)

Get the IP address of a container's interface using nsenter

func (*DockerManager) GetContainerLogs added in v0.17.0

func (dm *DockerManager) GetContainerLogs(pod *api.Pod, containerID kubecontainer.ContainerID, logOptions *api.PodLogOptions, 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 added in v0.17.0

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) GetNetNS added in v1.2.0

func (dm *DockerManager) GetNetNS(containerID kubecontainer.ContainerID) (string, error)

GetNetNS returns the network namespace path for the given container

func (*DockerManager) GetPodStatus added in v0.15.0

func (dm *DockerManager) GetPodStatus(uid types.UID, name, namespace string) (*kubecontainer.PodStatus, error)

func (*DockerManager) GetPods added in v0.16.0

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

func (*DockerManager) IsImagePresent added in v0.16.0

func (dm *DockerManager) IsImagePresent(image kubecontainer.ImageSpec) (bool, error)

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

func (*DockerManager) KillContainerInPod added in v0.17.0

func (dm *DockerManager) KillContainerInPod(containerID kubecontainer.ContainerID, container *api.Container, pod *api.Pod, message string) error

KillContainerInPod kills a container in the pod. It must be passed either a container ID or a container and pod, and will attempt to lookup the other information if missing.

func (*DockerManager) KillPod added in v0.16.0

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

TODO(random-liu): Change running pod to pod status in the future. We can't do it now, because kubelet also uses this function without pod status. We can only deprecate this after refactoring kubelet. TODO(random-liu): After using pod status for KillPod(), we can also remove the kubernetesPodLabel, because all the needed information should have been extract from new labels and stored in pod status.

func (*DockerManager) ListImages added in v0.17.0

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

List all images in the local storage.

func (*DockerManager) PortForward added in v0.16.0

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 added in v0.17.0

func (dm *DockerManager) PullImage(image kubecontainer.ImageSpec, secrets []api.Secret) error

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

func (*DockerManager) RemoveImage added in v0.17.0

func (dm *DockerManager) RemoveImage(image kubecontainer.ImageSpec) error

Removes the specified image.

func (*DockerManager) RunInContainer added in v0.16.0

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

RunInContainer uses nsinit to run the command inside the container identified by containerID

func (*DockerManager) Status added in v1.2.0

func (dm *DockerManager) Status() error

Status returns error if docker daemon is unhealthy, nil otherwise. Now we do this by checking whether: 1) `docker version` works 2) docker version is compatible with minimum requirement

func (*DockerManager) SyncPod added in v0.17.0

func (dm *DockerManager) SyncPod(pod *api.Pod, _ api.PodStatus, podStatus *kubecontainer.PodStatus, pullSecrets []api.Secret, backOff *util.Backoff) (result kubecontainer.PodSyncResult)

Sync the running pod to match the specified desired pod.

func (*DockerManager) Type added in v1.1.1

func (dm *DockerManager) Type() string

func (*DockerManager) Version added in v0.16.0

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

type DockerPuller

type DockerPuller interface {
	Pull(image string, secrets []api.Secret) error
	IsImagePresent(image string) (bool, error)
}

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

type ExecHandler added in v0.19.0

type ExecHandler interface {
	ExecInContainer(client DockerInterface, container *docker.Container, cmd []string, stdin io.Reader, stdout, stderr io.WriteCloser, tty bool) error
}

ExecHandler knows how to execute a command in a running Docker container.

type FakeDockerClient

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

	// Created, Stopped and Removed all container docker ID
	Created       []string
	Stopped       []string
	Removed       []string
	RemovedImages sets.String
	VersionInfo   docker.Env
	Information   docker.Env
	ExecInspect   *docker.ExecInspect

	EnableSleep bool
	// 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 NewFakeDockerClient added in v1.2.0

func NewFakeDockerClient() *FakeDockerClient

func NewFakeDockerClientWithVersion added in v1.2.0

func NewFakeDockerClientWithVersion(version, apiVersion string) *FakeDockerClient

func (*FakeDockerClient) AssertCalls

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

func (*FakeDockerClient) AssertCreated added in v0.15.0

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

func (*FakeDockerClient) AssertStopped added in v0.15.0

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

func (*FakeDockerClient) AssertUnorderedCalls added in v0.14.0

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

func (*FakeDockerClient) AttachToContainer added in v1.1.0

func (f *FakeDockerClient) AttachToContainer(opts docker.AttachToContainerOptions) error

func (*FakeDockerClient) ClearCalls added in v0.8.0

func (f *FakeDockerClient) ClearCalls()

func (*FakeDockerClient) ClearErrors added in v1.2.0

func (f *FakeDockerClient) ClearErrors()

func (*FakeDockerClient) CreateContainer

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

func (*FakeDockerClient) CreateExec added in v0.5.1

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

func (*FakeDockerClient) Info added in v0.16.0

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

func (*FakeDockerClient) InjectError added in v1.2.0

func (f *FakeDockerClient) InjectError(fn string, err error)

func (*FakeDockerClient) InjectErrors added in v1.2.0

func (f *FakeDockerClient) InjectErrors(errs map[string]error)

func (*FakeDockerClient) InspectContainer

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) InspectExec added in v0.18.0

func (f *FakeDockerClient) InspectExec(id string) (*docker.ExecInspect, error)

func (*FakeDockerClient) InspectImage

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

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 added in v0.8.0

func (*FakeDockerClient) Logs

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

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

func (*FakeDockerClient) RemoveContainer added in v0.4.2

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

func (*FakeDockerClient) RemoveImage added in v0.8.0

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

func (*FakeDockerClient) SetFakeContainers added in v1.2.0

func (f *FakeDockerClient) SetFakeContainers(containers []*docker.Container)

func (*FakeDockerClient) SetFakeRunningContainers added in v1.2.0

func (f *FakeDockerClient) SetFakeRunningContainers(containers []*docker.Container)

func (*FakeDockerClient) StartContainer

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

StartContainer is a test-spy implementation of DockerInterface.StartContainer. It adds an entry "start" to the internal method call record. The HostConfig at StartContainer will be deprecated from docker 1.10. Now in docker manager the HostConfig is set when CreateContainer(). TODO(random-liu): Remove the HostConfig here when it is completely removed in docker 1.12.

func (*FakeDockerClient) StartExec added in v0.5.1

func (*FakeDockerClient) StopContainer

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 added in v0.5.1

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

type FakeDockerPuller

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

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

func (*FakeDockerPuller) Pull

func (f *FakeDockerPuller) Pull(image string, secrets []api.Secret) (err error)

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

type KubeletContainerName added in v0.14.0

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

KubeletContainerName encapsulates a pod name and a Kubernetes container name.

func ParseDockerName

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 NativeExecHandler added in v0.19.0

type NativeExecHandler struct{}

NativeExecHandler executes commands in Docker containers using Docker's exec API.

func (*NativeExecHandler) ExecInContainer added in v0.19.0

func (*NativeExecHandler) ExecInContainer(client DockerInterface, container *docker.Container, cmd []string, stdin io.Reader, stdout, stderr io.WriteCloser, tty bool) error

type NsenterExecHandler added in v0.19.0

type NsenterExecHandler struct{}

NsenterExecHandler executes commands in Docker containers using nsenter.

func (*NsenterExecHandler) ExecInContainer added in v0.19.0

func (*NsenterExecHandler) ExecInContainer(client DockerInterface, container *docker.Container, cmd []string, stdin io.Reader, stdout, stderr io.WriteCloser, tty bool) error

TODO should we support nsenter in a container, running with elevated privs and --pid=host?

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL