store

package
v0.0.0-...-04f2983 Latest Latest
Warning

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

Go to latest
Published: May 5, 2021 License: Apache-2.0, Apache-2.0 Imports: 17 Imported by: 6

Documentation

Index

Constants

View Source
const (
	// ConfigurationFile is the file name used for every JSON sandbox configuration.
	ConfigurationFile string = "config.json"

	// StateFile is the file name storing a sandbox state.
	StateFile = "state.json"

	// NetworkFile is the file name storing a sandbox network.
	NetworkFile = "network.json"

	// HypervisorFile is the file name storing a hypervisor's state.
	HypervisorFile = "hypervisor.json"

	// AgentFile is the file name storing an agent's state.
	AgentFile = "agent.json"

	// ProcessFile is the file name storing a container process.
	ProcessFile = "process.json"

	// LockFile is the file name locking the usage of a resource.
	LockFile = "lock"

	// MountsFile is the file name storing a container's mount points.
	MountsFile = "mounts.json"

	// DevicesFile is the file name storing a container's devices.
	DevicesFile = "devices.json"
)
View Source
const DirMode = os.FileMode(0750) | os.ModeDir

DirMode is the permission bits used for creating a directory

View Source
const SandboxPathSuffix = "sbs"

SandboxPathSuffix is the suffix used for sandbox storage

View Source
const StoragePathSuffix = "vc"

StoragePathSuffix is the suffix used for all storage paths

Note: this very brief path represents "virtcontainers". It is as terse as possible to minimise path length.

View Source
const UUIDPathSuffix = "uuid"

UUIDPathSuffix is the suffix used for uuid storage

View Source
const VMPathSuffix = "vm"

VMPathSuffix is the suffix used for guest VMs.

Variables

View Source
var ConfigStoragePath = func() string {
	path := filepath.Join("/var/lib", StoragePathSuffix, SandboxPathSuffix)
	if rootless.IsRootless() {
		return filepath.Join(rootless.GetRootlessDir(), path)
	}
	return path
}

ConfigStoragePath is the sandbox configuration directory. It will contain one config.json file for each created sandbox. The function is declared this way for mocking in unit tests

View Source
var RunStoragePath = func() string {
	path := filepath.Join("/run", StoragePathSuffix, SandboxPathSuffix)
	if rootless.IsRootless() {
		return filepath.Join(rootless.GetRootlessDir(), path)
	}
	return path
}

RunStoragePath is the sandbox runtime directory. It will contain one state.json and one lock file for each created sandbox. The function is declared this way for mocking in unit tests

View Source
var RunVMStoragePath = func() string {
	path := filepath.Join("/run", StoragePathSuffix, VMPathSuffix)
	if rootless.IsRootless() {
		return filepath.Join(rootless.GetRootlessDir(), path)
	}
	return path
}

RunVMStoragePath is the vm directory. It will contain all guest vm sockets and shared mountpoints. The function is declared this way for mocking in unit tests

View Source
var VCStorePrefix = ""

VCStorePrefix is only used for tests to config a temp store dir

View Source
var VMUUIDStoragePath = func() string {
	path := filepath.Join("/var/lib", StoragePathSuffix, UUIDPathSuffix)
	if rootless.IsRootless() {
		return filepath.Join(rootless.GetRootlessDir(), path)
	}
	return path

}

VMUUIDStoragePath is the uuid directory. It will contain all uuid info used by guest vm.

Functions

func ContainerConfigurationRoot

func ContainerConfigurationRoot(sandboxID, containerID string) string

ContainerConfigurationRoot returns a virtcontainers container configuration root URL. This will hold across host reboot persistent data about a container configuration. It should look like file:///var/lib/vc/sbs/<sandboxID>/<containerID> Or if rootless file://<rootlessDir>/var/lib/vc/sbs/<sandboxID>/<containerID>

func ContainerConfigurationRootPath

func ContainerConfigurationRootPath(sandboxID, containerID string) string

ContainerConfigurationRootPath returns a virtcontainers container configuration root path.

func ContainerRuntimeRoot

func ContainerRuntimeRoot(sandboxID, containerID string) string

ContainerRuntimeRoot returns a virtcontainers container runtime root URL. This will hold data related to a container run-time state that will not be persistent across host reboots. It should look like file:///run/vc/sbs/<sandboxID>/<containerID>/ Or for rootless file://<rootlessDir>/run/vc/sbs/<sandboxID>/<containerID>/

func ContainerRuntimeRootPath

func ContainerRuntimeRootPath(sandboxID, containerID string) string

ContainerRuntimeRootPath returns a virtcontainers container runtime root path.

func DeleteAll

func DeleteAll()

DeleteAll deletes all Stores from the manager.

func SandboxConfigurationItemPath

func SandboxConfigurationItemPath(id string, item Item) (string, error)

SandboxConfigurationItemPath returns a virtcontainers sandbox configuration item path.

func SandboxConfigurationRoot

func SandboxConfigurationRoot(id string) string

SandboxConfigurationRoot returns a virtcontainers sandbox configuration root URL. This will hold across host reboot persistent data about a sandbox configuration. It should look like file:///var/lib/vc/sbs/<sandboxID>/ Or for rootless: file://<rootlessDir>/var/lib/vc/sbs/<sandboxID>/

func SandboxConfigurationRootPath

func SandboxConfigurationRootPath(id string) string

SandboxConfigurationRootPath returns a virtcontainers sandbox configuration root path.

func SandboxRuntimeItemPath

func SandboxRuntimeItemPath(id string, item Item) (string, error)

SandboxRuntimeItemPath returns a virtcontainers sandbox runtime item path.

func SandboxRuntimeRoot

func SandboxRuntimeRoot(id string) string

SandboxRuntimeRoot returns a virtcontainers sandbox runtime root URL. This will hold data related to a sandbox run-time state that will not be persistent across host reboots. It should look like file:///run/vc/sbs/<sandboxID>/ or if rootless: file://<rootlessDir>/run/vc/sbs/<sandboxID>/

func SandboxRuntimeRootPath

func SandboxRuntimeRootPath(id string) string

SandboxRuntimeRootPath returns a virtcontainers sandbox runtime root path.

func SetLogger

func SetLogger(logger *logrus.Entry)

SetLogger sets the custom logger to be used by this package. If not called, the package will create its own logger.

func VCSandboxStoreExists

func VCSandboxStoreExists(ctx context.Context, sandboxID string) bool

VCSandboxStoreExists returns true if a sandbox store already exists.

func VCStoreUUIDPath

func VCStoreUUIDPath() string

VCStoreUUIDPath returns a virtcontainers runtime uuid URL.

Types

type Item

type Item uint8

Item represents a virtcontainers items that will be managed through the store.

const (
	// Configuration represents a configuration item to be stored
	Configuration Item = iota

	// State represents a state item to be stored.
	State

	// Network represents a networking item to be stored.
	Network

	// Hypervisor represents an hypervisor item to be stored.
	Hypervisor

	// Agent represents a agent item to be stored.
	Agent

	// Process represents a container process item to be stored.
	Process

	// Lock represents a lock item to be stored.
	Lock

	// Mounts represents a set of mounts related item to be stored.
	Mounts

	// Devices represents a set of devices related item to be stored.
	Devices

	// DeviceIDs represents a set of reference IDs item to be stored.
	DeviceIDs

	// UUID represents a set of uuids item to be stored.
	UUID
)

func (Item) String

func (i Item) String() string

type Store

type Store struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Store is an opaque structure representing a virtcontainers Store.

func New

func New(ctx context.Context, storeURL string) (*Store, error)

New will return a new virtcontainers Store. If there is already a Store for the URL, we will re-use it. Otherwise a new Store is created.

func (*Store) Delete

func (s *Store) Delete() error

Delete deletes all artifacts created by a Store. The Store is also removed from the manager.

func (*Store) ItemLock

func (s *Store) ItemLock(item Item, exclusive bool) (string, error)

ItemLock takes a lock on an item.

func (*Store) ItemUnlock

func (s *Store) ItemUnlock(item Item, token string) error

ItemUnlock unlocks an item.

func (*Store) Load

func (s *Store) Load(item Item, data interface{}) error

Load loads a virtcontainers item from a Store.

func (*Store) Logger

func (s *Store) Logger() *logrus.Entry

Logger returns a logrus logger appropriate for logging Store messages

func (*Store) Raw

func (s *Store) Raw(id string) (string, error)

Raw creates a raw item to be handled directly by the API caller. It returns a full URL to the item and the caller is responsible for handling the item through this URL.

func (*Store) Store

func (s *Store) Store(item Item, data interface{}) error

Store stores a virtcontainers item into a Store.

type TypedDevice

type TypedDevice struct {
	Type string

	// Data is assigned the Device object.
	// This being declared as RawMessage prevents it from being  marshalled/unmarshalled.
	// We do that explicitly depending on Type.
	Data json.RawMessage
}

TypedDevice is used as an intermediate representation for marshalling and unmarshalling Device implementations.

type VCStore

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

VCStore is a virtcontainers specific Store. Virtcontainers typically needs a configuration Store for storing permanent items across reboots. It also needs a state Store for storing states and other run-time related items. Those should not survive a reboot.

VCStore simply dispatches items into the right Store.

func NewVCContainerStore

func NewVCContainerStore(ctx context.Context, sandboxID, containerID string) (*VCStore, error)

NewVCContainerStore creates a virtcontainers container Store, with filesystem backend.

func NewVCSandboxStore

func NewVCSandboxStore(ctx context.Context, sandboxID string) (*VCStore, error)

NewVCSandboxStore creates a virtcontainers sandbox Store, with filesystem backend.

func NewVCStore

func NewVCStore(ctx context.Context, configRoot, stateRoot string) (*VCStore, error)

NewVCStore creates a virtcontainers specific Store.

func (*VCStore) Delete

func (s *VCStore) Delete() error

Delete deletes all artifacts created by a VCStore. Both config and state Stores are also removed from the manager.

func (*VCStore) Load

func (s *VCStore) Load(item Item, data interface{}) error

Load loads a virtcontainers item from the right Store.

func (*VCStore) LoadContainerState

func (s *VCStore) LoadContainerState() (types.ContainerState, error)

LoadContainerState loads an returns a virtcontainer state

func (*VCStore) LoadDevices

func (s *VCStore) LoadDevices() ([]api.Device, error)

LoadDevices loads an returns a virtcontainer devices slice. We need a custom unmarshalling routine for translating TypedDevices into api.Devices based on their type.

func (*VCStore) LoadState

func (s *VCStore) LoadState() (types.SandboxState, error)

LoadState loads an returns a virtcontainer state

func (*VCStore) Lock

func (s *VCStore) Lock() (string, error)

Lock takes an exclusive lock on the virtcontainers state Lock item.

func (*VCStore) RLock

func (s *VCStore) RLock() (string, error)

RLock takes a shared lock on the virtcontainers state Lock item.

func (*VCStore) Raw

func (s *VCStore) Raw(id string) (string, error)

Raw creates a raw item in the virtcontainer state Store. A raw item is a custom one, not defined through the Item enum, and that the caller needs to handle directly. Typically this is used to create a custom virtcontainers file. For example the Firecracker code uses this API to create temp files under the sandbox state root path, and uses them as block driver backend placeholder.

func (*VCStore) Store

func (s *VCStore) Store(item Item, data interface{}) error

Store stores a virtcontainers item into the right Store.

func (*VCStore) StoreDevices

func (s *VCStore) StoreDevices(devices []api.Device) error

StoreDevices stores a virtcontainers devices slice. The Device slice is first marshalled into a TypedDevice one to include the type of the Device objects.

func (*VCStore) Unlock

func (s *VCStore) Unlock(token string) error

Unlock unlocks the virtcontainers state Lock item.

Jump to

Keyboard shortcuts

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