container

package
v0.0.0-...-b3c77dc Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2018 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Container

type Container struct {
	// Metadata is the metadata of the container, it is **immutable** after created.
	Metadata
	// Status stores the status of the container.
	Status StatusStorage
	// Container is the containerd container client.
	Container containerd.Container
	// Container IO
	IO *cio.ContainerIO
	// StopCh is used to propagate the stop information of the container.
	*store.StopCh
}

Container contains all resources associated with the container. All methods to mutate the internal state are thread-safe.

func NewContainer

func NewContainer(metadata Metadata, opts ...Opts) (Container, error)

NewContainer creates an internally used container type.

func (*Container) Delete

func (c *Container) Delete() error

Delete deletes checkpoint for the container.

type Metadata

type Metadata struct {
	// ID is the container id.
	ID string
	// Name is the container name.
	Name string
	// SandboxID is the sandbox id the container belongs to.
	SandboxID string
	// Config is the CRI container config.
	// NOTE(random-liu): Resource limits are updatable, the source
	// of truth for resource limits are in containerd.
	Config *runtime.ContainerConfig
	// ImageRef is the reference of image used by the container.
	ImageRef string
	// LogPath is the container log path.
	LogPath string
}

Metadata is the unversioned container metadata.

func (*Metadata) MarshalJSON

func (c *Metadata) MarshalJSON() ([]byte, error)

MarshalJSON encodes Metadata into bytes in json format.

func (*Metadata) UnmarshalJSON

func (c *Metadata) UnmarshalJSON(data []byte) error

UnmarshalJSON decodes Metadata from bytes.

type Opts

type Opts func(*Container) error

Opts sets specific information to newly created Container.

func WithContainer

func WithContainer(cntr containerd.Container) Opts

WithContainer adds the containerd Container to the internal data store.

func WithContainerIO

func WithContainerIO(io *cio.ContainerIO) Opts

WithContainerIO adds IO into the container.

func WithFakeStatus

func WithFakeStatus(status Status) Opts

WithFakeStatus adds fake status to the container.

func WithStatus

func WithStatus(status Status, root string) Opts

WithStatus adds status to the container.

type Status

type Status struct {
	// Pid is the init process id of the container.
	Pid uint32
	// CreatedAt is the created timestamp.
	CreatedAt int64
	// StartedAt is the started timestamp.
	StartedAt int64
	// FinishedAt is the finished timestamp.
	FinishedAt int64
	// ExitCode is the container exit code.
	ExitCode int32
	// CamelCase string explaining why container is in its current state.
	Reason string
	// Human-readable message indicating details about why container is in its
	// current state.
	Message string
	// Removing indicates that the container is in removing state.
	// This field doesn't need to be checkpointed.
	Removing bool `json:"-"`
}

Status is the status of a container.

func LoadStatus

func LoadStatus(root, id string) (Status, error)

LoadStatus loads container status from checkpoint. There shouldn't be threads writing to the file during loading.

func (Status) State

func (s Status) State() runtime.ContainerState

State returns current state of the container based on the container status.

type StatusStorage

type StatusStorage interface {
	// Get a container status.
	Get() Status
	// UpdateSync updates the container status and the on disk checkpoint.
	// Note that the update MUST be applied in one transaction.
	UpdateSync(UpdateFunc) error
	// Update the container status. Note that the update MUST be applied
	// in one transaction.
	Update(UpdateFunc) error
	// Delete the container status.
	// Note:
	// * Delete should be idempotent.
	// * The status must be deleted in one trasaction.
	Delete() error
}

StatusStorage manages the container status with a storage backend.

func StoreStatus

func StoreStatus(root, id string, status Status) (StatusStorage, error)

StoreStatus creates the storage containing the passed in container status with the specified id. The status MUST be created in one transaction.

type Store

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

Store stores all Containers.

func NewStore

func NewStore() *Store

NewStore creates a container store.

func (*Store) Add

func (s *Store) Add(c Container) error

Add a container into the store. Returns store.ErrAlreadyExist if the container already exists.

func (*Store) Delete

func (s *Store) Delete(id string)

Delete deletes the container from store with specified id.

func (*Store) Get

func (s *Store) Get(id string) (Container, error)

Get returns the container with specified id. Returns store.ErrNotExist if the container doesn't exist.

func (*Store) List

func (s *Store) List() []Container

List lists all containers.

type UpdateFunc

type UpdateFunc func(Status) (Status, error)

UpdateFunc is function used to update the container status. If there is an error, the update will be rolled back.

Jump to

Keyboard shortcuts

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