Documentation ¶
Index ¶
- Constants
- Variables
- func BuildDockerName(dockerName KubeletContainerName, container *api.Container) (string, string)
- func LogSymlink(containerLogsDir, podFullName, containerName, dockerId string) string
- func NewVersion(input string) (dockerVersion, error)
- type DockerContainers
- type DockerInterface
- type DockerManager
- func (dm *DockerManager) AttachContainer(containerId string, stdin io.Reader, stdout, stderr io.WriteCloser, tty bool) error
- func (dm *DockerManager) ExecInContainer(containerId string, cmd []string, stdin io.Reader, ...) error
- func (dm *DockerManager) GetContainerLogs(pod *api.Pod, containerID string, logOptions *api.PodLogOptions, ...) (err error)
- func (dm *DockerManager) GetContainers(all bool) ([]*kubecontainer.Container, error)
- func (dm *DockerManager) GetPodStatus(pod *api.Pod) (*api.PodStatus, error)
- func (dm *DockerManager) GetPods(all bool) ([]*kubecontainer.Pod, error)
- func (dm *DockerManager) IsImagePresent(image kubecontainer.ImageSpec) (bool, error)
- func (dm *DockerManager) KillContainerInPod(containerID types.UID, container *api.Container, pod *api.Pod) error
- func (dm *DockerManager) KillPod(pod *api.Pod, runningPod kubecontainer.Pod) error
- func (dm *DockerManager) ListImages() ([]kubecontainer.Image, error)
- func (dm *DockerManager) PortForward(pod *kubecontainer.Pod, port uint16, stream io.ReadWriteCloser) error
- func (dm *DockerManager) PullImage(image kubecontainer.ImageSpec, secrets []api.Secret) error
- func (dm *DockerManager) RemoveImage(image kubecontainer.ImageSpec) error
- func (dm *DockerManager) RunInContainer(containerID string, cmd []string) ([]byte, error)
- func (dm *DockerManager) SyncPod(pod *api.Pod, runningPod kubecontainer.Pod, podStatus api.PodStatus, ...) error
- func (dm *DockerManager) Version() (kubecontainer.Version, error)
- type DockerPuller
- type ExecHandler
- type FakeDockerClient
- func (f *FakeDockerClient) AssertCalls(calls []string) (err error)
- func (f *FakeDockerClient) AssertCreated(created []string) error
- func (f *FakeDockerClient) AssertStopped(stopped []string) error
- func (f *FakeDockerClient) AssertUnorderedCalls(calls []string) (err error)
- func (f *FakeDockerClient) AttachToContainer(opts docker.AttachToContainerOptions) error
- func (f *FakeDockerClient) ClearCalls()
- func (f *FakeDockerClient) CreateContainer(c docker.CreateContainerOptions) (*docker.Container, error)
- func (f *FakeDockerClient) CreateExec(opts docker.CreateExecOptions) (*docker.Exec, error)
- func (f *FakeDockerClient) Info() (*docker.Env, error)
- func (f *FakeDockerClient) InspectContainer(id string) (*docker.Container, error)
- func (f *FakeDockerClient) InspectExec(id string) (*docker.ExecInspect, error)
- func (f *FakeDockerClient) InspectImage(name string) (*docker.Image, error)
- func (f *FakeDockerClient) ListContainers(options docker.ListContainersOptions) ([]docker.APIContainers, error)
- func (f *FakeDockerClient) ListImages(opts docker.ListImagesOptions) ([]docker.APIImages, error)
- func (f *FakeDockerClient) Logs(opts docker.LogsOptions) error
- func (f *FakeDockerClient) PullImage(opts docker.PullImageOptions, auth docker.AuthConfiguration) error
- func (f *FakeDockerClient) RemoveContainer(opts docker.RemoveContainerOptions) error
- func (f *FakeDockerClient) RemoveImage(image string) error
- func (f *FakeDockerClient) StartContainer(id string, hostConfig *docker.HostConfig) error
- func (f *FakeDockerClient) StartExec(_ string, _ docker.StartExecOptions) error
- func (f *FakeDockerClient) StopContainer(id string, timeout uint) error
- func (f *FakeDockerClient) Version() (*docker.Env, error)
- type FakeDockerPuller
- type KubeletContainerName
- type NativeExecHandler
- type NsenterExecHandler
- type PodContainerChangesSpec
Constants ¶
const ( PodInfraContainerName = leaky.PodInfraContainerName DockerPrefix = "docker://" PodInfraContainerImage = "gcr.io/google_containers/pause:0.8.0" LogSuffix = "log" )
Variables ¶
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)
Creates a name which can be reversed to identify both full pod name and container name.
func LogSymlink ¶
func NewVersion ¶
Types ¶
type DockerContainers ¶
type DockerContainers map[kubeletTypes.DockerID]*docker.APIContainers
DockerContainers is a map of containers
func GetKubeletDockerContainers ¶
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 ¶
func (c DockerContainers) FindPodContainer(podFullName string, uid types.UID, containerName string) (*docker.APIContainers, bool, uint64)
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 ¶
func ConnectToDockerOrDie(dockerEndpoint string) DockerInterface
func NewInstrumentedDockerInterface ¶
func NewInstrumentedDockerInterface(dockerClient DockerInterface) DockerInterface
Creates an instrumented DockerInterface from an existing DockerInterface.
type DockerManager ¶
type DockerManager struct {
// contains filtered or unexported fields
}
func NewDockerManager ¶
func NewDockerManager( client DockerInterface, recorder record.EventRecorder, readinessManager *kubecontainer.ReadinessManager, containerRefManager *kubecontainer.RefManager, machineInfo *cadvisorApi.MachineInfo, podInfraContainerImage string, qps float32, burst int, containerLogsDir string, osInterface kubecontainer.OSInterface, networkPlugin network.NetworkPlugin, generator kubecontainer.RunContainerOptionsGenerator, httpClient kubeletTypes.HttpGetter, execHandler ExecHandler, oomAdjuster *oom.OomAdjuster, procFs procfs.ProcFsInterface, cpuCFSQuota bool) *DockerManager
func NewFakeDockerManager ¶
func NewFakeDockerManager( client DockerInterface, recorder record.EventRecorder, readinessManager *kubecontainer.ReadinessManager, containerRefManager *kubecontainer.RefManager, machineInfo *cadvisorApi.MachineInfo, podInfraContainerImage string, qps float32, burst int, containerLogsDir string, osInterface kubecontainer.OSInterface, networkPlugin network.NetworkPlugin, generator kubecontainer.RunContainerOptionsGenerator, httpClient kubeletTypes.HttpGetter) *DockerManager
func (*DockerManager) AttachContainer ¶
func (dm *DockerManager) AttachContainer(containerId string, stdin io.Reader, stdout, stderr io.WriteCloser, tty bool) error
func (*DockerManager) ExecInContainer ¶
func (dm *DockerManager) ExecInContainer(containerId string, cmd []string, stdin io.Reader, stdout, stderr io.WriteCloser, tty bool) error
ExecInContainer runs the command inside the container identified by containerID.
TODO:
- use strong type for containerId
func (*DockerManager) GetContainerLogs ¶
func (dm *DockerManager) GetContainerLogs(pod *api.Pod, containerID string, 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 ¶
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) GetPodStatus ¶
GetPodStatus returns docker related status for all containers in the pod as well as the infrastructure container.
func (*DockerManager) GetPods ¶
func (dm *DockerManager) GetPods(all bool) ([]*kubecontainer.Pod, error)
func (*DockerManager) IsImagePresent ¶
func (dm *DockerManager) IsImagePresent(image kubecontainer.ImageSpec) (bool, error)
IsImagePresent checks whether the container image is already in the local storage.
func (*DockerManager) KillContainerInPod ¶
func (dm *DockerManager) KillContainerInPod(containerID types.UID, container *api.Container, pod *api.Pod) 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 ¶
func (dm *DockerManager) KillPod(pod *api.Pod, runningPod kubecontainer.Pod) error
Kills all containers in the specified pod
func (*DockerManager) ListImages ¶
func (dm *DockerManager) ListImages() ([]kubecontainer.Image, error)
List all images in the local storage.
func (*DockerManager) PortForward ¶
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 ¶
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 ¶
func (dm *DockerManager) RemoveImage(image kubecontainer.ImageSpec) error
Removes the specified image.
func (*DockerManager) RunInContainer ¶
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 ¶
func (dm *DockerManager) SyncPod(pod *api.Pod, runningPod kubecontainer.Pod, podStatus api.PodStatus, pullSecrets []api.Secret, backOff *util.Backoff) error
Sync the running pod to match the specified desired pod.
func (*DockerManager) Version ¶
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 ¶
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 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 sets.String VersionInfo docker.Env Information docker.Env ExecInspect *docker.ExecInspect // 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. TODO: create a proper constructor for FakeDockerClient, so we won't need to check if ContainerMap is not nil.
func (*FakeDockerClient) AssertCalls ¶
func (f *FakeDockerClient) AssertCalls(calls []string) (err error)
func (*FakeDockerClient) AssertCreated ¶
func (f *FakeDockerClient) AssertCreated(created []string) error
func (*FakeDockerClient) AssertStopped ¶
func (f *FakeDockerClient) AssertStopped(stopped []string) error
func (*FakeDockerClient) AssertUnorderedCalls ¶
func (f *FakeDockerClient) AssertUnorderedCalls(calls []string) (err error)
func (*FakeDockerClient) AttachToContainer ¶
func (f *FakeDockerClient) AttachToContainer(opts docker.AttachToContainerOptions) error
func (*FakeDockerClient) ClearCalls ¶
func (f *FakeDockerClient) ClearCalls()
func (*FakeDockerClient) CreateContainer ¶
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 ¶
func (f *FakeDockerClient) CreateExec(opts docker.CreateExecOptions) (*docker.Exec, 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 ¶
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 ¶
func (f *FakeDockerClient) ListImages(opts docker.ListImagesOptions) ([]docker.APIImages, error)
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 ¶
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 ¶
func (f *FakeDockerClient) RemoveContainer(opts docker.RemoveContainerOptions) error
func (*FakeDockerClient) RemoveImage ¶
func (f *FakeDockerClient) RemoveImage(image string) error
func (*FakeDockerClient) StartContainer ¶
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 ¶
func (f *FakeDockerClient) StartExec(_ string, _ docker.StartExecOptions) error
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.
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)
type KubeletContainerName ¶
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 ¶
type NativeExecHandler struct{}
NativeExecHandler executes commands in Docker containers using Docker's exec API.
func (*NativeExecHandler) ExecInContainer ¶
func (*NativeExecHandler) ExecInContainer(client DockerInterface, container *docker.Container, cmd []string, stdin io.Reader, stdout, stderr io.WriteCloser, tty bool) error
type NsenterExecHandler ¶
type NsenterExecHandler struct{}
NsenterExecHandler executes commands in Docker containers using nsenter.
func (*NsenterExecHandler) ExecInContainer ¶
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?
type PodContainerChangesSpec ¶
type PodContainerChangesSpec struct { StartInfraContainer bool InfraContainerId kubeletTypes.DockerID ContainersToStart map[int]empty ContainersToKeep map[kubeletTypes.DockerID]int }