Documentation
¶
Index ¶
- Constants
- func CheckContainerStatus(client DockerClientInterface, containerID string) (*dockertypes.ContainerJSON, error)
- func GenerateEnvList(envs []*v1.KeyValue) (result []string)
- func GenerateMountBindings(mounts []*v1.Mount, terminationMessagePath string) []string
- func GetFakeContainerID(name string) string
- func IsContainerNotFoundError(err error) bool
- func IsImageNotFoundError(err error) bool
- func MakePortsAndBindings(pm []*v1.PortMapping) (nat.PortSet, map[nat.Port][]nat.PortBinding)
- func ParseDockerTimestamp(s string) (time.Time, error)
- type CalledDetail
- type DockerClientInterface
- type FakeContainer
- type FakeDockerClient
- func (f *FakeDockerClient) AssertCallDetails(calls ...CalledDetail) (err error)
- func (f *FakeDockerClient) AssertCalls(calls []string) (err 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) (*dockercontainer.CreateResponse, error)
- func (f *FakeDockerClient) CreateExec(id string, opts dockertypes.ExecConfig) (*dockertypes.IDResponse, error)
- func (f *FakeDockerClient) GetContainerStats(id string) (*dockertypes.StatsJSON, error)
- func (f *FakeDockerClient) ImageHistory(id string) ([]dockerimagetypes.HistoryResponseItem, error)
- func (f *FakeDockerClient) Info() (*dockertypes.Info, error)
- func (f *FakeDockerClient) InjectContainerStats(data map[string]*dockertypes.StatsJSON)
- func (f *FakeDockerClient) InjectError(fn string, err error)
- func (f *FakeDockerClient) InjectErrors(errs map[string]error)
- func (f *FakeDockerClient) InjectImageHistory(data map[string][]dockerimagetypes.HistoryResponseItem)
- func (f *FakeDockerClient) InjectImageInspects(inspects []dockertypes.ImageInspect)
- func (f *FakeDockerClient) InjectImages(images []dockertypes.ImageSummary)
- func (f *FakeDockerClient) InspectContainer(id string) (*dockertypes.ContainerJSON, error)
- func (f *FakeDockerClient) InspectContainerWithSize(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.ImageSummary, error)
- func (f *FakeDockerClient) Logs(id string, opts dockertypes.ContainerLogsOptions, sopts StreamOptions) error
- func (f *FakeDockerClient) MakeImagesPrivate(images []dockertypes.ImageSummary, auth dockertypes.AuthConfig)
- 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.ImageDeleteResponseItem, error)
- func (f *FakeDockerClient) ResetImages()
- func (f *FakeDockerClient) ResizeContainerTTY(id string, height, width uint) error
- func (f *FakeDockerClient) ResizeExecTTY(id string, height, width uint) error
- func (f *FakeDockerClient) SetFakeContainers(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 time.Duration) error
- func (f *FakeDockerClient) UpdateContainerResources(id string, updateConfig dockercontainer.UpdateConfig) error
- func (f *FakeDockerClient) Version() (*dockertypes.Version, error)
- func (f *FakeDockerClient) WithClock(c clock.Clock) *FakeDockerClient
- func (f *FakeDockerClient) WithRandSource(source rand.Source) *FakeDockerClient
- func (f *FakeDockerClient) WithTraceDisabled() *FakeDockerClient
- func (f *FakeDockerClient) WithVersion(version, apiVersion string) *FakeDockerClient
- type FakeDockerPuller
- type ImageNotFoundError
- type StreamOptions
Constants ¶
const ( // https://docs.docker.com/engine/reference/api/docker_remote_api/ // docker version should be at least 1.13.1 MinimumDockerAPIVersion = "1.26.0" // Status of a container returned by ListContainers. StatusRunningPrefix = "Up" StatusCreatedPrefix = "Created" StatusExitedPrefix = "Exited" // Fake docker endpoint FakeDockerEndpoint = "fake://" )
Variables ¶
This section is empty.
Functions ¶
func CheckContainerStatus ¶
func CheckContainerStatus( client DockerClientInterface, containerID string, ) (*dockertypes.ContainerJSON, error)
func GenerateEnvList ¶
generateEnvList converts KeyValue list to a list of strings, in the form of '<key>=<value>', which can be understood by docker.
func GenerateMountBindings ¶
generateMountBindings converts the mount list to a list of strings that can be understood by docker. '<HostPath>:<ContainerPath>[:options]', where 'options' is a comma-separated list of the following strings: 'ro', if the path is read only 'Z', if the volume requires SELinux relabeling propagation mode such as 'rslave'
func GetFakeContainerID ¶
GetFakeContainerID generates a fake container id from container name with a hash.
func IsContainerNotFoundError ¶
IsContainerNotFoundError checks whether the error is container not found error.
func IsImageNotFoundError ¶
IsImageNotFoundError checks whether the error is image not found error. This is exposed to share with cri-dockerd.
func MakePortsAndBindings ¶
func MakePortsAndBindings( pm []*v1.PortMapping, ) (nat.PortSet, map[nat.Port][]nat.PortBinding)
Types ¶
type CalledDetail ¶
type CalledDetail struct {
// contains filtered or unexported fields
}
func NewCalledDetail ¶
func NewCalledDetail(name string, arguments []interface{}) CalledDetail
NewCalledDetail create a new call detail item.
type DockerClientInterface ¶
type DockerClientInterface interface {
ListContainers(options dockertypes.ContainerListOptions) ([]dockertypes.Container, error)
InspectContainer(id string) (*dockertypes.ContainerJSON, error)
InspectContainerWithSize(id string) (*dockertypes.ContainerJSON, error)
CreateContainer(
dockertypes.ContainerCreateConfig,
) (*dockercontainer.CreateResponse, error)
StartContainer(id string) error
StopContainer(id string, timeout time.Duration) error
UpdateContainerResources(id string, updateConfig dockercontainer.UpdateConfig) 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.ImageSummary, error)
PullImage(image string, auth dockertypes.AuthConfig, opts dockertypes.ImagePullOptions) error
RemoveImage(
image string,
opts dockertypes.ImageRemoveOptions,
) ([]dockertypes.ImageDeleteResponseItem, error)
ImageHistory(id string) ([]dockerimagetypes.HistoryResponseItem, error)
Logs(string, dockertypes.ContainerLogsOptions, StreamOptions) error
Version() (*dockertypes.Version, error)
Info() (*dockertypes.Info, error)
CreateExec(string, dockertypes.ExecConfig) (*dockertypes.IDResponse, error)
StartExec(string, dockertypes.ExecStartCheck, StreamOptions) error
InspectExec(id string) (*dockertypes.ContainerExecInspect, error)
AttachToContainer(string, dockertypes.ContainerAttachOptions, StreamOptions) error
ResizeContainerTTY(id string, height, width uint) error
ResizeExecTTY(id string, height, width uint) error
GetContainerStats(id string) (*dockertypes.StatsJSON, error)
}
DockerClientInterface is an abstract interface for testability. It abstracts the interface of docker client.
func ConnectToDockerOrDie ¶
func ConnectToDockerOrDie( dockerEndpoint string, requestTimeout, imagePullProgressDeadline time.Duration, ) DockerClientInterface
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 NewInstrumentedInterface ¶
func NewInstrumentedInterface(dockerClient DockerClientInterface) DockerClientInterface
NewInstrumentedInterface creates an instrumented DockerClientInterface from an existing DockerClientInterface.
type FakeContainer ¶
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.ImageSummary
ImageIDsNeedingAuth map[string]dockertypes.AuthConfig
Errors map[string]error
EnableTrace bool
RandGenerator *rand.Rand
// 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][]dockerimagetypes.HistoryResponseItem
ContainerStatsMap map[string]*dockertypes.StatsJSON
// 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 ¶
func NewFakeDockerClient() *FakeDockerClient
func (*FakeDockerClient) AssertCallDetails ¶
func (f *FakeDockerClient) AssertCallDetails(calls ...CalledDetail) (err error)
func (*FakeDockerClient) AssertCalls ¶
func (f *FakeDockerClient) AssertCalls(calls []string) (err error)
func (*FakeDockerClient) AttachToContainer ¶
func (f *FakeDockerClient) AttachToContainer( id string, opts dockertypes.ContainerAttachOptions, sopts StreamOptions, ) error
func (*FakeDockerClient) ClearCalls ¶
func (f *FakeDockerClient) ClearCalls()
func (*FakeDockerClient) ClearErrors ¶
func (f *FakeDockerClient) ClearErrors()
func (*FakeDockerClient) CreateContainer ¶
func (f *FakeDockerClient) CreateContainer( c dockertypes.ContainerCreateConfig, ) (*dockercontainer.CreateResponse, error)
CreateContainer is a test-spy implementation of DockerClientInterface.CreateContainer. It adds an entry "create" to the internal method call record.
func (*FakeDockerClient) CreateExec ¶
func (f *FakeDockerClient) CreateExec( id string, opts dockertypes.ExecConfig, ) (*dockertypes.IDResponse, error)
func (*FakeDockerClient) GetContainerStats ¶
func (f *FakeDockerClient) GetContainerStats(id string) (*dockertypes.StatsJSON, error)
func (*FakeDockerClient) ImageHistory ¶
func (f *FakeDockerClient) ImageHistory(id string) ([]dockerimagetypes.HistoryResponseItem, error)
func (*FakeDockerClient) Info ¶
func (f *FakeDockerClient) Info() (*dockertypes.Info, error)
func (*FakeDockerClient) InjectContainerStats ¶
func (f *FakeDockerClient) InjectContainerStats(data map[string]*dockertypes.StatsJSON)
func (*FakeDockerClient) InjectError ¶
func (f *FakeDockerClient) InjectError(fn string, err error)
func (*FakeDockerClient) InjectErrors ¶
func (f *FakeDockerClient) InjectErrors(errs map[string]error)
func (*FakeDockerClient) InjectImageHistory ¶
func (f *FakeDockerClient) InjectImageHistory( data map[string][]dockerimagetypes.HistoryResponseItem, )
func (*FakeDockerClient) InjectImageInspects ¶
func (f *FakeDockerClient) InjectImageInspects(inspects []dockertypes.ImageInspect)
func (*FakeDockerClient) InjectImages ¶
func (f *FakeDockerClient) InjectImages(images []dockertypes.ImageSummary)
func (*FakeDockerClient) InspectContainer ¶
func (f *FakeDockerClient) InspectContainer(id string) (*dockertypes.ContainerJSON, error)
InspectContainer is a test-spy implementation of DockerClientInterface.InspectContainer. It adds an entry "inspect" to the internal method call record.
func (*FakeDockerClient) InspectContainerWithSize ¶
func (f *FakeDockerClient) InspectContainerWithSize(id string) (*dockertypes.ContainerJSON, error)
InspectContainerWithSize is a test-spy implementation of DockerClientInterface.InspectContainerWithSize. It adds an entry "inspect" to the internal method call record.
func (*FakeDockerClient) InspectExec ¶
func (f *FakeDockerClient) InspectExec(id string) (*dockertypes.ContainerExecInspect, error)
func (*FakeDockerClient) InspectImageByID ¶
func (f *FakeDockerClient) InspectImageByID(name string) (*dockertypes.ImageInspect, error)
InspectImageByID is a test-spy implementation of DockerClientInterface.InspectImageByID. It adds an entry "inspect" to the internal method call record.
func (*FakeDockerClient) InspectImageByRef ¶
func (f *FakeDockerClient) InspectImageByRef(name string) (*dockertypes.ImageInspect, error)
InspectImageByRef is a test-spy implementation of DockerClientInterface.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 DockerClientInterface.ListContainers. It adds an entry "list" to the internal method call record.
func (*FakeDockerClient) ListImages ¶
func (f *FakeDockerClient) ListImages( opts dockertypes.ImageListOptions, ) ([]dockertypes.ImageSummary, error)
func (*FakeDockerClient) Logs ¶
func (f *FakeDockerClient) Logs( id string, opts dockertypes.ContainerLogsOptions, sopts StreamOptions, ) error
Logs is a test-spy implementation of DockerClientInterface.Logs. It adds an entry "logs" to the internal method call record.
func (*FakeDockerClient) MakeImagesPrivate ¶
func (f *FakeDockerClient) MakeImagesPrivate( images []dockertypes.ImageSummary, auth dockertypes.AuthConfig, )
func (*FakeDockerClient) PullImage ¶
func (f *FakeDockerClient) PullImage( image string, auth dockertypes.AuthConfig, opts dockertypes.ImagePullOptions, ) error
PullImage is a test-spy implementation of DockerClientInterface.PullImage. It adds an entry "pull" to the internal method call record.
func (*FakeDockerClient) RemoveContainer ¶
func (f *FakeDockerClient) RemoveContainer( id string, opts dockertypes.ContainerRemoveOptions, ) error
func (*FakeDockerClient) RemoveImage ¶
func (f *FakeDockerClient) RemoveImage( image string, opts dockertypes.ImageRemoveOptions, ) ([]dockertypes.ImageDeleteResponseItem, error)
func (*FakeDockerClient) ResetImages ¶
func (f *FakeDockerClient) ResetImages()
func (*FakeDockerClient) ResizeContainerTTY ¶
func (f *FakeDockerClient) ResizeContainerTTY(id string, height, width uint) error
func (*FakeDockerClient) ResizeExecTTY ¶
func (f *FakeDockerClient) ResizeExecTTY(id string, height, width uint) error
func (*FakeDockerClient) SetFakeContainers ¶
func (f *FakeDockerClient) SetFakeContainers(containers []*FakeContainer)
func (*FakeDockerClient) StartContainer ¶
func (f *FakeDockerClient) StartContainer(id string) error
StartContainer is a test-spy implementation of DockerClientInterface.StartContainer. It adds an entry "start" to the internal method call record.
func (*FakeDockerClient) StartExec ¶
func (f *FakeDockerClient) StartExec( startExec string, opts dockertypes.ExecStartCheck, sopts StreamOptions, ) error
func (*FakeDockerClient) StopContainer ¶
func (f *FakeDockerClient) StopContainer(id string, timeout time.Duration) error
StopContainer is a test-spy implementation of DockerClientInterface.StopContainer. It adds an entry "stop" to the internal method call record.
func (*FakeDockerClient) UpdateContainerResources ¶
func (f *FakeDockerClient) UpdateContainerResources( id string, updateConfig dockercontainer.UpdateConfig, ) error
func (*FakeDockerClient) Version ¶
func (f *FakeDockerClient) Version() (*dockertypes.Version, error)
func (*FakeDockerClient) WithClock ¶
func (f *FakeDockerClient) WithClock(c clock.Clock) *FakeDockerClient
func (*FakeDockerClient) WithRandSource ¶
func (f *FakeDockerClient) WithRandSource(source rand.Source) *FakeDockerClient
func (*FakeDockerClient) WithTraceDisabled ¶
func (f *FakeDockerClient) WithTraceDisabled() *FakeDockerClient
func (*FakeDockerClient) WithVersion ¶
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 ¶
func (f *FakeDockerPuller) GetImageRef(image string) (string, error)
type ImageNotFoundError ¶
type ImageNotFoundError struct {
ID string
}
ImageNotFoundError is the error returned by InspectImage when image not found. Expose this to inject error in cri-dockerd for testing.
func (ImageNotFoundError) Error ¶
func (e ImageNotFoundError) Error() string