sandbox

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: May 22, 2018 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrClosedNetNS = errors.New("network namespace is closed")

ErrClosedNetNS is the error returned when network namespace is closed.

Functions

This section is empty.

Types

type Metadata

type Metadata struct {
	// ID is the sandbox id.
	ID string
	// Name is the sandbox name.
	Name string
	// Config is the CRI sandbox config.
	Config *runtime.PodSandboxConfig
	// NetNSPath is the network namespace used by the sandbox.
	NetNSPath string
	// IP of Pod if it is attached to non host network
	IP string
}

Metadata is the unversioned sandbox 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 NetNS

type NetNS struct {
	sync.Mutex
	// contains filtered or unexported fields
}

NetNS holds network namespace for sandbox

func LoadNetNS

func LoadNetNS(path string) (*NetNS, error)

LoadNetNS loads existing network namespace. It returns ErrClosedNetNS if the network namespace has already been closed.

func NewNetNS

func NewNetNS() (*NetNS, error)

NewNetNS creates a network namespace for the sandbox

func (*NetNS) Closed

func (n *NetNS) Closed() bool

Closed checks whether the network namespace has been closed.

func (*NetNS) GetNs

func (n *NetNS) GetNs() cnins.NetNS

GetNs returns the network namespace handle

func (*NetNS) GetPath

func (n *NetNS) GetPath() string

GetPath returns network namespace path for sandbox container

func (*NetNS) Remove

func (n *NetNS) Remove() error

Remove removes network namepace if it exists and not closed. Remove is idempotent, meaning it might be invoked multiple times and provides consistent result.

type Sandbox

type Sandbox struct {
	// Metadata is the metadata of the sandbox, it is immutable after created.
	Metadata
	// Status stores the status of the sandbox.
	Status StatusStorage
	// Container is the containerd sandbox container client
	Container containerd.Container
	// CNI network namespace client
	NetNS *NetNS
	// StopCh is used to propagate the stop information of the sandbox.
	*store.StopCh
}

Sandbox contains all resources associated with the sandbox. All methods to mutate the internal state are thread safe.

func NewSandbox

func NewSandbox(metadata Metadata, status Status) Sandbox

NewSandbox creates an internally used sandbox type. This functions reminds the caller that a sandbox must have a status.

type State

type State uint32

State is the sandbox state we use in containerd/cri. It has unknown state defined.

const (
	// StateUnknown is unknown state of sandbox. Sandbox
	// is in unknown state before its corresponding sandbox container
	// is created. Sandbox in unknown state should be ignored by most
	// functions, unless the caller needs to update sandbox state.
	StateUnknown State = iota
	// StateReady is ready state, it means sandbox container
	// is running.
	StateReady
	// StateNotReady is notready state, it ONLY means sandbox
	// container is not running.
	// StopPodSandbox should still be called for NOTREADY sandbox to
	// cleanup resources other than sandbox container, e.g. network namespace.
	// This is an assumption made in CRI.
	StateNotReady
)

type Status

type Status struct {
	// Pid is the init process id of the sandbox container.
	Pid uint32
	// CreatedAt is the created timestamp.
	CreatedAt time.Time
	// State is the state of the sandbox.
	State State
}

Status is the status of a sandbox.

type StatusStorage

type StatusStorage interface {
	// Get a sandbox status.
	Get() Status
	// Update the sandbox status. Note that the update MUST be applied
	// in one transaction.
	Update(UpdateFunc) error
}

StatusStorage manages the sandbox status. The status storage for sandbox is different from container status storage, because we don't checkpoint sandbox status. If we need checkpoint in the future, we should combine this with container status storage.

func StoreStatus

func StoreStatus(status Status) StatusStorage

StoreStatus creates the storage containing the passed in sandbox 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 sandboxes.

func NewStore

func NewStore() *Store

NewStore creates a sandbox store.

func (*Store) Add

func (s *Store) Add(sb Sandbox) error

Add a sandbox into the store.

func (*Store) Delete

func (s *Store) Delete(id string)

Delete deletes the sandbox with specified id.

func (*Store) Get

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

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

func (*Store) GetAll

func (s *Store) GetAll(id string) (Sandbox, error)

GetAll returns the sandbox with specified id, including sandbox in unknown state. Returns store.ErrNotExist if the sandbox doesn't exist.

func (*Store) List

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

List lists all sandboxes.

type UpdateFunc

type UpdateFunc func(Status) (Status, error)

UpdateFunc is function used to update the sandbox 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