docker

package
v0.0.0-...-45d6c7c Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2024 License: Apache-2.0 Imports: 32 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrDockerUnexcepted = errors.New("unexcepted data")
)

errors of Docker runtime.

Functions

This section is empty.

Types

type Docker

type Docker struct {
	DockerSockets             []string
	DeletedContainersCallback func(containersID []string)
	IsContainerIgnored        func(facts.Container) bool
	// contains filtered or unexported fields
}

Docker implement a method to query Docker runtime. It try to connect to the first valid DockerSockets. Empty string is a special value: it means use default.

func FakeDocker

func FakeDocker(client *MockDockerClient, isContainerIgnored func(facts.Container) bool) *Docker

FakeDocker return a Docker runtime connector that use a mock client.

func New

func New(
	runtime config.ContainerRuntimeAddresses,
	hostRoot string,
	deletedContainersCallback func(containersID []string),
	isContainerIgnored func(facts.Container) bool,
) *Docker

New returns a new Docker runtime.

func (*Docker) CachedContainer

func (d *Docker) CachedContainer(containerID string) (c facts.Container, found bool)

CachedContainer return a container without querying Docker, it use in-memory cache which must have been filled by a call to Continers().

func (*Docker) ContainerExists

func (d *Docker) ContainerExists(id string) bool

func (*Docker) ContainerLastKill

func (d *Docker) ContainerLastKill(containerID string) time.Time

ContainerLastKill return the last time a container was killed or zero-time if unknown.

func (*Docker) Containers

func (d *Docker) Containers(ctx context.Context, maxAge time.Duration, includeIgnored bool) (containers []facts.Container, err error)

Containers return Docker containers.

func (*Docker) DiagnosticArchive

func (d *Docker) DiagnosticArchive(_ context.Context, archive types.ArchiveWriter) error

func (*Docker) Events

func (d *Docker) Events() <-chan facts.ContainerEvent

Events return the channel used to send events. There is only one shared channel (so multiple consumer should be implemented by caller).

func (*Docker) Exec

func (d *Docker) Exec(ctx context.Context, containerID string, cmd []string) ([]byte, error)

Exec run a command in a container and return stdout+stderr.

func (*Docker) IsContainerNameRecentlyDeleted

func (d *Docker) IsContainerNameRecentlyDeleted(name string) bool

func (*Docker) IsRuntimeRunning

func (d *Docker) IsRuntimeRunning(ctx context.Context) bool

IsRuntimeRunning returns whether or not Docker is available

IsRuntimeRunning will try to open a new connection if it never tried. It will also check that connection is still working (do a ping). Note: if Docker is running but Glouton can't access it, IsRuntimeRunning will return false.

func (*Docker) LastUpdate

func (d *Docker) LastUpdate() time.Time

LastUpdate return the last time containers list was updated.

func (*Docker) Metrics

func (d *Docker) Metrics(_ context.Context, now time.Time) ([]types.MetricPoint, error)

func (*Docker) MetricsMinute

func (d *Docker) MetricsMinute(_ context.Context, now time.Time) ([]types.MetricPoint, error)

func (*Docker) ProcessWithCache

func (d *Docker) ProcessWithCache() facts.ContainerRuntimeProcessQuerier

ProcessWithCache facts.containerRuntime.

func (*Docker) Run

func (d *Docker) Run(ctx context.Context) error

Run will run connect and listen to Docker event until context is cancelled

Any error (unable to connect due to permission issue or Docker down) are not returned by Run but could be retrieved with LastError.

func (*Docker) RuntimeFact

func (d *Docker) RuntimeFact(ctx context.Context, currentFact map[string]string) map[string]string

RuntimeFact will return facts from the Docker runtime, like docker_version.

func (*Docker) ServerAddress

func (d *Docker) ServerAddress() string

ServerAddress will return the last server address for which connection succeeded. Note that empty string could be "docker default" or no valid connection. You should use this after call to IsRuntimeRunning().

type MockDockerClient

type MockDockerClient struct {
	EventChanMaker func() <-chan events.Message
	Containers     []dockerTypes.ContainerJSON
	Version        dockerTypes.Version
	Top            map[string]containerTypes.ContainerTopOKBody
	TopWaux        map[string]containerTypes.ContainerTopOKBody
	ReturnError    error

	TopCallCount int
}

MockDockerClient is a fake Docker client that could be used during test.

func NewDockerMock

func NewDockerMock(dirname string) (*MockDockerClient, error)

NewDockerMock create new MockDockerClient from a directory which may contains docker-version & docker-containers.json.

func NewDockerMockFromFile

func NewDockerMockFromFile(filename string) (*MockDockerClient, error)

NewDockerMockFromFile create a MockDockerClient from JSON file which contains containers.

func (*MockDockerClient) Close

func (cl *MockDockerClient) Close() error

Close the docker client.

func (*MockDockerClient) ContainerExecAttach

ContainerExecAttach is not implemented.

func (*MockDockerClient) ContainerExecCreate

ContainerExecCreate is not implemented.

func (*MockDockerClient) ContainerInspect

func (cl *MockDockerClient) ContainerInspect(_ context.Context, container string) (dockerTypes.ContainerJSON, error)

ContainerInspect return inspect for in-memory list of containers.

func (*MockDockerClient) ContainerList

ContainerList list containers from in-memory list.

func (*MockDockerClient) ContainerTop

func (cl *MockDockerClient) ContainerTop(_ context.Context, container string, arguments []string) (containerTypes.ContainerTopOKBody, error)

ContainerTop return hard-coded value for top.

func (*MockDockerClient) Events

func (cl *MockDockerClient) Events(context.Context, events.ListOptions) (<-chan events.Message, <-chan error)

Events do events.

func (*MockDockerClient) NetworkInspect

NetworkInspect is not implemented.

func (*MockDockerClient) NetworkList

NetworkList is not implemented.

func (*MockDockerClient) Ping

Ping do nothing.

func (*MockDockerClient) ServerVersion

func (cl *MockDockerClient) ServerVersion(context.Context) (dockerTypes.Version, error)

ServerVersion do server version.

Jump to

Keyboard shortcuts

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