mgr

package
v0.0.0-...-058fe0e Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2018 License: Apache-2.0 Imports: 43 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultStopTimeout is the timeout (in seconds) for the syscall signal used to stop a container.
	DefaultStopTimeout = 10
)

Variables

This section is empty.

Functions

func Register

func Register(f SetupFunc)

Register is used to registe spec setup function.

Types

type AttachConfig

type AttachConfig struct {
	Hijack  http.Hijacker
	Stdin   bool
	Stdout  bool
	Stderr  bool
	Upgrade bool
}

AttachConfig wraps some infos of attaching.

type Container

type Container struct {
	sync.Mutex

	DetachKeys string
	// contains filtered or unexported fields
}

Container represents the container instance in runtime.

func (*Container) Config

func (c *Container) Config() *types.ContainerConfig

Config returns container's config.

func (*Container) ID

func (c *Container) ID() string

ID returns container's id.

func (*Container) Image

func (c *Container) Image() string

Image returns container's image name.

func (*Container) IsCreated

func (c *Container) IsCreated() bool

IsCreated returns container is created or not.

func (*Container) IsPaused

func (c *Container) IsPaused() bool

IsPaused returns container is paused or not.

func (*Container) IsRunning

func (c *Container) IsRunning() bool

IsRunning returns container is running or not.

func (*Container) IsStopped

func (c *Container) IsStopped() bool

IsStopped returns container is stopped or not.

func (*Container) Key

func (c *Container) Key() string

Key returns container's id.

func (*Container) Name

func (c *Container) Name() string

Name returns container's name.

func (*Container) StopTimeout

func (c *Container) StopTimeout() int64

StopTimeout returns the timeout (in seconds) used to stop the container.

func (*Container) Write

func (c *Container) Write(store *meta.Store) error

Write writes container's meta data into meta store.

type ContainerFilter

type ContainerFilter func(*ContainerMeta) bool

ContainerFilter defines a function to filter container in the store.

type ContainerListOption

type ContainerListOption struct {
	All bool
}

ContainerListOption wraps the container list interface params.

type ContainerManager

type ContainerManager struct {
	// Store stores containers in Backend store.
	// Element operated in store must has a type of *ContainerMeta.
	// By default, Store will use local filesystem with json format to store containers.
	Store *meta.Store

	// Client is used to interact with containerd.
	Client *ctrd.Client

	// NameToID stores relations between container's name and ID.
	// It is used to get container ID via container name.
	NameToID *collect.SafeMap

	ImageMgr      ImageMgr
	VolumeMgr     VolumeMgr
	NetworkMgr    NetworkMgr
	IOs           *containerio.Cache
	ExecProcesses *collect.SafeMap

	Config *config.Config
	// contains filtered or unexported fields
}

ContainerManager is the default implement of interface ContainerMgr.

func NewContainerManager

func NewContainerManager(ctx context.Context, store *meta.Store, cli *ctrd.Client, imgMgr ImageMgr, volMgr VolumeMgr, netMgr NetworkMgr, cfg *config.Config) (*ContainerManager, error)

NewContainerManager creates a brand new container manager.

func (*ContainerManager) Attach

func (mgr *ContainerManager) Attach(ctx context.Context, name string, attach *AttachConfig) error

Attach attachs a container's io.

func (*ContainerManager) Create

Create checks passed in parameters and create a Container object whose status is set at Created.

func (*ContainerManager) CreateExec

func (mgr *ContainerManager) CreateExec(ctx context.Context, name string, config *types.ExecCreateConfig) (string, error)

CreateExec creates exec process's meta data.

func (*ContainerManager) Get

func (mgr *ContainerManager) Get(ctx context.Context, name string) (*ContainerMeta, error)

Get the detailed information of container.

func (*ContainerManager) List

List returns the container's list.

func (*ContainerManager) Pause

func (mgr *ContainerManager) Pause(ctx context.Context, name string) error

Pause pauses a running container.

func (*ContainerManager) Remove

func (mgr *ContainerManager) Remove(ctx context.Context, name string, option *ContainerRemoveOption) error

Remove removes a container, it may be running or stopped and so on.

func (*ContainerManager) Rename

func (mgr *ContainerManager) Rename(ctx context.Context, oldName, newName string) error

Rename renames a container

func (*ContainerManager) Restore

func (mgr *ContainerManager) Restore(ctx context.Context) error

Restore containers from meta store to memory and recover those container.

func (*ContainerManager) Start

func (mgr *ContainerManager) Start(ctx context.Context, id, detachKeys string) (err error)

Start a pre created Container.

func (*ContainerManager) StartExec

func (mgr *ContainerManager) StartExec(ctx context.Context, execid string, config *types.ExecStartConfig, attach *AttachConfig) error

StartExec executes a new process in container.

func (*ContainerManager) Stop

func (mgr *ContainerManager) Stop(ctx context.Context, name string, timeout int64) error

Stop stops a running container.

func (*ContainerManager) Unpause

func (mgr *ContainerManager) Unpause(ctx context.Context, name string) error

Unpause unpauses a paused container.

type ContainerMeta

type ContainerMeta struct {

	// app armor profile
	AppArmorProfile string `json:"AppArmorProfile,omitempty"`

	// The arguments to the command being run
	Args []string `json:"Args"`

	// config
	Config *types.ContainerConfig `json:"Config,omitempty"`

	// The time the container was created
	Created string `json:"Created,omitempty"`

	// driver
	Driver string `json:"Driver,omitempty"`

	// exec ids
	ExecIds string `json:"ExecIDs,omitempty"`

	// graph driver
	GraphDriver *types.GraphDriverData `json:"GraphDriver,omitempty"`

	// host config
	HostConfig *types.HostConfig `json:"HostConfig,omitempty"`

	// hostname path
	HostnamePath string `json:"HostnamePath,omitempty"`

	// hosts path
	HostsPath string `json:"HostsPath,omitempty"`

	// The ID of the container
	ID string `json:"Id,omitempty"`

	// The container's image
	Image string `json:"Image,omitempty"`

	// log path
	LogPath string `json:"LogPath,omitempty"`

	// mount label
	MountLabel string `json:"MountLabel,omitempty"`

	// mounts
	Mounts []*types.MountPoint `json:"Mounts"`

	// name
	Name string `json:"Name,omitempty"`

	// network settings
	NetworkSettings *types.NetworkSettings `json:"NetworkSettings,omitempty"`

	Node interface{} `json:"Node,omitempty"`

	// The path to the command being run
	Path string `json:"Path,omitempty"`

	// process label
	ProcessLabel string `json:"ProcessLabel,omitempty"`

	// resolv conf path
	ResolvConfPath string `json:"ResolvConfPath,omitempty"`

	// restart count
	RestartCount int64 `json:"RestartCount,omitempty"`

	// The total size of all the files in this container.
	SizeRootFs int64 `json:"SizeRootFs,omitempty"`

	// The size of files that have been created or changed by this container.
	SizeRw int64 `json:"SizeRw,omitempty"`

	// state
	State *types.ContainerState `json:"State,omitempty"`
}

ContainerMeta represents the container's meta data.

func (*ContainerMeta) Key

func (meta *ContainerMeta) Key() string

Key returns container's id.

type ContainerMgr

type ContainerMgr interface {
	// Create a new container.
	Create(ctx context.Context, name string, config *types.ContainerCreateConfig) (*types.ContainerCreateResp, error)

	// Start a container.
	Start(ctx context.Context, id, detachKeys string) error

	// Stop a container.
	Stop(ctx context.Context, name string, timeout int64) error

	// Pause a container.
	Pause(ctx context.Context, name string) error

	// Unpause a container.
	Unpause(ctx context.Context, name string) error

	// Attach a container.
	Attach(ctx context.Context, name string, attach *AttachConfig) error

	// List returns the list of containers.
	List(ctx context.Context, filter ContainerFilter, option *ContainerListOption) ([]*ContainerMeta, error)

	// CreateExec creates exec process's environment.
	CreateExec(ctx context.Context, name string, config *types.ExecCreateConfig) (string, error)

	// StartExec executes a new process in container.
	StartExec(ctx context.Context, execid string, config *types.ExecStartConfig, attach *AttachConfig) error

	// Remove removes a container, it may be running or stopped and so on.
	Remove(ctx context.Context, name string, option *ContainerRemoveOption) error

	// Rename renames a container
	Rename(ctx context.Context, oldName string, newName string) error

	// Get the detailed information of container
	Get(ctx context.Context, name string) (*ContainerMeta, error)
}

ContainerMgr as an interface defines all operations against container.

type ContainerRemoveOption

type ContainerRemoveOption struct {
	Force  bool
	Volume bool
	Link   bool
}

ContainerRemoveOption wraps the container remove interface params.

type CriManager

type CriManager struct {
	ContainerMgr ContainerMgr
	ImageMgr     ImageMgr
}

CriManager is an implementation of interface CriMgr.

func NewCriManager

func NewCriManager(ctrMgr ContainerMgr, imgMgr ImageMgr) (*CriManager, error)

NewCriManager creates a brand new cri manager.

func (*CriManager) Attach

Attach prepares a streaming endpoint to attach to a running container, and returns the address.

func (*CriManager) ContainerStats

ContainerStats returns stats of the container. If the container does not exist, the call returns an error.

func (*CriManager) ContainerStatus

ContainerStatus inspects the container and returns the status.

func (*CriManager) CreateContainer

CreateContainer creates a new container in the given PodSandbox.

func (*CriManager) Exec

Exec prepares a streaming endpoint to execute a command in the container, and returns the address.

func (*CriManager) ExecSync

ExecSync executes a command in the container, and returns the stdout output. If command exits with a non-zero exit code, an error is returned.

func (*CriManager) ImageFsInfo

ImageFsInfo returns information of the filesystem that is used to store images.

func (*CriManager) ImageStatus

ImageStatus returns the status of the image, returns nil if the image isn't present.

func (*CriManager) ListContainerStats

ListContainerStats returns stats of all running containers.

func (*CriManager) ListContainers

ListContainers lists all containers matching the filter.

func (*CriManager) ListImages

ListImages lists existing images.

func (*CriManager) ListPodSandbox

ListPodSandbox returns a list of Sandbox.

func (*CriManager) PodSandboxStatus

PodSandboxStatus returns the status of the PodSandbox.

func (*CriManager) PortForward

PortForward prepares a streaming endpoint to forward ports from a PodSandbox, and returns the address.

func (*CriManager) PullImage

PullImage pulls an image with authentication config.

func (*CriManager) RemoveContainer

RemoveContainer removes the container.

func (*CriManager) RemoveImage

RemoveImage removes the image.

func (*CriManager) RemovePodSandbox

RemovePodSandbox removes the sandbox. If there are running containers in the sandbox, they should be forcibly removed.

func (*CriManager) RunPodSandbox

RunPodSandbox creates and starts a pod-level sandbox. Runtimes should ensure the sandbox is in ready state.

func (*CriManager) StartContainer

StartContainer starts the container.

func (*CriManager) Status

Status returns the status of the runtime.

func (*CriManager) StopContainer

StopContainer stops a running container with a grace period (i.e., timeout).

func (*CriManager) StopPodSandbox

StopPodSandbox stops the sandbox. If there are any running containers in the sandbox, they should be forcibly terminated.

func (*CriManager) UpdateContainerResources

UpdateContainerResources updates ContainerConfig of the container.

func (*CriManager) UpdateRuntimeConfig

UpdateRuntimeConfig updates the runtime config. Currently only handles podCIDR updates.

func (*CriManager) Version

Version returns the runtime name, runtime version and runtime API version.

type CriMgr

type CriMgr interface {
	// RuntimeServiceServer is interface of CRI runtime service.
	runtime.RuntimeServiceServer

	// ImageServiceServer is interface of CRI image service.
	runtime.ImageServiceServer
}

CriMgr as an interface defines all operations against CRI.

type ImageManager

type ImageManager struct {
	// DefaultRegistry is the default registry of daemon.
	// When users do not specify image repo in image name,
	// daemon will automatically pull images from DefaultRegistry.
	// TODO: make DefaultRegistry can be reloaded.
	DefaultRegistry string
	// contains filtered or unexported fields
}

ImageManager is an implementation of interface ImageMgr. It is a stateless manager, and it will never store image details. When image details needed from users, ImageManager interacts with containerd to get details.

func NewImageManager

func NewImageManager(cfg *config.Config, client *ctrd.Client) (*ImageManager, error)

NewImageManager initializes a brand new image manager.

func (*ImageManager) GetImage

func (mgr *ImageManager) GetImage(ctx context.Context, idOrRef string) (*types.ImageInfo, error)

GetImage gets image by image id or ref.

func (*ImageManager) ListImages

func (mgr *ImageManager) ListImages(ctx context.Context, filters string) ([]types.ImageInfo, error)

ListImages lists images stored by containerd.

func (*ImageManager) PullImage

func (mgr *ImageManager) PullImage(pctx context.Context, image, tag string, out io.Writer) error

PullImage pulls images from specified registry.

func (*ImageManager) RemoveImage

func (mgr *ImageManager) RemoveImage(ctx context.Context, image *types.ImageInfo, option *ImageRemoveOption) error

RemoveImage deletes an image by reference.

func (*ImageManager) SearchImages

func (mgr *ImageManager) SearchImages(ctx context.Context, name string, registry string) ([]types.SearchResultItem, error)

SearchImages searches imaged from specified registry.

type ImageMgr

type ImageMgr interface {
	// PullImage pulls images from specified registry.
	PullImage(ctx context.Context, image, tag string, out io.Writer) error

	// ListImages lists images stored by containerd.
	ListImages(ctx context.Context, filters string) ([]types.ImageInfo, error)

	// Search Images from specified registry.
	SearchImages(ctx context.Context, name string, registry string) ([]types.SearchResultItem, error)

	// GetImage gets image by image id or ref.
	GetImage(ctx context.Context, idOrRef string) (*types.ImageInfo, error)

	// RemoveImage deletes an image by reference.
	RemoveImage(ctx context.Context, image *types.ImageInfo, option *ImageRemoveOption) error
}

ImageMgr as an interface defines all operations against images.

type ImageRemoveOption

type ImageRemoveOption struct {
	Force bool
}

ImageRemoveOption wraps the image remove interface params.

type NetworkManager

type NetworkManager struct {
	// contains filtered or unexported fields
}

NetworkManager is the default implement of interface NetworkMgr.

func NewNetworkManager

func NewNetworkManager(cfg *config.Config, store *meta.Store) (*NetworkManager, error)

NewNetworkManager creates a brand new network manager.

func (*NetworkManager) Create

Create is used to create network.

func (*NetworkManager) EndpointCreate

func (nm *NetworkManager) EndpointCreate(ctx context.Context, name string) error

EndpointCreate is used to create network endpoint.

func (*NetworkManager) EndpointInfo

func (nm *NetworkManager) EndpointInfo(ctx context.Context, name string) (*types.Endpoint, error)

EndpointInfo returns the information of endpoint that specified name/id.

func (*NetworkManager) EndpointList

func (nm *NetworkManager) EndpointList(ctx context.Context) ([]*types.Endpoint, error)

EndpointList returns all endpoints.

func (*NetworkManager) EndpointRemove

func (nm *NetworkManager) EndpointRemove(ctx context.Context, name string) error

EndpointRemove is used to create network endpoint.

func (*NetworkManager) Get

func (nm *NetworkManager) Get(ctx context.Context, name string) (*types.Network, error)

Get returns the information of network that specified name/id.

func (*NetworkManager) List

func (nm *NetworkManager) List(ctx context.Context, labels map[string]string) ([]*types.Network, error)

List returns all networks on this host.

func (*NetworkManager) Remove

func (nm *NetworkManager) Remove(ctx context.Context, name string) error

Remove is used to delete an existing network.

type NetworkMgr

type NetworkMgr interface {
	// Create is used to create network.
	Create(ctx context.Context, create apitypes.NetworkCreateConfig) (*types.Network, error)

	// NetworkRemove is used to delete an existing network.
	Remove(ctx context.Context, name string) error

	// List returns all networks on this host.
	List(ctx context.Context, labels map[string]string) ([]*types.Network, error)

	// Get returns the information of network that specified name/id.
	Get(ctx context.Context, name string) (*types.Network, error)

	// EndpointCreate is used to create network endpoint.
	EndpointCreate(ctx context.Context, name string) error

	// EndpointRemove is used to create network endpoint.
	EndpointRemove(ctx context.Context, name string) error

	// EndpointList returns all endpoints.
	EndpointList(ctx context.Context) ([]*types.Endpoint, error)

	// EndpointInfo returns the information of endpoint that specified name/id.
	EndpointInfo(ctx context.Context, name string) (*types.Endpoint, error)
}

NetworkMgr defines interface to manage container network.

type SetupFunc

type SetupFunc func(ctx context.Context, m *ContainerMeta, s *specs.Spec) error

SetupFunc defines spec setup function type.

func SetupFuncs

func SetupFuncs() []SetupFunc

SetupFuncs returns all the spec setup functions.

type SystemManager

type SystemManager struct {
	// contains filtered or unexported fields
}

SystemManager is an instance of system management.

func NewSystemManager

func NewSystemManager(cfg *config.Config) (*SystemManager, error)

NewSystemManager creates a brand new system manager.

func (*SystemManager) Info

func (mgr *SystemManager) Info() (types.SystemInfo, error)

Info shows system information of daemon.

func (*SystemManager) Version

func (mgr *SystemManager) Version() (types.SystemVersion, error)

Version shows version of daemon.

type SystemMgr

type SystemMgr interface {
	Info() (types.SystemInfo, error)
	Version() (types.SystemVersion, error)
}

SystemMgr as an interface defines all operations against host.

type VolumeManager

type VolumeManager struct {
	// contains filtered or unexported fields
}

VolumeManager is the default implement of interface VolumeMgr.

func NewVolumeManager

func NewVolumeManager(ms *meta.Store, cfg volume.Config) (*VolumeManager, error)

NewVolumeManager creates a brand new volume manager.

func (*VolumeManager) Attach

func (vm *VolumeManager) Attach(ctx context.Context, name string, options map[string]string) (*types.Volume, error)

Attach is used to bind a volume to container.

func (*VolumeManager) Create

func (vm *VolumeManager) Create(ctx context.Context, name, driver string, options, labels map[string]string) error

Create is used to create volume.

func (*VolumeManager) Detach

func (vm *VolumeManager) Detach(ctx context.Context, name string, options map[string]string) (*types.Volume, error)

Detach is used to unbind a volume from container.

func (*VolumeManager) Get

func (vm *VolumeManager) Get(ctx context.Context, name string) (*types.Volume, error)

Get returns the information of volume that specified name/id.

func (*VolumeManager) List

func (vm *VolumeManager) List(ctx context.Context, labels map[string]string) ([]string, error)

List returns all volumes on this host.

func (*VolumeManager) Path

func (vm *VolumeManager) Path(ctx context.Context, name string) (string, error)

Path returns the mount path of volume.

func (*VolumeManager) Remove

func (vm *VolumeManager) Remove(ctx context.Context, name string) error

Remove is used to delete an existing volume.

type VolumeMgr

type VolumeMgr interface {
	// Create is used to create volume.
	Create(ctx context.Context, name, driver string, options, labels map[string]string) error

	// Remove is used to delete an existing volume.
	Remove(ctx context.Context, name string) error

	// List returns all volumes on this host.
	List(ctx context.Context, labels map[string]string) ([]string, error)

	// Get returns the information of volume that specified name/id.
	Get(ctx context.Context, name string) (*types.Volume, error)

	// Path returns the mount path of volume.
	Path(ctx context.Context, name string) (string, error)

	// Attach is used to bind a volume to container.
	Attach(ctx context.Context, name string, options map[string]string) (*types.Volume, error)

	// Detach is used to unbind a volume from container.
	Detach(ctx context.Context, name string, options map[string]string) (*types.Volume, error)
}

VolumeMgr defines interface to manage container volume.

Jump to

Keyboard shortcuts

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