Documentation
¶
Index ¶
- Constants
- Variables
- func BuildDockerName(dockerName KubeletContainerName, container *api.Container) string
- func GetPods(client DockerInterface, all bool) ([]*kubecontainer.Pod, error)
- func HashContainer(container *api.Container) uint64
- func StartPty(c *exec.Cmd) (*os.File, error)
- type ContainerCommandRunner
- type DockerCache
- type DockerContainers
- func (c DockerContainers) FindContainersByPod(podUID types.UID, podFullName string) DockerContainers
- func (c DockerContainers) FindPodContainer(podFullName string, uid types.UID, containerName string) (*docker.APIContainers, bool, uint64)
- func (c DockerContainers) RemoveContainerWithID(containerID DockerID)
- type DockerID
- type DockerInterface
- type DockerManager
- func (self *DockerManager) GetKubeletDockerContainerLogs(containerID, tail string, follow bool, stdout, stderr io.Writer) (err error)
- func (self *DockerManager) GetPodStatus(pod *api.Pod) (*api.PodStatus, error)
- func (self *DockerManager) GetRunningContainers(ids []string) ([]*docker.Container, error)
- func (self *DockerManager) RunContainer(pod *api.Pod, container *api.Container, ...) (string, error)
- type DockerPuller
- type FakeDockerCache
- 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) ClearCalls()
- func (f *FakeDockerClient) CreateContainer(c docker.CreateContainerOptions) (*docker.Container, error)
- func (f *FakeDockerClient) CreateExec(_ docker.CreateExecOptions) (*docker.Exec, error)
- func (f *FakeDockerClient) InspectContainer(id string) (*docker.Container, 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
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") )
Functions ¶
func BuildDockerName ¶
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 GetPods ¶ added in v0.14.0
func GetPods(client DockerInterface, all bool) ([]*kubecontainer.Pod, error)
TODO: Move this function with dockerCache to DockerManager.
func HashContainer ¶
Types ¶
type ContainerCommandRunner ¶
type ContainerCommandRunner interface { RunInContainer(containerID string, cmd []string) ([]byte, error) GetDockerServerVersion() ([]uint, 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 }
TODO(yifan): Move this to container.Runtime.
func NewDockerContainerCommandRunner ¶
func NewDockerContainerCommandRunner(client DockerInterface) ContainerCommandRunner
NewDockerContainerCommandRunner creates a ContainerCommandRunner which uses nsinit to run a command inside a container.
type DockerCache ¶ added in v0.12.0
type DockerCache interface { GetPods() ([]*container.Pod, error) ForceUpdateIfOlder(time.Time) error }
func NewDockerCache ¶ added in v0.12.0
func NewDockerCache(client DockerInterface) (DockerCache, error)
func NewFakeDockerCache ¶ added in v0.12.0
func NewFakeDockerCache(client DockerInterface) DockerCache
type DockerContainers ¶
type DockerContainers map[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) FindContainersByPod ¶ added in v0.13.0
func (c DockerContainers) FindContainersByPod(podUID types.UID, podFullName string) DockerContainers
FindContainersByPod returns the containers that belong to the pod.
func (DockerContainers) FindPodContainer ¶
func (c DockerContainers) FindPodContainer(podFullName string, uid types.UID, containerName string) (*docker.APIContainers, bool, uint64)
func (DockerContainers) RemoveContainerWithID ¶ added in v0.13.0
func (c DockerContainers) RemoveContainerWithID(containerID DockerID)
RemoveContainerWithID removes the container with the given containerID.
type DockerID ¶
type DockerID string
DockerID is an ID of docker container. It is a type to make it clear when we're working with docker container Ids
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) 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 ¶ added in v0.11.0
func ConnectToDockerOrDie(dockerEndpoint string) DockerInterface
type DockerManager ¶ added in v0.15.0
type DockerManager struct { // TODO(yifan): PodInfraContainerImage can be unexported once // we move createPodInfraContainer into dockertools. PodInfraContainerImage string // contains filtered or unexported fields }
Implements kubecontainer.ContainerRunner. TODO: Eventually DockerManager should implement kubecontainer.Runtime interface, and it should also add a cache to replace dockerCache.
func NewDockerManager ¶ added in v0.15.0
func NewDockerManager(client DockerInterface, recorder record.EventRecorder, podInfraContainerImage string) *DockerManager
func (*DockerManager) GetKubeletDockerContainerLogs ¶ added in v0.15.0
func (self *DockerManager) GetKubeletDockerContainerLogs(containerID, tail string, follow bool, stdout, stderr io.Writer) (err error)
GetKubeletDockerContainerLogs 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) GetPodStatus ¶ added in v0.15.0
GetPodStatus returns docker related status for all containers in the pod as well as the infrastructure container.
func (*DockerManager) GetRunningContainers ¶ added in v0.15.0
func (self *DockerManager) GetRunningContainers(ids []string) ([]*docker.Container, error)
func (*DockerManager) RunContainer ¶ added in v0.15.0
func (self *DockerManager) RunContainer(pod *api.Pod, container *api.Container, opts *kubecontainer.RunContainerOptions) (string, error)
type DockerPuller ¶
DockerPuller is an abstract interface for testability. It abstracts image pull operations.
func NewDockerPuller ¶
func NewDockerPuller(client DockerInterface, qps float32, burst int) DockerPuller
NewDockerPuller creates a new instance of the default implementation of DockerPuller.
type FakeDockerCache ¶ added in v0.12.0
type FakeDockerCache struct {
// contains filtered or unexported fields
}
func (*FakeDockerCache) ForceUpdateIfOlder ¶ added in v0.13.0
func (f *FakeDockerCache) ForceUpdateIfOlder(time.Time) error
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 util.StringSet VersionInfo 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 ¶
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) ClearCalls ¶ added in v0.8.2
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 ¶ added in v0.5.1
func (f *FakeDockerClient) CreateExec(_ 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) 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.2
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 ¶ added in v0.4.2
func (f *FakeDockerClient) RemoveContainer(opts docker.RemoveContainerOptions) error
func (*FakeDockerClient) RemoveImage ¶ added in v0.8.2
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 ¶ added in v0.5.1
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.
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) (err error)
Pull records the image pull attempt, and optionally injects an error.
type KubeletContainerName ¶ added in v0.14.0
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.