Documentation
¶
Index ¶
- Constants
- func BuildDockerName(dockerName KubeletContainerName, container *v1.Container) (string, string, string)
- func GetFakeContainerID(name string) string
- func GetKubeletDockerContainers(client DockerInterface, allContainers bool) ([]*dockertypes.Container, error)
- func IsContainerNotFoundError(err error) bool
- func IsImageNotFoundError(err error) bool
- func LogSymlink(containerLogsDir, podFullName, containerName, dockerId string) string
- func NewCalledDetail(name string, arguments []interface{}) calledDetail
- func ParseDockerTimestamp(s string) (time.Time, error)
- func SetContainerNamePrefix(prefix string)
- type DockerInterface
- type DockerPuller
- type FakeContainer
- type FakeDockerClient
- func (f *FakeDockerClient) AssertCallDetails(calls ...calledDetail) (err error)
- func (f *FakeDockerClient) AssertCalls(calls []string) (err error)
- func (f *FakeDockerClient) AssertCreatedByName(created []string) error
- func (f *FakeDockerClient) AssertCreatedByNameWithOrder(created []string) error
- func (f *FakeDockerClient) AssertImagesPulled(pulled []string) error
- func (f *FakeDockerClient) AssertStopped(stopped []string) error
- func (f *FakeDockerClient) AssertStoppedByName(stopped []string) error
- func (f *FakeDockerClient) AttachToContainer(id string, opts dockertypes.ContainerAttachOptions, sopts StreamOptions) error
- func (f *FakeDockerClient) ClearCalls()
- func (f *FakeDockerClient) ClearErrors()
- func (f *FakeDockerClient) CreateContainer(c dockertypes.ContainerCreateConfig) (*dockertypes.ContainerCreateResponse, error)
- func (f *FakeDockerClient) CreateExec(id string, opts dockertypes.ExecConfig) (*dockertypes.ContainerExecCreateResponse, error)
- func (f *FakeDockerClient) ImageHistory(id string) ([]dockertypes.ImageHistory, error)
- func (f *FakeDockerClient) Info() (*dockertypes.Info, error)
- func (f *FakeDockerClient) InjectError(fn string, err error)
- func (f *FakeDockerClient) InjectErrors(errs map[string]error)
- func (f *FakeDockerClient) InjectImageHistory(data map[string][]dockertypes.ImageHistory)
- func (f *FakeDockerClient) InjectImageInspects(inspects []dockertypes.ImageInspect)
- func (f *FakeDockerClient) InjectImages(images []dockertypes.Image)
- func (f *FakeDockerClient) InspectContainer(id string) (*dockertypes.ContainerJSON, error)
- func (f *FakeDockerClient) InspectExec(id string) (*dockertypes.ContainerExecInspect, error)
- func (f *FakeDockerClient) InspectImageByID(name string) (*dockertypes.ImageInspect, error)
- func (f *FakeDockerClient) InspectImageByRef(name string) (*dockertypes.ImageInspect, error)
- func (f *FakeDockerClient) ListContainers(options dockertypes.ContainerListOptions) ([]dockertypes.Container, error)
- func (f *FakeDockerClient) ListImages(opts dockertypes.ImageListOptions) ([]dockertypes.Image, error)
- func (f *FakeDockerClient) Logs(id string, opts dockertypes.ContainerLogsOptions, sopts StreamOptions) error
- func (f *FakeDockerClient) PullImage(image string, auth dockertypes.AuthConfig, opts dockertypes.ImagePullOptions) error
- func (f *FakeDockerClient) RemoveContainer(id string, opts dockertypes.ContainerRemoveOptions) error
- func (f *FakeDockerClient) RemoveImage(image string, opts dockertypes.ImageRemoveOptions) ([]dockertypes.ImageDelete, error)
- func (f *FakeDockerClient) ResetImages()
- func (f *FakeDockerClient) ResizeContainerTTY(id string, height, width int) error
- func (f *FakeDockerClient) ResizeExecTTY(id string, height, width int) error
- func (f *FakeDockerClient) SetFakeContainers(containers []*FakeContainer)
- func (f *FakeDockerClient) SetFakeRunningContainers(containers []*FakeContainer)
- func (f *FakeDockerClient) StartContainer(id string) error
- func (f *FakeDockerClient) StartExec(startExec string, opts dockertypes.ExecStartCheck, sopts StreamOptions) error
- func (f *FakeDockerClient) StopContainer(id string, timeout int) error
- func (f *FakeDockerClient) Version() (*dockertypes.Version, error)
- func (f *FakeDockerClient) WithClock(c clock.Clock) *FakeDockerClient
- func (f *FakeDockerClient) WithTraceDisabled() *FakeDockerClient
- func (f *FakeDockerClient) WithVersion(version, apiVersion string) *FakeDockerClient
- type FakeDockerPuller
- type ImageNotFoundError
- type KubeletContainerName
- type StreamOptions
Constants ¶
const ( LogSuffix = "log" DockerType = "docker" )
Variables ¶
This section is empty.
Functions ¶
func BuildDockerName ¶
func BuildDockerName(dockerName KubeletContainerName, container *v1.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 a 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 GetFakeContainerID ¶ added in v1.6.0
GetFakeContainerID generates a fake container id from container name with a hash.
func GetKubeletDockerContainers ¶
func GetKubeletDockerContainers(client DockerInterface, allContainers bool) ([]*dockertypes.Container, error)
GetKubeletDockerContainers lists all container or just the running ones. Returns a list of docker containers that we manage TODO: This function should be deleted after migrating test/e2e_node/garbage_collector_test.go off of it.
func IsContainerNotFoundError ¶ added in v1.6.0
IsContainerNotFoundError checks whether the error is container not found error.
func IsImageNotFoundError ¶ added in v1.5.0
IsImageNotFoundError checks whether the error is image not found error. This is exposed to share with dockershim.
func LogSymlink ¶ added in v1.0.0
func NewCalledDetail ¶ added in v1.5.0
func NewCalledDetail(name string, arguments []interface{}) calledDetail
NewCalledDetail create a new call detail item.
func ParseDockerTimestamp ¶ added in v1.4.0
ParseDockerTimestamp parses the timestamp returned by DockerInterface from string to time.Time
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 dockertypes.ContainerListOptions) ([]dockertypes.Container, error) InspectContainer(id string) (*dockertypes.ContainerJSON, error) CreateContainer(dockertypes.ContainerCreateConfig) (*dockertypes.ContainerCreateResponse, error) StartContainer(id string) error StopContainer(id string, timeout int) error RemoveContainer(id string, opts dockertypes.ContainerRemoveOptions) error InspectImageByRef(imageRef string) (*dockertypes.ImageInspect, error) InspectImageByID(imageID string) (*dockertypes.ImageInspect, error) ListImages(opts dockertypes.ImageListOptions) ([]dockertypes.Image, error) PullImage(image string, auth dockertypes.AuthConfig, opts dockertypes.ImagePullOptions) error RemoveImage(image string, opts dockertypes.ImageRemoveOptions) ([]dockertypes.ImageDelete, error) ImageHistory(id string) ([]dockertypes.ImageHistory, error) Logs(string, dockertypes.ContainerLogsOptions, StreamOptions) error Version() (*dockertypes.Version, error) Info() (*dockertypes.Info, error) CreateExec(string, dockertypes.ExecConfig) (*dockertypes.ContainerExecCreateResponse, error) StartExec(string, dockertypes.ExecStartCheck, StreamOptions) error InspectExec(id string) (*dockertypes.ContainerExecInspect, error) AttachToContainer(string, dockertypes.ContainerAttachOptions, StreamOptions) error ResizeContainerTTY(id string, height, width int) error ResizeExecTTY(id string, height, width int) 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, requestTimeout, imagePullProgressDeadline time.Duration) DockerInterface
ConnectToDockerOrDie creates docker client connecting to docker daemon. If the endpoint passed in is "fake://", a fake docker client will be returned. The program exits if error occurs. The requestTimeout is the timeout for docker requests. If timeout is exceeded, the request will be cancelled and throw out an error. If requestTimeout is 0, a default value will be applied.
func NewInstrumentedDockerInterface ¶ added in v0.16.2
func NewInstrumentedDockerInterface(dockerClient DockerInterface) DockerInterface
Creates an instrumented DockerInterface from an existing DockerInterface.
type DockerPuller ¶
type DockerPuller interface { Pull(image string, secrets []v1.Secret) error GetImageRef(image string) (string, error) }
DockerPuller is an abstract interface for testability. It abstracts image pull operations.
type FakeContainer ¶ added in v1.3.0
type FakeContainer struct { ID string Name string Running bool ExitCode int Pid int CreatedAt time.Time StartedAt time.Time FinishedAt time.Time Config *dockercontainer.Config HostConfig *dockercontainer.HostConfig }
Because the new data type returned by engine-api is too complex to manually initialize, we need a fake container which is easier to initialize.
type FakeDockerClient ¶
type FakeDockerClient struct { sync.Mutex Clock clock.Clock RunningContainerList []dockertypes.Container ExitedContainerList []dockertypes.Container ContainerMap map[string]*dockertypes.ContainerJSON ImageInspects map[string]*dockertypes.ImageInspect Images []dockertypes.Image Errors map[string]error EnableTrace bool // Created, Started, Stopped and Removed all contain container docker ID Created []string Started []string Stopped []string Removed []string // Images pulled by ref (name or ID). ImagesPulled []string VersionInfo dockertypes.Version Information dockertypes.Info ExecInspect *dockertypes.ContainerExecInspect EnableSleep bool ImageHistoryMap map[string][]dockertypes.ImageHistory // 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 (*FakeDockerClient) AssertCallDetails ¶ added in v1.3.3
func (f *FakeDockerClient) AssertCallDetails(calls ...calledDetail) (err error)
func (*FakeDockerClient) AssertCalls ¶
func (f *FakeDockerClient) AssertCalls(calls []string) (err error)
func (*FakeDockerClient) AssertCreatedByName ¶ added in v1.6.0
func (f *FakeDockerClient) AssertCreatedByName(created []string) error
func (*FakeDockerClient) AssertCreatedByNameWithOrder ¶ added in v1.6.0
func (f *FakeDockerClient) AssertCreatedByNameWithOrder(created []string) error
func (*FakeDockerClient) AssertImagesPulled ¶ added in v1.6.0
func (f *FakeDockerClient) AssertImagesPulled(pulled []string) error
func (*FakeDockerClient) AssertStopped ¶ added in v0.15.0
func (f *FakeDockerClient) AssertStopped(stopped []string) error
func (*FakeDockerClient) AssertStoppedByName ¶ added in v1.6.0
func (f *FakeDockerClient) AssertStoppedByName(stopped []string) error
func (*FakeDockerClient) AttachToContainer ¶ added in v1.1.1
func (f *FakeDockerClient) AttachToContainer(id string, opts dockertypes.ContainerAttachOptions, sopts StreamOptions) 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 ¶
func (f *FakeDockerClient) CreateContainer(c dockertypes.ContainerCreateConfig) (*dockertypes.ContainerCreateResponse, 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(id string, opts dockertypes.ExecConfig) (*dockertypes.ContainerExecCreateResponse, error)
func (*FakeDockerClient) ImageHistory ¶ added in v1.3.0
func (f *FakeDockerClient) ImageHistory(id string) ([]dockertypes.ImageHistory, error)
func (*FakeDockerClient) Info ¶ added in v0.16.2
func (f *FakeDockerClient) Info() (*dockertypes.Info, 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) InjectImageHistory ¶ added in v1.3.0
func (f *FakeDockerClient) InjectImageHistory(data map[string][]dockertypes.ImageHistory)
func (*FakeDockerClient) InjectImageInspects ¶ added in v1.6.0
func (f *FakeDockerClient) InjectImageInspects(inspects []dockertypes.ImageInspect)
func (*FakeDockerClient) InjectImages ¶ added in v1.3.0
func (f *FakeDockerClient) InjectImages(images []dockertypes.Image)
func (*FakeDockerClient) InspectContainer ¶
func (f *FakeDockerClient) InspectContainer(id string) (*dockertypes.ContainerJSON, 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) (*dockertypes.ContainerExecInspect, error)
func (*FakeDockerClient) InspectImageByID ¶ added in v1.5.0
func (f *FakeDockerClient) InspectImageByID(name string) (*dockertypes.ImageInspect, error)
InspectImageByID is a test-spy implementation of DockerInterface.InspectImageByID. It adds an entry "inspect" to the internal method call record.
func (*FakeDockerClient) InspectImageByRef ¶ added in v1.5.0
func (f *FakeDockerClient) InspectImageByRef(name string) (*dockertypes.ImageInspect, error)
InspectImageByRef is a test-spy implementation of DockerInterface.InspectImageByRef. It adds an entry "inspect" to the internal method call record.
func (*FakeDockerClient) ListContainers ¶
func (f *FakeDockerClient) ListContainers(options dockertypes.ContainerListOptions) ([]dockertypes.Container, 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 (f *FakeDockerClient) ListImages(opts dockertypes.ImageListOptions) ([]dockertypes.Image, error)
func (*FakeDockerClient) Logs ¶
func (f *FakeDockerClient) Logs(id string, opts dockertypes.ContainerLogsOptions, sopts StreamOptions) 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(image string, auth dockertypes.AuthConfig, opts dockertypes.ImagePullOptions) error
PullImage is a test-spy implementation of DockerInterface.PullImage. It adds an entry "pull" to the internal method call record.
func (*FakeDockerClient) RemoveContainer ¶ added in v0.4.3
func (f *FakeDockerClient) RemoveContainer(id string, opts dockertypes.ContainerRemoveOptions) error
func (*FakeDockerClient) RemoveImage ¶ added in v0.8.0
func (f *FakeDockerClient) RemoveImage(image string, opts dockertypes.ImageRemoveOptions) ([]dockertypes.ImageDelete, error)
func (*FakeDockerClient) ResetImages ¶ added in v1.6.0
func (f *FakeDockerClient) ResetImages()
func (*FakeDockerClient) ResizeContainerTTY ¶ added in v1.4.0
func (f *FakeDockerClient) ResizeContainerTTY(id string, height, width int) error
func (*FakeDockerClient) ResizeExecTTY ¶ added in v1.4.0
func (f *FakeDockerClient) ResizeExecTTY(id string, height, width int) error
func (*FakeDockerClient) SetFakeContainers ¶ added in v1.2.0
func (f *FakeDockerClient) SetFakeContainers(containers []*FakeContainer)
func (*FakeDockerClient) SetFakeRunningContainers ¶ added in v1.2.0
func (f *FakeDockerClient) SetFakeRunningContainers(containers []*FakeContainer)
func (*FakeDockerClient) StartContainer ¶
func (f *FakeDockerClient) StartContainer(id string) 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(startExec string, opts dockertypes.ExecStartCheck, sopts StreamOptions) error
func (*FakeDockerClient) StopContainer ¶
func (f *FakeDockerClient) StopContainer(id string, timeout int) 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() (*dockertypes.Version, error)
func (*FakeDockerClient) WithClock ¶ added in v1.6.0
func (f *FakeDockerClient) WithClock(c clock.Clock) *FakeDockerClient
func (*FakeDockerClient) WithTraceDisabled ¶ added in v1.6.0
func (f *FakeDockerClient) WithTraceDisabled() *FakeDockerClient
func (*FakeDockerClient) WithVersion ¶ added in v1.6.0
func (f *FakeDockerClient) WithVersion(version, apiVersion string) *FakeDockerClient
type FakeDockerPuller ¶
type FakeDockerPuller struct {
// contains filtered or unexported fields
}
FakeDockerPuller is meant to be a simple wrapper around FakeDockerClient. Please do not add more functionalities to it.
func (*FakeDockerPuller) GetImageRef ¶ added in v1.6.0
func (f *FakeDockerPuller) GetImageRef(image string) (string, error)
type ImageNotFoundError ¶ added in v1.6.0
type ImageNotFoundError struct {
ID string
}
ImageNotFoundError is the error returned by InspectImage when image not found. Expose this to inject error in dockershim for testing.
func (ImageNotFoundError) Error ¶ added in v1.6.0
func (e ImageNotFoundError) Error() string
type KubeletContainerName ¶ added in v0.14.0
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.