Documentation ¶
Overview ¶
Package overmount - mount tars in an overlay filesystem
overmount is intended to mount docker images, or work with similar functionality to achieve a series of layered filesystems which can be composed into an image.
See the examples/ directory for examples of how to use the API.
github.com/pkg/errors.Wrap is in use with many of our errors; look at the errors.Cause API in that package for more information on how to extract the static error constants.
Index ¶
- Variables
- type Asset
- type Exporter
- type Image
- type Importer
- type Layer
- func (l *Layer) Config() (*v1.Image, error)
- func (l *Layer) Create() error
- func (l *Layer) Digest() (digest.Digest, error)
- func (l *Layer) Exists() bool
- func (l *Layer) ID() string
- func (l *Layer) LoadParent() error
- func (l *Layer) MountPath() string
- func (l *Layer) Pack(writer io.Writer) (digest.Digest, error)
- func (l *Layer) Path() string
- func (l *Layer) Remove() error
- func (l *Layer) RestoreParent() error
- func (l *Layer) SaveConfig(config *v1.Image) error
- func (l *Layer) SaveParent() error
- func (l *Layer) Unpack(reader io.Reader) (digest.Digest, error)
- type Mount
- type Repository
- func (r *Repository) AddLayer(layer *Layer) error
- func (r *Repository) AddMount(mount *Mount) error
- func (r *Repository) CreateLayer(id string, parent *Layer) (*Layer, error)
- func (r *Repository) Export(e Exporter, layer *Layer) (io.ReadCloser, error)
- func (r *Repository) Import(i Importer, reader io.ReadCloser) ([]*Layer, error)
- func (r *Repository) NewImage(topLayer *Layer) *Image
- func (r *Repository) NewLayer(id string, parent *Layer) (*Layer, error)
- func (r *Repository) NewMount(target, lower, upper string) (*Mount, error)
- func (r *Repository) RemoveLayer(layer *Layer)
- func (r *Repository) RemoveMount(mount *Mount)
- func (r *Repository) TempDir() (string, error)
Constants ¶
This section is empty.
Variables ¶
var ( // ErrParentNotMounted is returned when the parent layer is not mounted (but exists) ErrParentNotMounted = errors.New("parent not mounted, cannot continue") // ErrMountFailed returns an underlying error when the mount has failed. ErrMountFailed = errors.New("mount failed") // ErrUnmountFailed returns an underlying error when the unmount has failed. ErrUnmountFailed = errors.New("unmount failed") // ErrMountCannotProceed returns an underlying error when the mount cannot be processed. ErrMountCannotProceed = errors.New("mount cannot proceed") // ErrImageCannotBeComposed is returned when an image (a set of layers) fails validation. ErrImageCannotBeComposed = errors.New("image cannot be composed") // ErrInvalidAsset is returned when the asset cannot be used. ErrInvalidAsset = errors.New("invalid asset") // ErrInvalidLayer is returned when the layer cannot be used. ErrInvalidLayer = errors.New("invalid layer") // ErrLayerExists is called when a layer id already exists in the repository. ErrLayerExists = errors.New("layer already exists") // ErrMountExists is called when a mount already exists in the repository. ErrMountExists = errors.New("mount already exists") )
Functions ¶
This section is empty.
Types ¶
type Asset ¶
type Asset struct {
// contains filtered or unexported fields
}
Asset is the representation of an on-disk asset. Assets usually are a pair of (path, tar) where one direction is applied; f.e., you can copy from the tar to the dir, or the dir to the tar using the Read and Write calls.
func NewAsset ¶
NewAsset constructs a new *Asset that operates on path `path`. A digester must be provided. Typically this is a `digest.SHA256.Digester()` but can be any algorithm that opencontainers/go-digest supports.
func (*Asset) LoadDigest ¶
LoadDigest processes the digest from the existing contents of the filesystem.
type Exporter ¶
type Exporter interface { // Export produces a tar represented as an io.ReadCloser from the Layer provided. Export(*Layer) (io.ReadCloser, error) }
Exporter is an interface to image exporters; ways to get images out of overmount repositories.
type Image ¶
type Image struct {
// contains filtered or unexported fields
}
Image is the representation of a set of sequential layers to be mounted.
type Importer ¶
type Importer interface { // Import takes a tar represented as an io.ReadCloser, and converts and unpacks // it into the overmount repository. Returns the top-most layer and any // error. Import(*Repository, io.ReadCloser) ([]*Layer, error) }
Importer is an interface to image importers; ways to get images into overmount repositories.
type Layer ¶
type Layer struct { Parent *Layer // contains filtered or unexported fields }
Layer is the representation of a filesystem layer. Layers are organized in a reverse linked-list from topmost layer to the root layer. In an (*Image).Mount() scenario, the layers are mounted from the bottom up to culminate in a mount path that represents the top-most layer merged with all the lower layers.
See https://www.kernel.org/doc/Documentation/filesystems/overlayfs.txt for more information on mount flags.
func (*Layer) Create ¶
Create creates the layer and makes it available for use, if possible. Otherwise, it returns an error.
func (*Layer) LoadParent ¶
LoadParent loads only the parent for this specific instance. See RestoreParent for restoring the whole chain.
func (*Layer) RestoreParent ¶
RestoreParent reads any parent file and sets the layer accordingly. It does this recursively.
func (*Layer) SaveConfig ¶
SaveConfig writes a *v1.Image configuration to the repository for the layer.
func (*Layer) SaveParent ¶
SaveParent will silently only save the
type Mount ¶
type Mount struct {
// contains filtered or unexported fields
}
Mount represents a single overlay mount. The lower value is computed from the parent layer of the layer provided to the NewMount call. The target and upper dirs are computed from the passed layer.
func (*Mount) Close ¶
Close a mount and remove the work directory. The target directory is left untouched.
type Repository ¶
type Repository struct {
// contains filtered or unexported fields
}
Repository is a collection of mounts/layers. Repositories have a base path and a collection of layers and mounts. Overlay work directories are stored in `tmp`.
In summary:
basedir/ layers/ layer-id/ top-layer/ tmp/ some-random-workdir/ mount/ another-layer-id/ top-layer/
Repositories can hold any number of mounts and layers. They do not necessarily need to be related.
func NewRepository ¶
func NewRepository(baseDir string) (*Repository, error)
NewRepository constructs a *Repository and creates the dir in which the repository lives. A repository is used to hold images and mounts.
func (*Repository) AddLayer ¶
func (r *Repository) AddLayer(layer *Layer) error
AddLayer adds a layer to the repository.
func (*Repository) AddMount ¶
func (r *Repository) AddMount(mount *Mount) error
AddMount adds a layer to the repository.
func (*Repository) CreateLayer ¶
func (r *Repository) CreateLayer(id string, parent *Layer) (*Layer, error)
CreateLayer prepares a new layer for work and creates it in the repository.
func (*Repository) Export ¶
func (r *Repository) Export(e Exporter, layer *Layer) (io.ReadCloser, error)
Export an image (provided via writer) from the repository.
func (*Repository) Import ¶
func (r *Repository) Import(i Importer, reader io.ReadCloser) ([]*Layer, error)
Import an image (provided over reader) to the repository.
func (*Repository) NewImage ¶
func (r *Repository) NewImage(topLayer *Layer) *Image
NewImage preps a set of layers to be a part of an image. There must be at least two layers
func (*Repository) NewLayer ¶
func (r *Repository) NewLayer(id string, parent *Layer) (*Layer, error)
NewLayer prepares a new layer for work but DOES NOT add it to the repository. The ID is the directory that will be created in the repository; see NewRepository for more info.
func (*Repository) NewMount ¶
func (r *Repository) NewMount(target, lower, upper string) (*Mount, error)
NewMount creates a new mount for use. Target, lower, and upper correspond to specific fields in the mount stanza; read https://www.kernel.org/doc/Documentation/filesystems/overlayfs.txt for more information.
func (*Repository) RemoveLayer ¶
func (r *Repository) RemoveLayer(layer *Layer)
RemoveLayer removes a layer from the repository
func (*Repository) RemoveMount ¶
func (r *Repository) RemoveMount(mount *Mount)
RemoveMount removes a layer from the repository
func (*Repository) TempDir ¶
func (r *Repository) TempDir() (string, error)
TempDir returns a temporary path within the repository