containerd

package
v0.0.0-...-b19e04c Latest Latest
Warning

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

Go to latest
Published: May 21, 2024 License: Apache-2.0 Imports: 41 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrMockNotImplemented is returned when a mock does not implement a method.
	ErrMockNotImplemented = errors.New("mock does not implement this method")
	// ErrWrongNamespace is returned when the namespace is mismatched.
	ErrWrongNamespace = errors.New("missmatch namespace")
)

Functions

func DumpToJSON

func DumpToJSON(ctx context.Context, address string) ([]byte, error)

DumpToJSON dump to a json all information required to build a MockClient. It will dump from all namespace: containers and their task + PIDs.

Types

type ContainerOCISpec

type ContainerOCISpec struct {
	containers.Container
	Spec *oci.Spec `json:"Spec,omitempty"`
}

ContainerOCISpec contains Info() & unmarshaled oci Spec.

type Containerd

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

Containerd implement connector to containerd.

func FakeContainerd

func FakeContainerd(client *MockClient, isContainerIgnored func(facts.Container) bool) *Containerd

FakeContainerd return a Containerd 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,
) *Containerd

New returns a new Docker runtime.

func (*Containerd) CachedContainer

func (c *Containerd) CachedContainer(containerID string) (cont facts.Container, found bool)

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

func (*Containerd) ContainerLastKill

func (c *Containerd) ContainerLastKill(containerID string) time.Time

ContainerLastKill return the last time a container was killed or zero-time if unknown. containerd does not provide this information.

func (*Containerd) Containers

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

Containers return ContainerD containers.

func (*Containerd) DiagnosticArchive

func (c *Containerd) DiagnosticArchive(_ context.Context, archive types.ArchiveWriter) error

func (*Containerd) Events

func (c *Containerd) 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 (*Containerd) Exec

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

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

func (*Containerd) IsContainerNameRecentlyDeleted

func (c *Containerd) IsContainerNameRecentlyDeleted(name string) bool

func (*Containerd) IsRuntimeRunning

func (c *Containerd) IsRuntimeRunning(ctx context.Context) bool

IsRuntimeRunning returns whether or not Containerd 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 ContainerD is running but Glouton can't access it, IsRuntimeRunning will return false.

func (*Containerd) LastUpdate

func (c *Containerd) LastUpdate() time.Time

LastUpdate return the last time containers list was updated.

func (*Containerd) Metrics

func (c *Containerd) Metrics(ctx context.Context, now time.Time) ([]types.MetricPoint, error)

Metrics return metrics in a format similar to the one returned by Telegraf docker input. Note that Metrics will never open the connection to ContainerD and will return empty points if not connected.

func (*Containerd) MetricsMinute

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

func (*Containerd) ProcessWithCache

func (c *Containerd) ProcessWithCache() facts.ContainerRuntimeProcessQuerier

ProcessWithCache facts.containerRuntime.

func (*Containerd) Run

func (c *Containerd) Run(ctx context.Context) error

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

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

func (*Containerd) RuntimeFact

func (c *Containerd) RuntimeFact(ctx context.Context, currentFact map[string]string) map[string]string

RuntimeFact will return facts from the ContainerD runtime, like containerd_version.

type MockClient

type MockClient struct {
	Data           MockJSON
	EventChanMaker func() <-chan *events.Envelope
	// contains filtered or unexported fields
}

MockClient is a fake containerd client.

func NewMockFromFile

func NewMockFromFile(filename string) (*MockClient, error)

NewMockFromFile create a MockClient from JSON file. Use DumpToJSON to build such JSON.

func (*MockClient) Close

func (m *MockClient) Close() error

Close close.

func (*MockClient) Containers

func (m *MockClient) Containers(ctx context.Context) ([]containerd.Container, error)

Containers do Containers.

func (*MockClient) Events

func (m *MockClient) Events(context.Context) (<-chan *events.Envelope, <-chan error)

Events do events.

func (*MockClient) LoadContainer

func (m *MockClient) LoadContainer(ctx context.Context, id string) (containerd.Container, error)

LoadContainer do LoadContainer.

func (*MockClient) Metrics

func (m *MockClient) Metrics(_ context.Context, filters []string) (*tasks.MetricsResponse, error)

Metrics do metrics.

func (*MockClient) Namespaces

func (m *MockClient) Namespaces(context.Context) ([]string, error)

Namespaces do namespaces.

func (*MockClient) Version

Version do version.

type MockContainer

type MockContainer struct {
	MockInfo     ContainerOCISpec
	MockImageOCI ocispec.Descriptor
	MockTask     MockTask
	// contains filtered or unexported fields
}

MockContainer contains information about a container.

func (MockContainer) Checkpoint

Checkpoint implement containerd.Container.

func (MockContainer) Delete

Delete implement containerd.Container.

func (MockContainer) Extensions

func (c MockContainer) Extensions(context.Context) (map[string]typeurl.Any, error)

Extensions implement containerd.Container.

func (MockContainer) ID

func (c MockContainer) ID() string

ID implement containerd.Container.

func (MockContainer) Image

Image implement containerd.Container.

func (MockContainer) Info

Info implement containerd.Container.

func (MockContainer) Labels

func (c MockContainer) Labels(ctx context.Context) (map[string]string, error)

Labels implement containerd.Container.

func (MockContainer) NewTask

NewTask implement containerd.Container.

func (MockContainer) SetLabels

func (c MockContainer) SetLabels(context.Context, map[string]string) (map[string]string, error)

SetLabels implement containerd.Container.

func (MockContainer) Spec

func (c MockContainer) Spec(ctx context.Context) (*oci.Spec, error)

Spec implement containerd.Container.

func (MockContainer) Task

Task implement containerd.Container.

func (MockContainer) Update

Update implement containerd.Container.

type MockImage

type MockImage struct {
	MockName   string
	MockTarget ocispec.Descriptor
}

MockImage is an implementation of containerd.Image.

func (MockImage) Config

Config implement containerd.Image.

func (MockImage) ContentStore

func (i MockImage) ContentStore() content.Store

ContentStore implement containerd.Image.

func (MockImage) IsUnpacked

func (i MockImage) IsUnpacked(context.Context, string) (bool, error)

IsUnpacked implement containerd.Image.

func (MockImage) Labels

func (i MockImage) Labels() map[string]string

Labels implement containerd.Image.

func (MockImage) Metadata

func (i MockImage) Metadata() images.Image

Metadata implement containerd.Image.

func (MockImage) Name

func (i MockImage) Name() string

Name implement containerd.Image.

func (MockImage) Platform

func (i MockImage) Platform() platforms.MatchComparer

Platform implement containerd.Image.

func (MockImage) RootFS

func (i MockImage) RootFS(_ context.Context) ([]digest.Digest, error)

RootFS implement containerd.Image.

func (MockImage) Size

func (i MockImage) Size(_ context.Context) (int64, error)

Size implement containerd.Image.

func (MockImage) Spec

func (i MockImage) Spec(_ context.Context) (ocispec.Image, error)

Spec implement containerd.Image.

func (MockImage) Target

func (i MockImage) Target() ocispec.Descriptor

Target implement containerd.Image.

func (MockImage) Unpack

Unpack implement containerd.Image.

func (MockImage) Usage

Usage implement containerd.Image.

type MockJSON

type MockJSON struct {
	Namespaces []MockNamespace
	Version    containerd.Version
}

MockJSON store all information that MockClient can provide.

type MockNamespace

type MockNamespace struct {
	MockNamespace  string
	MockContainers []MockContainer
}

MockNamespace contains namespaced information.

type MockTask

type MockTask struct {
	MockID     string
	MockPID    uint32
	MockStatus containerd.Status
	MockPids   []containerd.ProcessInfo
	// contains filtered or unexported fields
}

MockTask is an implementation of containerd.Task.

func (MockTask) Checkpoint

Checkpoint implements containerd.Task.

func (MockTask) CloseIO

CloseIO implements containerd.Task.

func (MockTask) Delete

Delete implements containerd.Task.

func (MockTask) Exec

func (t MockTask) Exec(context.Context, string, *specs.Process, cio.Creator) (containerd.Process, error)

Exec implements containerd.Task.

func (MockTask) ID

func (t MockTask) ID() string

ID implements containerd.Task.

func (MockTask) IO

func (t MockTask) IO() cio.IO

IO implements containerd.Task.

func (MockTask) Kill

Kill implements containerd.Task.

func (MockTask) LoadProcess

LoadProcess implements containerd.Task.

func (MockTask) Metrics

Metrics implements containerd.Task.

func (MockTask) Pause

func (t MockTask) Pause(context.Context) error

Pause implements containerd.Task.

func (MockTask) Pid

func (t MockTask) Pid() uint32

Pid implements containerd.Task.

func (MockTask) Pids

Pids implements containerd.Task.

func (MockTask) Resize

func (t MockTask) Resize(_ context.Context, _, _ uint32) error

Resize implements containerd.Task.

func (MockTask) Resume

func (t MockTask) Resume(context.Context) error

Resume implements containerd.Task.

func (MockTask) Spec

func (t MockTask) Spec(context.Context) (*oci.Spec, error)

Spec implements containerd.Task.

func (MockTask) Start

func (t MockTask) Start(context.Context) error

Start implements containerd.Task.

func (MockTask) Status

func (t MockTask) Status(ctx context.Context) (containerd.Status, error)

Status implements containerd.Task.

func (MockTask) Update

Update implements containerd.Task.

func (MockTask) Wait

func (t MockTask) Wait(context.Context) (<-chan containerd.ExitStatus, error)

Wait implements containerd.Task.

Jump to

Keyboard shortcuts

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