rename snapshot->snapshots pkg
Signed-off-by: Jess Valarezo <valarezo.jessica@gmail.com>
This commit is contained in:
parent
61c8fe2307
commit
9885edfc44
@ -33,7 +33,7 @@ import (
|
||||
"github.com/containerd/containerd/remotes"
|
||||
"github.com/containerd/containerd/remotes/docker"
|
||||
"github.com/containerd/containerd/remotes/docker/schema1"
|
||||
"github.com/containerd/containerd/snapshot"
|
||||
"github.com/containerd/containerd/snapshots"
|
||||
"github.com/containerd/typeurl"
|
||||
ptypes "github.com/gogo/protobuf/types"
|
||||
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
|
||||
@ -435,7 +435,7 @@ func (c *Client) ContentStore() content.Store {
|
||||
}
|
||||
|
||||
// SnapshotService returns the underlying snapshotter for the provided snapshotter name
|
||||
func (c *Client) SnapshotService(snapshotterName string) snapshot.Snapshotter {
|
||||
func (c *Client) SnapshotService(snapshotterName string) snapshots.Snapshotter {
|
||||
return NewSnapshotterFromClient(snapshotapi.NewSnapshotsClient(c.conn), snapshotterName)
|
||||
}
|
||||
|
||||
|
@ -2,4 +2,4 @@
|
||||
|
||||
package main
|
||||
|
||||
import _ "github.com/containerd/containerd/snapshot/btrfs"
|
||||
import _ "github.com/containerd/containerd/snapshots/btrfs"
|
||||
|
@ -3,5 +3,5 @@ package main
|
||||
import (
|
||||
_ "github.com/containerd/containerd/linux"
|
||||
_ "github.com/containerd/containerd/metrics/cgroups"
|
||||
_ "github.com/containerd/containerd/snapshot/overlay"
|
||||
_ "github.com/containerd/containerd/snapshots/overlay"
|
||||
)
|
||||
|
@ -3,5 +3,5 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
_ "github.com/containerd/containerd/snapshot/naive"
|
||||
_ "github.com/containerd/containerd/snapshots/naive"
|
||||
)
|
||||
|
@ -1,6 +1,6 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
_ "github.com/containerd/containerd/snapshot/windows"
|
||||
_ "github.com/containerd/containerd/snapshots/windows"
|
||||
_ "github.com/containerd/containerd/windows"
|
||||
)
|
||||
|
@ -11,7 +11,7 @@ import (
|
||||
"github.com/containerd/containerd/log"
|
||||
"github.com/containerd/containerd/mount"
|
||||
"github.com/containerd/containerd/progress"
|
||||
"github.com/containerd/containerd/snapshot"
|
||||
"github.com/containerd/containerd/snapshots"
|
||||
digest "github.com/opencontainers/go-digest"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/urfave/cli"
|
||||
@ -53,7 +53,7 @@ var listCommand = cli.Command{
|
||||
tw = tabwriter.NewWriter(os.Stdout, 1, 8, 1, ' ', 0)
|
||||
)
|
||||
fmt.Fprintln(tw, "KEY\tPARENT\tKIND\t")
|
||||
if err := snapshotter.Walk(ctx, func(ctx gocontext.Context, info snapshot.Info) error {
|
||||
if err := snapshotter.Walk(ctx, func(ctx gocontext.Context, info snapshots.Info) error {
|
||||
fmt.Fprintf(tw, "%v\t%v\t%v\t\n",
|
||||
info.Name,
|
||||
info.Parent,
|
||||
@ -99,7 +99,7 @@ var usageCommand = cli.Command{
|
||||
)
|
||||
fmt.Fprintln(tw, "KEY\tSIZE\tINODES\t")
|
||||
if context.NArg() == 0 {
|
||||
if err := snapshotter.Walk(ctx, func(ctx gocontext.Context, info snapshot.Info) error {
|
||||
if err := snapshotter.Walk(ctx, func(ctx gocontext.Context, info snapshots.Info) error {
|
||||
usage, err := snapshotter.Usage(ctx, info.Name)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -290,7 +290,7 @@ var treeCommand = cli.Command{
|
||||
tree = make(map[string]*snapshotTreeNode)
|
||||
)
|
||||
|
||||
if err := snapshotter.Walk(ctx, func(ctx gocontext.Context, info snapshot.Info) error {
|
||||
if err := snapshotter.Walk(ctx, func(ctx gocontext.Context, info snapshots.Info) error {
|
||||
// Get or create node and add node details
|
||||
node := getOrCreateTreeNode(info.Name, tree)
|
||||
if info.Parent != "" {
|
||||
@ -352,7 +352,7 @@ var setLabelCommand = cli.Command{
|
||||
|
||||
snapshotter := client.SnapshotService(context.GlobalString("snapshotter"))
|
||||
|
||||
info := snapshot.Info{
|
||||
info := snapshots.Info{
|
||||
Name: key,
|
||||
Labels: map[string]string{},
|
||||
}
|
||||
|
4
image.go
4
image.go
@ -9,7 +9,7 @@ import (
|
||||
"github.com/containerd/containerd/images"
|
||||
"github.com/containerd/containerd/platforms"
|
||||
"github.com/containerd/containerd/rootfs"
|
||||
"github.com/containerd/containerd/snapshot"
|
||||
"github.com/containerd/containerd/snapshots"
|
||||
digest "github.com/opencontainers/go-digest"
|
||||
"github.com/opencontainers/image-spec/identity"
|
||||
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
|
||||
@ -112,7 +112,7 @@ func (i *image) Unpack(ctx context.Context, snapshotterName string) error {
|
||||
"containerd.io/uncompressed": layer.Diff.Digest.String(),
|
||||
}
|
||||
|
||||
unpacked, err = rootfs.ApplyLayer(ctx, layer, chain, sn, a, snapshot.WithLabels(labels))
|
||||
unpacked, err = rootfs.ApplyLayer(ctx, layer, chain, sn, a, snapshots.WithLabels(labels))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ import (
|
||||
"github.com/containerd/containerd/content"
|
||||
"github.com/containerd/containerd/gc"
|
||||
"github.com/containerd/containerd/log"
|
||||
"github.com/containerd/containerd/snapshot"
|
||||
"github.com/containerd/containerd/snapshots"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
@ -60,7 +60,7 @@ type DB struct {
|
||||
|
||||
// NewDB creates a new metadata database using the provided
|
||||
// bolt database, content store, and snapshotters.
|
||||
func NewDB(db *bolt.DB, cs content.Store, ss map[string]snapshot.Snapshotter) *DB {
|
||||
func NewDB(db *bolt.DB, cs content.Store, ss map[string]snapshots.Snapshotter) *DB {
|
||||
m := &DB{
|
||||
db: db,
|
||||
ss: make(map[string]*snapshotter, len(ss)),
|
||||
@ -171,7 +171,7 @@ func (m *DB) ContentStore() content.Store {
|
||||
|
||||
// Snapshotter returns a namespaced content store for
|
||||
// the requested snapshotter name proxied to a snapshotter.
|
||||
func (m *DB) Snapshotter(name string) snapshot.Snapshotter {
|
||||
func (m *DB) Snapshotter(name string) snapshots.Snapshotter {
|
||||
sn, ok := m.ss[name]
|
||||
if !ok {
|
||||
return nil
|
||||
|
@ -21,8 +21,8 @@ import (
|
||||
"github.com/containerd/containerd/gc"
|
||||
"github.com/containerd/containerd/images"
|
||||
"github.com/containerd/containerd/namespaces"
|
||||
"github.com/containerd/containerd/snapshot"
|
||||
"github.com/containerd/containerd/snapshot/naive"
|
||||
"github.com/containerd/containerd/snapshots"
|
||||
"github.com/containerd/containerd/snapshots/naive"
|
||||
"github.com/gogo/protobuf/types"
|
||||
digest "github.com/opencontainers/go-digest"
|
||||
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
|
||||
@ -377,7 +377,7 @@ type object struct {
|
||||
labels map[string]string
|
||||
}
|
||||
|
||||
func create(obj object, tx *bolt.Tx, cs content.Store, sn snapshot.Snapshotter) (*gc.Node, error) {
|
||||
func create(obj object, tx *bolt.Tx, cs content.Store, sn snapshots.Snapshotter) (*gc.Node, error) {
|
||||
var (
|
||||
node *gc.Node
|
||||
namespace = "test"
|
||||
@ -408,7 +408,7 @@ func create(obj object, tx *bolt.Tx, cs content.Store, sn snapshot.Snapshotter)
|
||||
case testSnapshot:
|
||||
ctx := WithTransactionContext(ctx, tx)
|
||||
if v.active {
|
||||
_, err := sn.Prepare(ctx, v.key, v.parent, snapshot.WithLabels(obj.labels))
|
||||
_, err := sn.Prepare(ctx, v.key, v.parent, snapshots.WithLabels(obj.labels))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -418,7 +418,7 @@ func create(obj object, tx *bolt.Tx, cs content.Store, sn snapshot.Snapshotter)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := sn.Commit(ctx, v.key, akey, snapshot.WithLabels(obj.labels)); err != nil {
|
||||
if err := sn.Commit(ctx, v.key, akey, snapshots.WithLabels(obj.labels)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
@ -528,7 +528,7 @@ type testContainer struct {
|
||||
snapshot string
|
||||
}
|
||||
|
||||
func newStores(t testing.TB) (*DB, content.Store, snapshot.Snapshotter, func()) {
|
||||
func newStores(t testing.TB) (*DB, content.Store, snapshots.Snapshotter, func()) {
|
||||
td, err := ioutil.TempDir("", "gc-test-")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@ -548,7 +548,7 @@ func newStores(t testing.TB) (*DB, content.Store, snapshot.Snapshotter, func())
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
mdb := NewDB(db, lcs, map[string]snapshot.Snapshotter{"naive": nsn})
|
||||
mdb := NewDB(db, lcs, map[string]snapshots.Snapshotter{"naive": nsn})
|
||||
|
||||
return mdb, mdb.ContentStore(), mdb.Snapshotter("naive"), func() {
|
||||
os.RemoveAll(td)
|
||||
|
@ -14,12 +14,12 @@ import (
|
||||
"github.com/containerd/containerd/metadata/boltutil"
|
||||
"github.com/containerd/containerd/mount"
|
||||
"github.com/containerd/containerd/namespaces"
|
||||
"github.com/containerd/containerd/snapshot"
|
||||
"github.com/containerd/containerd/snapshots"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type snapshotter struct {
|
||||
snapshot.Snapshotter
|
||||
snapshots.Snapshotter
|
||||
name string
|
||||
db *DB
|
||||
l sync.RWMutex
|
||||
@ -27,7 +27,7 @@ type snapshotter struct {
|
||||
|
||||
// newSnapshotter returns a new Snapshotter which namespaces the given snapshot
|
||||
// using the provided name and database.
|
||||
func newSnapshotter(db *DB, name string, sn snapshot.Snapshotter) *snapshotter {
|
||||
func newSnapshotter(db *DB, name string, sn snapshots.Snapshotter) *snapshotter {
|
||||
return &snapshotter{
|
||||
Snapshotter: sn,
|
||||
name: name,
|
||||
@ -75,15 +75,15 @@ func (s *snapshotter) resolveKey(ctx context.Context, key string) (string, error
|
||||
return id, nil
|
||||
}
|
||||
|
||||
func (s *snapshotter) Stat(ctx context.Context, key string) (snapshot.Info, error) {
|
||||
func (s *snapshotter) Stat(ctx context.Context, key string) (snapshots.Info, error) {
|
||||
ns, err := namespaces.NamespaceRequired(ctx)
|
||||
if err != nil {
|
||||
return snapshot.Info{}, err
|
||||
return snapshots.Info{}, err
|
||||
}
|
||||
|
||||
var (
|
||||
bkey string
|
||||
local = snapshot.Info{
|
||||
local = snapshots.Info{
|
||||
Name: key,
|
||||
}
|
||||
)
|
||||
@ -108,33 +108,33 @@ func (s *snapshotter) Stat(ctx context.Context, key string) (snapshot.Info, erro
|
||||
|
||||
return nil
|
||||
}); err != nil {
|
||||
return snapshot.Info{}, err
|
||||
return snapshots.Info{}, err
|
||||
}
|
||||
|
||||
info, err := s.Snapshotter.Stat(ctx, bkey)
|
||||
if err != nil {
|
||||
return snapshot.Info{}, err
|
||||
return snapshots.Info{}, err
|
||||
}
|
||||
|
||||
return overlayInfo(info, local), nil
|
||||
}
|
||||
|
||||
func (s *snapshotter) Update(ctx context.Context, info snapshot.Info, fieldpaths ...string) (snapshot.Info, error) {
|
||||
func (s *snapshotter) Update(ctx context.Context, info snapshots.Info, fieldpaths ...string) (snapshots.Info, error) {
|
||||
s.l.RLock()
|
||||
defer s.l.RUnlock()
|
||||
|
||||
ns, err := namespaces.NamespaceRequired(ctx)
|
||||
if err != nil {
|
||||
return snapshot.Info{}, err
|
||||
return snapshots.Info{}, err
|
||||
}
|
||||
|
||||
if info.Name == "" {
|
||||
return snapshot.Info{}, errors.Wrap(errdefs.ErrInvalidArgument, "")
|
||||
return snapshots.Info{}, errors.Wrap(errdefs.ErrInvalidArgument, "")
|
||||
}
|
||||
|
||||
var (
|
||||
bkey string
|
||||
local = snapshot.Info{
|
||||
local = snapshots.Info{
|
||||
Name: info.Name,
|
||||
}
|
||||
)
|
||||
@ -195,18 +195,18 @@ func (s *snapshotter) Update(ctx context.Context, info snapshot.Info, fieldpaths
|
||||
|
||||
return nil
|
||||
}); err != nil {
|
||||
return snapshot.Info{}, err
|
||||
return snapshots.Info{}, err
|
||||
}
|
||||
|
||||
info, err = s.Snapshotter.Stat(ctx, bkey)
|
||||
if err != nil {
|
||||
return snapshot.Info{}, err
|
||||
return snapshots.Info{}, err
|
||||
}
|
||||
|
||||
return overlayInfo(info, local), nil
|
||||
}
|
||||
|
||||
func overlayInfo(info, overlay snapshot.Info) snapshot.Info {
|
||||
func overlayInfo(info, overlay snapshots.Info) snapshots.Info {
|
||||
// Merge info
|
||||
info.Name = overlay.Name
|
||||
info.Created = overlay.Created
|
||||
@ -222,10 +222,10 @@ func overlayInfo(info, overlay snapshot.Info) snapshot.Info {
|
||||
return info
|
||||
}
|
||||
|
||||
func (s *snapshotter) Usage(ctx context.Context, key string) (snapshot.Usage, error) {
|
||||
func (s *snapshotter) Usage(ctx context.Context, key string) (snapshots.Usage, error) {
|
||||
bkey, err := s.resolveKey(ctx, key)
|
||||
if err != nil {
|
||||
return snapshot.Usage{}, err
|
||||
return snapshots.Usage{}, err
|
||||
}
|
||||
return s.Snapshotter.Usage(ctx, bkey)
|
||||
}
|
||||
@ -238,15 +238,15 @@ func (s *snapshotter) Mounts(ctx context.Context, key string) ([]mount.Mount, er
|
||||
return s.Snapshotter.Mounts(ctx, bkey)
|
||||
}
|
||||
|
||||
func (s *snapshotter) Prepare(ctx context.Context, key, parent string, opts ...snapshot.Opt) ([]mount.Mount, error) {
|
||||
func (s *snapshotter) Prepare(ctx context.Context, key, parent string, opts ...snapshots.Opt) ([]mount.Mount, error) {
|
||||
return s.createSnapshot(ctx, key, parent, false, opts)
|
||||
}
|
||||
|
||||
func (s *snapshotter) View(ctx context.Context, key, parent string, opts ...snapshot.Opt) ([]mount.Mount, error) {
|
||||
func (s *snapshotter) View(ctx context.Context, key, parent string, opts ...snapshots.Opt) ([]mount.Mount, error) {
|
||||
return s.createSnapshot(ctx, key, parent, true, opts)
|
||||
}
|
||||
|
||||
func (s *snapshotter) createSnapshot(ctx context.Context, key, parent string, readonly bool, opts []snapshot.Opt) ([]mount.Mount, error) {
|
||||
func (s *snapshotter) createSnapshot(ctx context.Context, key, parent string, readonly bool, opts []snapshots.Opt) ([]mount.Mount, error) {
|
||||
s.l.RLock()
|
||||
defer s.l.RUnlock()
|
||||
|
||||
@ -255,7 +255,7 @@ func (s *snapshotter) createSnapshot(ctx context.Context, key, parent string, re
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var base snapshot.Info
|
||||
var base snapshots.Info
|
||||
for _, opt := range opts {
|
||||
if err := opt(&base); err != nil {
|
||||
return nil, err
|
||||
@ -336,7 +336,7 @@ func (s *snapshotter) createSnapshot(ctx context.Context, key, parent string, re
|
||||
return m, nil
|
||||
}
|
||||
|
||||
func (s *snapshotter) Commit(ctx context.Context, name, key string, opts ...snapshot.Opt) error {
|
||||
func (s *snapshotter) Commit(ctx context.Context, name, key string, opts ...snapshots.Opt) error {
|
||||
s.l.RLock()
|
||||
defer s.l.RUnlock()
|
||||
|
||||
@ -345,7 +345,7 @@ func (s *snapshotter) Commit(ctx context.Context, name, key string, opts ...snap
|
||||
return err
|
||||
}
|
||||
|
||||
var base snapshot.Info
|
||||
var base snapshots.Info
|
||||
for _, opt := range opts {
|
||||
if err := opt(&base); err != nil {
|
||||
return err
|
||||
@ -493,10 +493,10 @@ func (s *snapshotter) Remove(ctx context.Context, key string) error {
|
||||
|
||||
type infoPair struct {
|
||||
bkey string
|
||||
info snapshot.Info
|
||||
info snapshots.Info
|
||||
}
|
||||
|
||||
func (s *snapshotter) Walk(ctx context.Context, fn func(context.Context, snapshot.Info) error) error {
|
||||
func (s *snapshotter) Walk(ctx context.Context, fn func(context.Context, snapshots.Info) error) error {
|
||||
ns, err := namespaces.NamespaceRequired(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -533,7 +533,7 @@ func (s *snapshotter) Walk(ctx context.Context, fn func(context.Context, snapsho
|
||||
|
||||
pair := infoPair{
|
||||
bkey: string(sbkt.Get(bucketKeyName)),
|
||||
info: snapshot.Info{
|
||||
info: snapshots.Info{
|
||||
Name: string(k),
|
||||
Parent: string(sbkt.Get(bucketKeyParent)),
|
||||
},
|
||||
@ -586,7 +586,7 @@ func (s *snapshotter) Walk(ctx context.Context, fn func(context.Context, snapsho
|
||||
return nil
|
||||
}
|
||||
|
||||
func validateSnapshot(info *snapshot.Info) error {
|
||||
func validateSnapshot(info *snapshots.Info) error {
|
||||
for k, v := range info.Labels {
|
||||
if err := labels.Validate(k, v); err != nil {
|
||||
return errors.Wrapf(err, "info.Labels")
|
||||
@ -670,7 +670,7 @@ func (s *snapshotter) garbageCollect(ctx context.Context) (d time.Duration, err
|
||||
}
|
||||
|
||||
type treeNode struct {
|
||||
info snapshot.Info
|
||||
info snapshots.Info
|
||||
remove bool
|
||||
children []*treeNode
|
||||
}
|
||||
@ -679,7 +679,7 @@ func (s *snapshotter) walkTree(ctx context.Context, seen map[string]struct{}) ([
|
||||
roots := []*treeNode{}
|
||||
nodes := map[string]*treeNode{}
|
||||
|
||||
if err := s.Snapshotter.Walk(ctx, func(ctx context.Context, info snapshot.Info) error {
|
||||
if err := s.Snapshotter.Walk(ctx, func(ctx context.Context, info snapshots.Info) error {
|
||||
_, isSeen := seen[info.Name]
|
||||
node, ok := nodes[info.Name]
|
||||
if !ok {
|
||||
|
@ -8,13 +8,13 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/boltdb/bolt"
|
||||
"github.com/containerd/containerd/snapshot"
|
||||
"github.com/containerd/containerd/snapshot/naive"
|
||||
"github.com/containerd/containerd/snapshot/testsuite"
|
||||
"github.com/containerd/containerd/snapshots"
|
||||
"github.com/containerd/containerd/snapshots/naive"
|
||||
"github.com/containerd/containerd/snapshots/testsuite"
|
||||
"github.com/containerd/containerd/testutil"
|
||||
)
|
||||
|
||||
func newTestSnapshotter(ctx context.Context, root string) (snapshot.Snapshotter, func() error, error) {
|
||||
func newTestSnapshotter(ctx context.Context, root string) (snapshots.Snapshotter, func() error, error) {
|
||||
naiveRoot := filepath.Join(root, "naive")
|
||||
if err := os.Mkdir(naiveRoot, 0770); err != nil {
|
||||
return nil, nil, err
|
||||
@ -29,7 +29,7 @@ func newTestSnapshotter(ctx context.Context, root string) (snapshot.Snapshotter,
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
sn := NewDB(db, nil, map[string]snapshot.Snapshotter{"naive": snapshotter}).Snapshotter("naive")
|
||||
sn := NewDB(db, nil, map[string]snapshots.Snapshotter{"naive": snapshotter}).Snapshotter("naive")
|
||||
|
||||
return sn, func() error {
|
||||
if err := sn.Close(); err != nil {
|
||||
|
@ -4,13 +4,13 @@ import (
|
||||
"context"
|
||||
|
||||
"github.com/containerd/containerd/content"
|
||||
"github.com/containerd/containerd/snapshot"
|
||||
"github.com/containerd/containerd/snapshots"
|
||||
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
|
||||
)
|
||||
|
||||
// Client interface used by SpecOpt
|
||||
type Client interface {
|
||||
SnapshotService(snapshotterName string) snapshot.Snapshotter
|
||||
SnapshotService(snapshotterName string) snapshots.Snapshotter
|
||||
}
|
||||
|
||||
// Image interface used by some SpecOpt to query image configuration
|
||||
|
@ -9,7 +9,7 @@ import (
|
||||
"github.com/containerd/containerd/diff"
|
||||
"github.com/containerd/containerd/errdefs"
|
||||
"github.com/containerd/containerd/log"
|
||||
"github.com/containerd/containerd/snapshot"
|
||||
"github.com/containerd/containerd/snapshots"
|
||||
"github.com/opencontainers/go-digest"
|
||||
"github.com/opencontainers/image-spec/identity"
|
||||
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
|
||||
@ -30,7 +30,7 @@ type Layer struct {
|
||||
// The returned result is a chain id digest representing all the applied layers.
|
||||
// Layers are applied in order they are given, making the first layer the
|
||||
// bottom-most layer in the layer chain.
|
||||
func ApplyLayers(ctx context.Context, layers []Layer, sn snapshot.Snapshotter, a diff.Differ) (digest.Digest, error) {
|
||||
func ApplyLayers(ctx context.Context, layers []Layer, sn snapshots.Snapshotter, a diff.Differ) (digest.Digest, error) {
|
||||
var chain []digest.Digest
|
||||
for _, layer := range layers {
|
||||
if _, err := ApplyLayer(ctx, layer, chain, sn, a); err != nil {
|
||||
@ -46,7 +46,7 @@ func ApplyLayers(ctx context.Context, layers []Layer, sn snapshot.Snapshotter, a
|
||||
// ApplyLayer applies a single layer on top of the given provided layer chain,
|
||||
// using the provided snapshotter and applier. If the layer was unpacked true
|
||||
// is returned, if the layer already exists false is returned.
|
||||
func ApplyLayer(ctx context.Context, layer Layer, chain []digest.Digest, sn snapshot.Snapshotter, a diff.Differ, opts ...snapshot.Opt) (bool, error) {
|
||||
func ApplyLayer(ctx context.Context, layer Layer, chain []digest.Digest, sn snapshots.Snapshotter, a diff.Differ, opts ...snapshots.Opt) (bool, error) {
|
||||
var (
|
||||
parent = identity.ChainID(chain)
|
||||
chainID = identity.ChainID(append(chain, layer.Diff.Digest))
|
||||
|
@ -5,7 +5,7 @@ import (
|
||||
|
||||
"github.com/containerd/containerd/diff"
|
||||
"github.com/containerd/containerd/mount"
|
||||
"github.com/containerd/containerd/snapshot"
|
||||
"github.com/containerd/containerd/snapshots"
|
||||
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
@ -14,7 +14,7 @@ import (
|
||||
// of the snapshot. A content ref is provided to track the progress of the
|
||||
// content creation and the provided snapshotter and mount differ are used
|
||||
// for calculating the diff. The descriptor for the layer diff is returned.
|
||||
func Diff(ctx context.Context, snapshotID string, sn snapshot.Snapshotter, d diff.Differ, opts ...diff.Opt) (ocispec.Descriptor, error) {
|
||||
func Diff(ctx context.Context, snapshotID string, sn snapshots.Snapshotter, d diff.Differ, opts ...diff.Opt) (ocispec.Descriptor, error) {
|
||||
info, err := sn.Stat(ctx, snapshotID)
|
||||
if err != nil {
|
||||
return ocispec.Descriptor{}, err
|
||||
@ -28,7 +28,7 @@ func Diff(ctx context.Context, snapshotID string, sn snapshot.Snapshotter, d dif
|
||||
defer sn.Remove(ctx, lowerKey)
|
||||
|
||||
var upper []mount.Mount
|
||||
if info.Kind == snapshot.KindActive {
|
||||
if info.Kind == snapshots.KindActive {
|
||||
upper, err = sn.Mounts(ctx, snapshotID)
|
||||
if err != nil {
|
||||
return ocispec.Descriptor{}, err
|
||||
|
@ -8,7 +8,7 @@ import (
|
||||
|
||||
"github.com/containerd/containerd/log"
|
||||
"github.com/containerd/containerd/mount"
|
||||
"github.com/containerd/containerd/snapshot"
|
||||
"github.com/containerd/containerd/snapshots"
|
||||
digest "github.com/opencontainers/go-digest"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
@ -26,7 +26,7 @@ type Mounter interface {
|
||||
}
|
||||
|
||||
// InitRootFS initializes the snapshot for use as a rootfs
|
||||
func InitRootFS(ctx context.Context, name string, parent digest.Digest, readonly bool, snapshotter snapshot.Snapshotter, mounter Mounter) ([]mount.Mount, error) {
|
||||
func InitRootFS(ctx context.Context, name string, parent digest.Digest, readonly bool, snapshotter snapshots.Snapshotter, mounter Mounter) ([]mount.Mount, error) {
|
||||
_, err := snapshotter.Stat(ctx, name)
|
||||
if err == nil {
|
||||
return nil, errors.Errorf("rootfs already exists")
|
||||
@ -51,7 +51,7 @@ func InitRootFS(ctx context.Context, name string, parent digest.Digest, readonly
|
||||
return snapshotter.Prepare(ctx, name, parentS)
|
||||
}
|
||||
|
||||
func createInitLayer(ctx context.Context, parent, initName string, initFn func(string) error, snapshotter snapshot.Snapshotter, mounter Mounter) (string, error) {
|
||||
func createInitLayer(ctx context.Context, parent, initName string, initFn func(string) error, snapshotter snapshots.Snapshotter, mounter Mounter) (string, error) {
|
||||
initS := fmt.Sprintf("%s %s", parent, initName)
|
||||
if _, err := snapshotter.Stat(ctx, initS); err == nil {
|
||||
return initS, nil
|
||||
|
@ -27,7 +27,7 @@ import (
|
||||
"github.com/containerd/containerd/log"
|
||||
"github.com/containerd/containerd/metadata"
|
||||
"github.com/containerd/containerd/plugin"
|
||||
"github.com/containerd/containerd/snapshot"
|
||||
"github.com/containerd/containerd/snapshots"
|
||||
metrics "github.com/docker/go-metrics"
|
||||
grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
|
||||
"github.com/pkg/errors"
|
||||
@ -199,7 +199,7 @@ func loadPlugins(config *Config) ([]*plugin.Registration, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
snapshotters := make(map[string]snapshot.Snapshotter)
|
||||
snapshotters := make(map[string]snapshots.Snapshotter)
|
||||
for name, sn := range snapshottersRaw {
|
||||
sn, err := sn.Instance()
|
||||
if err != nil {
|
||||
@ -207,7 +207,7 @@ func loadPlugins(config *Config) ([]*plugin.Registration, error) {
|
||||
Warnf("could not use snapshotter %v in metadata plugin", name)
|
||||
continue
|
||||
}
|
||||
snapshotters[name] = sn.(snapshot.Snapshotter)
|
||||
snapshotters[name] = sn.(snapshots.Snapshotter)
|
||||
}
|
||||
|
||||
path := filepath.Join(ic.Root, "meta.db")
|
||||
|
@ -12,7 +12,7 @@ import (
|
||||
"github.com/containerd/containerd/metadata"
|
||||
"github.com/containerd/containerd/mount"
|
||||
"github.com/containerd/containerd/plugin"
|
||||
"github.com/containerd/containerd/snapshot"
|
||||
"github.com/containerd/containerd/snapshots"
|
||||
ptypes "github.com/gogo/protobuf/types"
|
||||
"golang.org/x/net/context"
|
||||
"google.golang.org/grpc"
|
||||
@ -48,7 +48,7 @@ func newService(ic *plugin.InitContext) (interface{}, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *service) getSnapshotter(name string) (snapshot.Snapshotter, error) {
|
||||
func (s *service) getSnapshotter(name string) (snapshots.Snapshotter, error) {
|
||||
if name == "" {
|
||||
return nil, errdefs.ToGRPCf(errdefs.ErrInvalidArgument, "snapshotter argument missing")
|
||||
}
|
||||
@ -72,9 +72,9 @@ func (s *service) Prepare(ctx context.Context, pr *snapshotapi.PrepareSnapshotRe
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var opts []snapshot.Opt
|
||||
var opts []snapshots.Opt
|
||||
if pr.Labels != nil {
|
||||
opts = append(opts, snapshot.WithLabels(pr.Labels))
|
||||
opts = append(opts, snapshots.WithLabels(pr.Labels))
|
||||
}
|
||||
mounts, err := sn.Prepare(ctx, pr.Key, pr.Parent, opts...)
|
||||
if err != nil {
|
||||
@ -98,9 +98,9 @@ func (s *service) View(ctx context.Context, pr *snapshotapi.ViewSnapshotRequest)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var opts []snapshot.Opt
|
||||
var opts []snapshots.Opt
|
||||
if pr.Labels != nil {
|
||||
opts = append(opts, snapshot.WithLabels(pr.Labels))
|
||||
opts = append(opts, snapshots.WithLabels(pr.Labels))
|
||||
}
|
||||
mounts, err := sn.View(ctx, pr.Key, pr.Parent, opts...)
|
||||
if err != nil {
|
||||
@ -134,9 +134,9 @@ func (s *service) Commit(ctx context.Context, cr *snapshotapi.CommitSnapshotRequ
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var opts []snapshot.Opt
|
||||
var opts []snapshots.Opt
|
||||
if cr.Labels != nil {
|
||||
opts = append(opts, snapshot.WithLabels(cr.Labels))
|
||||
opts = append(opts, snapshots.WithLabels(cr.Labels))
|
||||
}
|
||||
if err := sn.Commit(ctx, cr.Name, cr.Key, opts...); err != nil {
|
||||
return nil, errdefs.ToGRPC(err)
|
||||
@ -214,7 +214,7 @@ func (s *service) List(sr *snapshotapi.ListSnapshotsRequest, ss snapshotapi.Snap
|
||||
})
|
||||
}
|
||||
)
|
||||
err = sn.Walk(ss.Context(), func(ctx gocontext.Context, info snapshot.Info) error {
|
||||
err = sn.Walk(ss.Context(), func(ctx gocontext.Context, info snapshots.Info) error {
|
||||
buffer = append(buffer, fromInfo(info))
|
||||
|
||||
if len(buffer) >= 100 {
|
||||
@ -254,17 +254,17 @@ func (s *service) Usage(ctx context.Context, ur *snapshotapi.UsageRequest) (*sna
|
||||
return fromUsage(usage), nil
|
||||
}
|
||||
|
||||
func fromKind(kind snapshot.Kind) snapshotapi.Kind {
|
||||
if kind == snapshot.KindActive {
|
||||
func fromKind(kind snapshots.Kind) snapshotapi.Kind {
|
||||
if kind == snapshots.KindActive {
|
||||
return snapshotapi.KindActive
|
||||
}
|
||||
if kind == snapshot.KindView {
|
||||
if kind == snapshots.KindView {
|
||||
return snapshotapi.KindView
|
||||
}
|
||||
return snapshotapi.KindCommitted
|
||||
}
|
||||
|
||||
func fromInfo(info snapshot.Info) snapshotapi.Info {
|
||||
func fromInfo(info snapshots.Info) snapshotapi.Info {
|
||||
return snapshotapi.Info{
|
||||
Name: info.Name,
|
||||
Parent: info.Parent,
|
||||
@ -275,7 +275,7 @@ func fromInfo(info snapshot.Info) snapshotapi.Info {
|
||||
}
|
||||
}
|
||||
|
||||
func fromUsage(usage snapshot.Usage) *snapshotapi.UsageResponse {
|
||||
func fromUsage(usage snapshots.Usage) *snapshotapi.UsageResponse {
|
||||
return &snapshotapi.UsageResponse{
|
||||
Inodes: usage.Inodes,
|
||||
Size_: usage.Size,
|
||||
@ -294,8 +294,8 @@ func fromMounts(mounts []mount.Mount) []*types.Mount {
|
||||
return out
|
||||
}
|
||||
|
||||
func toInfo(info snapshotapi.Info) snapshot.Info {
|
||||
return snapshot.Info{
|
||||
func toInfo(info snapshotapi.Info) snapshots.Info {
|
||||
return snapshots.Info{
|
||||
Name: info.Name,
|
||||
Parent: info.Parent,
|
||||
Kind: toKind(info.Kind),
|
||||
@ -305,12 +305,12 @@ func toInfo(info snapshotapi.Info) snapshot.Info {
|
||||
}
|
||||
}
|
||||
|
||||
func toKind(kind snapshotapi.Kind) snapshot.Kind {
|
||||
func toKind(kind snapshotapi.Kind) snapshots.Kind {
|
||||
if kind == snapshotapi.KindActive {
|
||||
return snapshot.KindActive
|
||||
return snapshots.KindActive
|
||||
}
|
||||
if kind == snapshotapi.KindView {
|
||||
return snapshot.KindView
|
||||
return snapshots.KindView
|
||||
}
|
||||
return snapshot.KindCommitted
|
||||
return snapshots.KindCommitted
|
||||
}
|
||||
|
54
snapshot.go
54
snapshot.go
@ -8,13 +8,13 @@ import (
|
||||
"github.com/containerd/containerd/api/types"
|
||||
"github.com/containerd/containerd/errdefs"
|
||||
"github.com/containerd/containerd/mount"
|
||||
"github.com/containerd/containerd/snapshot"
|
||||
"github.com/containerd/containerd/snapshots"
|
||||
protobuftypes "github.com/gogo/protobuf/types"
|
||||
)
|
||||
|
||||
// NewSnapshotterFromClient returns a new Snapshotter which communicates
|
||||
// over a GRPC connection.
|
||||
func NewSnapshotterFromClient(client snapshotapi.SnapshotsClient, snapshotterName string) snapshot.Snapshotter {
|
||||
func NewSnapshotterFromClient(client snapshotapi.SnapshotsClient, snapshotterName string) snapshots.Snapshotter {
|
||||
return &remoteSnapshotter{
|
||||
client: client,
|
||||
snapshotterName: snapshotterName,
|
||||
@ -26,19 +26,19 @@ type remoteSnapshotter struct {
|
||||
snapshotterName string
|
||||
}
|
||||
|
||||
func (r *remoteSnapshotter) Stat(ctx context.Context, key string) (snapshot.Info, error) {
|
||||
func (r *remoteSnapshotter) Stat(ctx context.Context, key string) (snapshots.Info, error) {
|
||||
resp, err := r.client.Stat(ctx,
|
||||
&snapshotapi.StatSnapshotRequest{
|
||||
Snapshotter: r.snapshotterName,
|
||||
Key: key,
|
||||
})
|
||||
if err != nil {
|
||||
return snapshot.Info{}, errdefs.FromGRPC(err)
|
||||
return snapshots.Info{}, errdefs.FromGRPC(err)
|
||||
}
|
||||
return toInfo(resp.Info), nil
|
||||
}
|
||||
|
||||
func (r *remoteSnapshotter) Update(ctx context.Context, info snapshot.Info, fieldpaths ...string) (snapshot.Info, error) {
|
||||
func (r *remoteSnapshotter) Update(ctx context.Context, info snapshots.Info, fieldpaths ...string) (snapshots.Info, error) {
|
||||
resp, err := r.client.Update(ctx,
|
||||
&snapshotapi.UpdateSnapshotRequest{
|
||||
Snapshotter: r.snapshotterName,
|
||||
@ -48,18 +48,18 @@ func (r *remoteSnapshotter) Update(ctx context.Context, info snapshot.Info, fiel
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
return snapshot.Info{}, errdefs.FromGRPC(err)
|
||||
return snapshots.Info{}, errdefs.FromGRPC(err)
|
||||
}
|
||||
return toInfo(resp.Info), nil
|
||||
}
|
||||
|
||||
func (r *remoteSnapshotter) Usage(ctx context.Context, key string) (snapshot.Usage, error) {
|
||||
func (r *remoteSnapshotter) Usage(ctx context.Context, key string) (snapshots.Usage, error) {
|
||||
resp, err := r.client.Usage(ctx, &snapshotapi.UsageRequest{
|
||||
Snapshotter: r.snapshotterName,
|
||||
Key: key,
|
||||
})
|
||||
if err != nil {
|
||||
return snapshot.Usage{}, errdefs.FromGRPC(err)
|
||||
return snapshots.Usage{}, errdefs.FromGRPC(err)
|
||||
}
|
||||
return toUsage(resp), nil
|
||||
}
|
||||
@ -75,8 +75,8 @@ func (r *remoteSnapshotter) Mounts(ctx context.Context, key string) ([]mount.Mou
|
||||
return toMounts(resp.Mounts), nil
|
||||
}
|
||||
|
||||
func (r *remoteSnapshotter) Prepare(ctx context.Context, key, parent string, opts ...snapshot.Opt) ([]mount.Mount, error) {
|
||||
var local snapshot.Info
|
||||
func (r *remoteSnapshotter) Prepare(ctx context.Context, key, parent string, opts ...snapshots.Opt) ([]mount.Mount, error) {
|
||||
var local snapshots.Info
|
||||
for _, opt := range opts {
|
||||
if err := opt(&local); err != nil {
|
||||
return nil, err
|
||||
@ -94,8 +94,8 @@ func (r *remoteSnapshotter) Prepare(ctx context.Context, key, parent string, opt
|
||||
return toMounts(resp.Mounts), nil
|
||||
}
|
||||
|
||||
func (r *remoteSnapshotter) View(ctx context.Context, key, parent string, opts ...snapshot.Opt) ([]mount.Mount, error) {
|
||||
var local snapshot.Info
|
||||
func (r *remoteSnapshotter) View(ctx context.Context, key, parent string, opts ...snapshots.Opt) ([]mount.Mount, error) {
|
||||
var local snapshots.Info
|
||||
for _, opt := range opts {
|
||||
if err := opt(&local); err != nil {
|
||||
return nil, err
|
||||
@ -113,8 +113,8 @@ func (r *remoteSnapshotter) View(ctx context.Context, key, parent string, opts .
|
||||
return toMounts(resp.Mounts), nil
|
||||
}
|
||||
|
||||
func (r *remoteSnapshotter) Commit(ctx context.Context, name, key string, opts ...snapshot.Opt) error {
|
||||
var local snapshot.Info
|
||||
func (r *remoteSnapshotter) Commit(ctx context.Context, name, key string, opts ...snapshots.Opt) error {
|
||||
var local snapshots.Info
|
||||
for _, opt := range opts {
|
||||
if err := opt(&local); err != nil {
|
||||
return err
|
||||
@ -137,7 +137,7 @@ func (r *remoteSnapshotter) Remove(ctx context.Context, key string) error {
|
||||
return errdefs.FromGRPC(err)
|
||||
}
|
||||
|
||||
func (r *remoteSnapshotter) Walk(ctx context.Context, fn func(context.Context, snapshot.Info) error) error {
|
||||
func (r *remoteSnapshotter) Walk(ctx context.Context, fn func(context.Context, snapshots.Info) error) error {
|
||||
sc, err := r.client.List(ctx, &snapshotapi.ListSnapshotsRequest{
|
||||
Snapshotter: r.snapshotterName,
|
||||
})
|
||||
@ -167,18 +167,18 @@ func (r *remoteSnapshotter) Close() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func toKind(kind snapshotapi.Kind) snapshot.Kind {
|
||||
func toKind(kind snapshotapi.Kind) snapshots.Kind {
|
||||
if kind == snapshotapi.KindActive {
|
||||
return snapshot.KindActive
|
||||
return snapshots.KindActive
|
||||
}
|
||||
if kind == snapshotapi.KindView {
|
||||
return snapshot.KindView
|
||||
return snapshots.KindView
|
||||
}
|
||||
return snapshot.KindCommitted
|
||||
return snapshots.KindCommitted
|
||||
}
|
||||
|
||||
func toInfo(info snapshotapi.Info) snapshot.Info {
|
||||
return snapshot.Info{
|
||||
func toInfo(info snapshotapi.Info) snapshots.Info {
|
||||
return snapshots.Info{
|
||||
Name: info.Name,
|
||||
Parent: info.Parent,
|
||||
Kind: toKind(info.Kind),
|
||||
@ -188,8 +188,8 @@ func toInfo(info snapshotapi.Info) snapshot.Info {
|
||||
}
|
||||
}
|
||||
|
||||
func toUsage(resp *snapshotapi.UsageResponse) snapshot.Usage {
|
||||
return snapshot.Usage{
|
||||
func toUsage(resp *snapshotapi.UsageResponse) snapshots.Usage {
|
||||
return snapshots.Usage{
|
||||
Inodes: resp.Inodes,
|
||||
Size: resp.Size_,
|
||||
}
|
||||
@ -207,17 +207,17 @@ func toMounts(mm []*types.Mount) []mount.Mount {
|
||||
return mounts
|
||||
}
|
||||
|
||||
func fromKind(kind snapshot.Kind) snapshotapi.Kind {
|
||||
if kind == snapshot.KindActive {
|
||||
func fromKind(kind snapshots.Kind) snapshotapi.Kind {
|
||||
if kind == snapshots.KindActive {
|
||||
return snapshotapi.KindActive
|
||||
}
|
||||
if kind == snapshot.KindView {
|
||||
if kind == snapshots.KindView {
|
||||
return snapshotapi.KindView
|
||||
}
|
||||
return snapshotapi.KindCommitted
|
||||
}
|
||||
|
||||
func fromInfo(info snapshot.Info) snapshotapi.Info {
|
||||
func fromInfo(info snapshots.Info) snapshotapi.Info {
|
||||
return snapshotapi.Info{
|
||||
Name: info.Name,
|
||||
Parent: info.Parent,
|
||||
|
@ -5,11 +5,11 @@ import (
|
||||
"runtime"
|
||||
"testing"
|
||||
|
||||
"github.com/containerd/containerd/snapshot"
|
||||
"github.com/containerd/containerd/snapshot/testsuite"
|
||||
"github.com/containerd/containerd/snapshots"
|
||||
"github.com/containerd/containerd/snapshots/testsuite"
|
||||
)
|
||||
|
||||
func newSnapshotter(ctx context.Context, root string) (snapshot.Snapshotter, func() error, error) {
|
||||
func newSnapshotter(ctx context.Context, root string) (snapshots.Snapshotter, func() error, error) {
|
||||
client, err := New(address)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
|
@ -14,8 +14,8 @@ import (
|
||||
"github.com/containerd/containerd/mount"
|
||||
"github.com/containerd/containerd/platforms"
|
||||
"github.com/containerd/containerd/plugin"
|
||||
"github.com/containerd/containerd/snapshot"
|
||||
"github.com/containerd/containerd/snapshot/storage"
|
||||
"github.com/containerd/containerd/snapshots"
|
||||
"github.com/containerd/containerd/snapshots/storage"
|
||||
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
@ -43,7 +43,7 @@ type snapshotter struct {
|
||||
// root directory for snapshots and stores the metadata in
|
||||
// a file in the provided root.
|
||||
// root needs to be a mount point of btrfs.
|
||||
func NewSnapshotter(root string) (snapshot.Snapshotter, error) {
|
||||
func NewSnapshotter(root string) (snapshots.Snapshotter, error) {
|
||||
// If directory does not exist, create it
|
||||
if _, err := os.Stat(root); err != nil {
|
||||
if !os.IsNotExist(err) {
|
||||
@ -93,41 +93,41 @@ func NewSnapshotter(root string) (snapshot.Snapshotter, error) {
|
||||
//
|
||||
// Should be used for parent resolution, existence checks and to discern
|
||||
// the kind of snapshot.
|
||||
func (b *snapshotter) Stat(ctx context.Context, key string) (snapshot.Info, error) {
|
||||
func (b *snapshotter) Stat(ctx context.Context, key string) (snapshots.Info, error) {
|
||||
ctx, t, err := b.ms.TransactionContext(ctx, false)
|
||||
if err != nil {
|
||||
return snapshot.Info{}, err
|
||||
return snapshots.Info{}, err
|
||||
}
|
||||
defer t.Rollback()
|
||||
_, info, _, err := storage.GetInfo(ctx, key)
|
||||
if err != nil {
|
||||
return snapshot.Info{}, err
|
||||
return snapshots.Info{}, err
|
||||
}
|
||||
|
||||
return info, nil
|
||||
}
|
||||
|
||||
func (b *snapshotter) Update(ctx context.Context, info snapshot.Info, fieldpaths ...string) (snapshot.Info, error) {
|
||||
func (b *snapshotter) Update(ctx context.Context, info snapshots.Info, fieldpaths ...string) (snapshots.Info, error) {
|
||||
ctx, t, err := b.ms.TransactionContext(ctx, true)
|
||||
if err != nil {
|
||||
return snapshot.Info{}, err
|
||||
return snapshots.Info{}, err
|
||||
}
|
||||
|
||||
info, err = storage.UpdateInfo(ctx, info, fieldpaths...)
|
||||
if err != nil {
|
||||
t.Rollback()
|
||||
return snapshot.Info{}, err
|
||||
return snapshots.Info{}, err
|
||||
}
|
||||
|
||||
if err := t.Commit(); err != nil {
|
||||
return snapshot.Info{}, err
|
||||
return snapshots.Info{}, err
|
||||
}
|
||||
|
||||
return info, nil
|
||||
}
|
||||
|
||||
// Usage retrieves the disk usage of the top-level snapshot.
|
||||
func (b *snapshotter) Usage(ctx context.Context, key string) (snapshot.Usage, error) {
|
||||
func (b *snapshotter) Usage(ctx context.Context, key string) (snapshots.Usage, error) {
|
||||
panic("not implemented")
|
||||
|
||||
// TODO(stevvooe): Btrfs has a quota model where data can be exclusive to a
|
||||
@ -143,7 +143,7 @@ func (b *snapshotter) Usage(ctx context.Context, key string) (snapshot.Usage, er
|
||||
}
|
||||
|
||||
// Walk the committed snapshots.
|
||||
func (b *snapshotter) Walk(ctx context.Context, fn func(context.Context, snapshot.Info) error) error {
|
||||
func (b *snapshotter) Walk(ctx context.Context, fn func(context.Context, snapshots.Info) error) error {
|
||||
ctx, t, err := b.ms.TransactionContext(ctx, false)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -152,15 +152,15 @@ func (b *snapshotter) Walk(ctx context.Context, fn func(context.Context, snapsho
|
||||
return storage.WalkInfo(ctx, fn)
|
||||
}
|
||||
|
||||
func (b *snapshotter) Prepare(ctx context.Context, key, parent string, opts ...snapshot.Opt) ([]mount.Mount, error) {
|
||||
return b.makeSnapshot(ctx, snapshot.KindActive, key, parent, opts)
|
||||
func (b *snapshotter) Prepare(ctx context.Context, key, parent string, opts ...snapshots.Opt) ([]mount.Mount, error) {
|
||||
return b.makeSnapshot(ctx, snapshots.KindActive, key, parent, opts)
|
||||
}
|
||||
|
||||
func (b *snapshotter) View(ctx context.Context, key, parent string, opts ...snapshot.Opt) ([]mount.Mount, error) {
|
||||
return b.makeSnapshot(ctx, snapshot.KindView, key, parent, opts)
|
||||
func (b *snapshotter) View(ctx context.Context, key, parent string, opts ...snapshots.Opt) ([]mount.Mount, error) {
|
||||
return b.makeSnapshot(ctx, snapshots.KindView, key, parent, opts)
|
||||
}
|
||||
|
||||
func (b *snapshotter) makeSnapshot(ctx context.Context, kind snapshot.Kind, key, parent string, opts []snapshot.Opt) ([]mount.Mount, error) {
|
||||
func (b *snapshotter) makeSnapshot(ctx context.Context, kind snapshots.Kind, key, parent string, opts []snapshots.Opt) ([]mount.Mount, error) {
|
||||
ctx, t, err := b.ms.TransactionContext(ctx, true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -190,7 +190,7 @@ func (b *snapshotter) makeSnapshot(ctx context.Context, kind snapshot.Kind, key,
|
||||
parentp := filepath.Join(b.root, "snapshots", s.ParentIDs[0])
|
||||
|
||||
var readonly bool
|
||||
if kind == snapshot.KindView {
|
||||
if kind == snapshots.KindView {
|
||||
readonly = true
|
||||
}
|
||||
|
||||
@ -222,7 +222,7 @@ func (b *snapshotter) mounts(dir string, s storage.Snapshot) ([]mount.Mount, err
|
||||
|
||||
options = append(options, fmt.Sprintf("subvolid=%d", sid))
|
||||
|
||||
if s.Kind != snapshot.KindActive {
|
||||
if s.Kind != snapshots.KindActive {
|
||||
options = append(options, "ro")
|
||||
}
|
||||
|
||||
@ -237,7 +237,7 @@ func (b *snapshotter) mounts(dir string, s storage.Snapshot) ([]mount.Mount, err
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (b *snapshotter) Commit(ctx context.Context, name, key string, opts ...snapshot.Opt) (err error) {
|
||||
func (b *snapshotter) Commit(ctx context.Context, name, key string, opts ...snapshots.Opt) (err error) {
|
||||
ctx, t, err := b.ms.TransactionContext(ctx, true)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -250,7 +250,7 @@ func (b *snapshotter) Commit(ctx context.Context, name, key string, opts ...snap
|
||||
}
|
||||
}()
|
||||
|
||||
id, err := storage.CommitActive(ctx, key, name, snapshot.Usage{}, opts...) // TODO(stevvooe): Resolve a usage value for btrfs
|
||||
id, err := storage.CommitActive(ctx, key, name, snapshots.Usage{}, opts...) // TODO(stevvooe): Resolve a usage value for btrfs
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to commit")
|
||||
}
|
||||
@ -330,14 +330,14 @@ func (b *snapshotter) Remove(ctx context.Context, key string) (err error) {
|
||||
}
|
||||
|
||||
switch k {
|
||||
case snapshot.KindView:
|
||||
case snapshots.KindView:
|
||||
source = filepath.Join(b.root, "view", id)
|
||||
removed = filepath.Join(b.root, "view", "rm-"+id)
|
||||
readonly = true
|
||||
case snapshot.KindActive:
|
||||
case snapshots.KindActive:
|
||||
source = filepath.Join(b.root, "active", id)
|
||||
removed = filepath.Join(b.root, "active", "rm-"+id)
|
||||
case snapshot.KindCommitted:
|
||||
case snapshots.KindCommitted:
|
||||
source = filepath.Join(b.root, "snapshots", id)
|
||||
removed = filepath.Join(b.root, "snapshots", "rm-"+id)
|
||||
readonly = true
|
@ -12,14 +12,14 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/containerd/containerd/mount"
|
||||
"github.com/containerd/containerd/snapshot"
|
||||
"github.com/containerd/containerd/snapshot/testsuite"
|
||||
"github.com/containerd/containerd/snapshots"
|
||||
"github.com/containerd/containerd/snapshots/testsuite"
|
||||
"github.com/containerd/containerd/testutil"
|
||||
"github.com/pkg/errors"
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
func boltSnapshotter(t *testing.T) func(context.Context, string) (snapshot.Snapshotter, func() error, error) {
|
||||
func boltSnapshotter(t *testing.T) func(context.Context, string) (snapshots.Snapshotter, func() error, error) {
|
||||
mkbtrfs, err := exec.LookPath("mkfs.btrfs")
|
||||
if err != nil {
|
||||
t.Skipf("could not find mkfs.btrfs: %v", err)
|
||||
@ -27,7 +27,7 @@ func boltSnapshotter(t *testing.T) func(context.Context, string) (snapshot.Snaps
|
||||
|
||||
// TODO: Check for btrfs in /proc/module and skip if not loaded
|
||||
|
||||
return func(ctx context.Context, root string) (snapshot.Snapshotter, func() error, error) {
|
||||
return func(ctx context.Context, root string) (snapshots.Snapshotter, func() error, error) {
|
||||
|
||||
deviceName, cleanupDevice, err := testutil.NewLoopback(100 << 20) // 100 MB
|
||||
if err != nil {
|
@ -11,8 +11,8 @@ import (
|
||||
"github.com/containerd/containerd/mount"
|
||||
"github.com/containerd/containerd/platforms"
|
||||
"github.com/containerd/containerd/plugin"
|
||||
"github.com/containerd/containerd/snapshot"
|
||||
"github.com/containerd/containerd/snapshot/storage"
|
||||
"github.com/containerd/containerd/snapshots"
|
||||
"github.com/containerd/containerd/snapshots/storage"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
@ -34,7 +34,7 @@ type snapshotter struct {
|
||||
|
||||
// NewSnapshotter returns a Snapshotter which copies layers on the underlying
|
||||
// file system. A metadata file is stored under the root.
|
||||
func NewSnapshotter(root string) (snapshot.Snapshotter, error) {
|
||||
func NewSnapshotter(root string) (snapshots.Snapshotter, error) {
|
||||
if err := os.MkdirAll(root, 0700); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -58,68 +58,68 @@ func NewSnapshotter(root string) (snapshot.Snapshotter, error) {
|
||||
//
|
||||
// Should be used for parent resolution, existence checks and to discern
|
||||
// the kind of snapshot.
|
||||
func (o *snapshotter) Stat(ctx context.Context, key string) (snapshot.Info, error) {
|
||||
func (o *snapshotter) Stat(ctx context.Context, key string) (snapshots.Info, error) {
|
||||
ctx, t, err := o.ms.TransactionContext(ctx, false)
|
||||
if err != nil {
|
||||
return snapshot.Info{}, err
|
||||
return snapshots.Info{}, err
|
||||
}
|
||||
defer t.Rollback()
|
||||
_, info, _, err := storage.GetInfo(ctx, key)
|
||||
if err != nil {
|
||||
return snapshot.Info{}, err
|
||||
return snapshots.Info{}, err
|
||||
}
|
||||
|
||||
return info, nil
|
||||
}
|
||||
|
||||
func (o *snapshotter) Update(ctx context.Context, info snapshot.Info, fieldpaths ...string) (snapshot.Info, error) {
|
||||
func (o *snapshotter) Update(ctx context.Context, info snapshots.Info, fieldpaths ...string) (snapshots.Info, error) {
|
||||
ctx, t, err := o.ms.TransactionContext(ctx, true)
|
||||
if err != nil {
|
||||
return snapshot.Info{}, err
|
||||
return snapshots.Info{}, err
|
||||
}
|
||||
|
||||
info, err = storage.UpdateInfo(ctx, info, fieldpaths...)
|
||||
if err != nil {
|
||||
t.Rollback()
|
||||
return snapshot.Info{}, err
|
||||
return snapshots.Info{}, err
|
||||
}
|
||||
|
||||
if err := t.Commit(); err != nil {
|
||||
return snapshot.Info{}, err
|
||||
return snapshots.Info{}, err
|
||||
}
|
||||
|
||||
return info, nil
|
||||
}
|
||||
|
||||
func (o *snapshotter) Usage(ctx context.Context, key string) (snapshot.Usage, error) {
|
||||
func (o *snapshotter) Usage(ctx context.Context, key string) (snapshots.Usage, error) {
|
||||
ctx, t, err := o.ms.TransactionContext(ctx, false)
|
||||
if err != nil {
|
||||
return snapshot.Usage{}, err
|
||||
return snapshots.Usage{}, err
|
||||
}
|
||||
defer t.Rollback()
|
||||
|
||||
id, info, usage, err := storage.GetInfo(ctx, key)
|
||||
if err != nil {
|
||||
return snapshot.Usage{}, err
|
||||
return snapshots.Usage{}, err
|
||||
}
|
||||
|
||||
if info.Kind == snapshot.KindActive {
|
||||
if info.Kind == snapshots.KindActive {
|
||||
du, err := fs.DiskUsage(o.getSnapshotDir(id))
|
||||
if err != nil {
|
||||
return snapshot.Usage{}, err
|
||||
return snapshots.Usage{}, err
|
||||
}
|
||||
usage = snapshot.Usage(du)
|
||||
usage = snapshots.Usage(du)
|
||||
}
|
||||
|
||||
return usage, nil
|
||||
}
|
||||
|
||||
func (o *snapshotter) Prepare(ctx context.Context, key, parent string, opts ...snapshot.Opt) ([]mount.Mount, error) {
|
||||
return o.createSnapshot(ctx, snapshot.KindActive, key, parent, opts)
|
||||
func (o *snapshotter) Prepare(ctx context.Context, key, parent string, opts ...snapshots.Opt) ([]mount.Mount, error) {
|
||||
return o.createSnapshot(ctx, snapshots.KindActive, key, parent, opts)
|
||||
}
|
||||
|
||||
func (o *snapshotter) View(ctx context.Context, key, parent string, opts ...snapshot.Opt) ([]mount.Mount, error) {
|
||||
return o.createSnapshot(ctx, snapshot.KindView, key, parent, opts)
|
||||
func (o *snapshotter) View(ctx context.Context, key, parent string, opts ...snapshots.Opt) ([]mount.Mount, error) {
|
||||
return o.createSnapshot(ctx, snapshots.KindView, key, parent, opts)
|
||||
}
|
||||
|
||||
// Mounts returns the mounts for the transaction identified by key. Can be
|
||||
@ -139,7 +139,7 @@ func (o *snapshotter) Mounts(ctx context.Context, key string) ([]mount.Mount, er
|
||||
return o.mounts(s), nil
|
||||
}
|
||||
|
||||
func (o *snapshotter) Commit(ctx context.Context, name, key string, opts ...snapshot.Opt) error {
|
||||
func (o *snapshotter) Commit(ctx context.Context, name, key string, opts ...snapshots.Opt) error {
|
||||
ctx, t, err := o.ms.TransactionContext(ctx, true)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -155,7 +155,7 @@ func (o *snapshotter) Commit(ctx context.Context, name, key string, opts ...snap
|
||||
return err
|
||||
}
|
||||
|
||||
if _, err := storage.CommitActive(ctx, key, name, snapshot.Usage(usage), opts...); err != nil {
|
||||
if _, err := storage.CommitActive(ctx, key, name, snapshots.Usage(usage), opts...); err != nil {
|
||||
if rerr := t.Rollback(); rerr != nil {
|
||||
log.G(ctx).WithError(rerr).Warn("Failure rolling back transaction")
|
||||
}
|
||||
@ -215,7 +215,7 @@ func (o *snapshotter) Remove(ctx context.Context, key string) (err error) {
|
||||
}
|
||||
|
||||
// Walk the committed snapshots.
|
||||
func (o *snapshotter) Walk(ctx context.Context, fn func(context.Context, snapshot.Info) error) error {
|
||||
func (o *snapshotter) Walk(ctx context.Context, fn func(context.Context, snapshots.Info) error) error {
|
||||
ctx, t, err := o.ms.TransactionContext(ctx, false)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -224,13 +224,13 @@ func (o *snapshotter) Walk(ctx context.Context, fn func(context.Context, snapsho
|
||||
return storage.WalkInfo(ctx, fn)
|
||||
}
|
||||
|
||||
func (o *snapshotter) createSnapshot(ctx context.Context, kind snapshot.Kind, key, parent string, opts []snapshot.Opt) ([]mount.Mount, error) {
|
||||
func (o *snapshotter) createSnapshot(ctx context.Context, kind snapshots.Kind, key, parent string, opts []snapshots.Opt) ([]mount.Mount, error) {
|
||||
var (
|
||||
err error
|
||||
path, td string
|
||||
)
|
||||
|
||||
if kind == snapshot.KindActive || parent == "" {
|
||||
if kind == snapshots.KindActive || parent == "" {
|
||||
td, err = ioutil.TempDir(filepath.Join(o.root, "snapshots"), "new-")
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to create temp dir")
|
||||
@ -299,13 +299,13 @@ func (o *snapshotter) mounts(s storage.Snapshot) []mount.Mount {
|
||||
source string
|
||||
)
|
||||
|
||||
if s.Kind == snapshot.KindView {
|
||||
if s.Kind == snapshots.KindView {
|
||||
roFlag = "ro"
|
||||
} else {
|
||||
roFlag = "rw"
|
||||
}
|
||||
|
||||
if len(s.ParentIDs) == 0 || s.Kind == snapshot.KindActive {
|
||||
if len(s.ParentIDs) == 0 || s.Kind == snapshots.KindActive {
|
||||
source = o.getSnapshotDir(s.ID)
|
||||
} else {
|
||||
source = o.getSnapshotDir(s.ParentIDs[0])
|
@ -5,12 +5,12 @@ import (
|
||||
"runtime"
|
||||
"testing"
|
||||
|
||||
"github.com/containerd/containerd/snapshot"
|
||||
"github.com/containerd/containerd/snapshot/testsuite"
|
||||
"github.com/containerd/containerd/snapshots"
|
||||
"github.com/containerd/containerd/snapshots/testsuite"
|
||||
"github.com/containerd/containerd/testutil"
|
||||
)
|
||||
|
||||
func newSnapshotter(ctx context.Context, root string) (snapshot.Snapshotter, func() error, error) {
|
||||
func newSnapshotter(ctx context.Context, root string) (snapshots.Snapshotter, func() error, error) {
|
||||
snapshotter, err := NewSnapshotter(root)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
@ -16,8 +16,8 @@ import (
|
||||
"github.com/containerd/containerd/mount"
|
||||
"github.com/containerd/containerd/platforms"
|
||||
"github.com/containerd/containerd/plugin"
|
||||
"github.com/containerd/containerd/snapshot"
|
||||
"github.com/containerd/containerd/snapshot/storage"
|
||||
"github.com/containerd/containerd/snapshots"
|
||||
"github.com/containerd/containerd/snapshots/storage"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
@ -41,7 +41,7 @@ type snapshotter struct {
|
||||
// NewSnapshotter returns a Snapshotter which uses overlayfs. The overlayfs
|
||||
// diffs are stored under the provided root. A metadata file is stored under
|
||||
// the root.
|
||||
func NewSnapshotter(root string) (snapshot.Snapshotter, error) {
|
||||
func NewSnapshotter(root string) (snapshots.Snapshotter, error) {
|
||||
if err := os.MkdirAll(root, 0700); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -72,34 +72,34 @@ func NewSnapshotter(root string) (snapshot.Snapshotter, error) {
|
||||
//
|
||||
// Should be used for parent resolution, existence checks and to discern
|
||||
// the kind of snapshot.
|
||||
func (o *snapshotter) Stat(ctx context.Context, key string) (snapshot.Info, error) {
|
||||
func (o *snapshotter) Stat(ctx context.Context, key string) (snapshots.Info, error) {
|
||||
ctx, t, err := o.ms.TransactionContext(ctx, false)
|
||||
if err != nil {
|
||||
return snapshot.Info{}, err
|
||||
return snapshots.Info{}, err
|
||||
}
|
||||
defer t.Rollback()
|
||||
_, info, _, err := storage.GetInfo(ctx, key)
|
||||
if err != nil {
|
||||
return snapshot.Info{}, err
|
||||
return snapshots.Info{}, err
|
||||
}
|
||||
|
||||
return info, nil
|
||||
}
|
||||
|
||||
func (o *snapshotter) Update(ctx context.Context, info snapshot.Info, fieldpaths ...string) (snapshot.Info, error) {
|
||||
func (o *snapshotter) Update(ctx context.Context, info snapshots.Info, fieldpaths ...string) (snapshots.Info, error) {
|
||||
ctx, t, err := o.ms.TransactionContext(ctx, true)
|
||||
if err != nil {
|
||||
return snapshot.Info{}, err
|
||||
return snapshots.Info{}, err
|
||||
}
|
||||
|
||||
info, err = storage.UpdateInfo(ctx, info, fieldpaths...)
|
||||
if err != nil {
|
||||
t.Rollback()
|
||||
return snapshot.Info{}, err
|
||||
return snapshots.Info{}, err
|
||||
}
|
||||
|
||||
if err := t.Commit(); err != nil {
|
||||
return snapshot.Info{}, err
|
||||
return snapshots.Info{}, err
|
||||
}
|
||||
|
||||
return info, nil
|
||||
@ -111,39 +111,39 @@ func (o *snapshotter) Update(ctx context.Context, info snapshot.Info, fieldpaths
|
||||
// "upper") directory and may take some time.
|
||||
//
|
||||
// For committed snapshots, the value is returned from the metadata database.
|
||||
func (o *snapshotter) Usage(ctx context.Context, key string) (snapshot.Usage, error) {
|
||||
func (o *snapshotter) Usage(ctx context.Context, key string) (snapshots.Usage, error) {
|
||||
ctx, t, err := o.ms.TransactionContext(ctx, false)
|
||||
if err != nil {
|
||||
return snapshot.Usage{}, err
|
||||
return snapshots.Usage{}, err
|
||||
}
|
||||
id, info, usage, err := storage.GetInfo(ctx, key)
|
||||
t.Rollback() // transaction no longer needed at this point.
|
||||
|
||||
if err != nil {
|
||||
return snapshot.Usage{}, err
|
||||
return snapshots.Usage{}, err
|
||||
}
|
||||
|
||||
upperPath := o.upperPath(id)
|
||||
|
||||
if info.Kind == snapshot.KindActive {
|
||||
if info.Kind == snapshots.KindActive {
|
||||
du, err := fs.DiskUsage(upperPath)
|
||||
if err != nil {
|
||||
// TODO(stevvooe): Consider not reporting an error in this case.
|
||||
return snapshot.Usage{}, err
|
||||
return snapshots.Usage{}, err
|
||||
}
|
||||
|
||||
usage = snapshot.Usage(du)
|
||||
usage = snapshots.Usage(du)
|
||||
}
|
||||
|
||||
return usage, nil
|
||||
}
|
||||
|
||||
func (o *snapshotter) Prepare(ctx context.Context, key, parent string, opts ...snapshot.Opt) ([]mount.Mount, error) {
|
||||
return o.createSnapshot(ctx, snapshot.KindActive, key, parent, opts)
|
||||
func (o *snapshotter) Prepare(ctx context.Context, key, parent string, opts ...snapshots.Opt) ([]mount.Mount, error) {
|
||||
return o.createSnapshot(ctx, snapshots.KindActive, key, parent, opts)
|
||||
}
|
||||
|
||||
func (o *snapshotter) View(ctx context.Context, key, parent string, opts ...snapshot.Opt) ([]mount.Mount, error) {
|
||||
return o.createSnapshot(ctx, snapshot.KindView, key, parent, opts)
|
||||
func (o *snapshotter) View(ctx context.Context, key, parent string, opts ...snapshots.Opt) ([]mount.Mount, error) {
|
||||
return o.createSnapshot(ctx, snapshots.KindView, key, parent, opts)
|
||||
}
|
||||
|
||||
// Mounts returns the mounts for the transaction identified by key. Can be
|
||||
@ -163,7 +163,7 @@ func (o *snapshotter) Mounts(ctx context.Context, key string) ([]mount.Mount, er
|
||||
return o.mounts(s), nil
|
||||
}
|
||||
|
||||
func (o *snapshotter) Commit(ctx context.Context, name, key string, opts ...snapshot.Opt) error {
|
||||
func (o *snapshotter) Commit(ctx context.Context, name, key string, opts ...snapshots.Opt) error {
|
||||
ctx, t, err := o.ms.TransactionContext(ctx, true)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -188,7 +188,7 @@ func (o *snapshotter) Commit(ctx context.Context, name, key string, opts ...snap
|
||||
return err
|
||||
}
|
||||
|
||||
if _, err = storage.CommitActive(ctx, key, name, snapshot.Usage(usage), opts...); err != nil {
|
||||
if _, err = storage.CommitActive(ctx, key, name, snapshots.Usage(usage), opts...); err != nil {
|
||||
return errors.Wrap(err, "failed to commit snapshot")
|
||||
}
|
||||
return t.Commit()
|
||||
@ -238,7 +238,7 @@ func (o *snapshotter) Remove(ctx context.Context, key string) (err error) {
|
||||
}
|
||||
|
||||
// Walk the committed snapshots.
|
||||
func (o *snapshotter) Walk(ctx context.Context, fn func(context.Context, snapshot.Info) error) error {
|
||||
func (o *snapshotter) Walk(ctx context.Context, fn func(context.Context, snapshots.Info) error) error {
|
||||
ctx, t, err := o.ms.TransactionContext(ctx, false)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -247,7 +247,7 @@ func (o *snapshotter) Walk(ctx context.Context, fn func(context.Context, snapsho
|
||||
return storage.WalkInfo(ctx, fn)
|
||||
}
|
||||
|
||||
func (o *snapshotter) createSnapshot(ctx context.Context, kind snapshot.Kind, key, parent string, opts []snapshot.Opt) ([]mount.Mount, error) {
|
||||
func (o *snapshotter) createSnapshot(ctx context.Context, kind snapshots.Kind, key, parent string, opts []snapshots.Opt) ([]mount.Mount, error) {
|
||||
var (
|
||||
path string
|
||||
snapshotDir = filepath.Join(o.root, "snapshots")
|
||||
@ -277,7 +277,7 @@ func (o *snapshotter) createSnapshot(ctx context.Context, kind snapshot.Kind, ke
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if kind == snapshot.KindActive {
|
||||
if kind == snapshots.KindActive {
|
||||
if err = os.MkdirAll(filepath.Join(td, "work"), 0711); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -336,7 +336,7 @@ func (o *snapshotter) mounts(s storage.Snapshot) []mount.Mount {
|
||||
// if we only have one layer/no parents then just return a bind mount as overlay
|
||||
// will not work
|
||||
roFlag := "rw"
|
||||
if s.Kind == snapshot.KindView {
|
||||
if s.Kind == snapshots.KindView {
|
||||
roFlag = "ro"
|
||||
}
|
||||
|
||||
@ -353,7 +353,7 @@ func (o *snapshotter) mounts(s storage.Snapshot) []mount.Mount {
|
||||
}
|
||||
var options []string
|
||||
|
||||
if s.Kind == snapshot.KindActive {
|
||||
if s.Kind == snapshots.KindActive {
|
||||
options = append(options,
|
||||
fmt.Sprintf("workdir=%s", o.workPath(s.ID)),
|
||||
fmt.Sprintf("upperdir=%s", o.upperPath(s.ID)),
|
@ -12,13 +12,13 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/containerd/containerd/mount"
|
||||
"github.com/containerd/containerd/snapshot"
|
||||
"github.com/containerd/containerd/snapshot/storage"
|
||||
"github.com/containerd/containerd/snapshot/testsuite"
|
||||
"github.com/containerd/containerd/snapshots"
|
||||
"github.com/containerd/containerd/snapshots/storage"
|
||||
"github.com/containerd/containerd/snapshots/testsuite"
|
||||
"github.com/containerd/containerd/testutil"
|
||||
)
|
||||
|
||||
func newSnapshotter(ctx context.Context, root string) (snapshot.Snapshotter, func() error, error) {
|
||||
func newSnapshotter(ctx context.Context, root string) (snapshots.Snapshotter, func() error, error) {
|
||||
snapshotter, err := NewSnapshotter(root)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
@ -150,7 +150,7 @@ func TestOverlayOverlayMount(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func getBasePath(ctx context.Context, sn snapshot.Snapshotter, root, key string) string {
|
||||
func getBasePath(ctx context.Context, sn snapshots.Snapshotter, root, key string) string {
|
||||
o := sn.(*snapshotter)
|
||||
ctx, t, err := o.ms.TransactionContext(ctx, false)
|
||||
if err != nil {
|
||||
@ -166,7 +166,7 @@ func getBasePath(ctx context.Context, sn snapshot.Snapshotter, root, key string)
|
||||
return filepath.Join(root, "snapshots", s.ID)
|
||||
}
|
||||
|
||||
func getParents(ctx context.Context, sn snapshot.Snapshotter, root, key string) []string {
|
||||
func getParents(ctx context.Context, sn snapshots.Snapshotter, root, key string) []string {
|
||||
o := sn.(*snapshotter)
|
||||
ctx, t, err := o.ms.TransactionContext(ctx, false)
|
||||
if err != nil {
|
@ -1,4 +1,4 @@
|
||||
package snapshot
|
||||
package snapshots
|
||||
|
||||
import (
|
||||
"context"
|
@ -10,7 +10,7 @@ import (
|
||||
"github.com/boltdb/bolt"
|
||||
"github.com/containerd/containerd/errdefs"
|
||||
"github.com/containerd/containerd/metadata/boltutil"
|
||||
"github.com/containerd/containerd/snapshot"
|
||||
"github.com/containerd/containerd/snapshots"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
@ -56,11 +56,11 @@ func getParentPrefix(b []byte) uint64 {
|
||||
|
||||
// GetInfo returns the snapshot Info directly from the metadata. Requires a
|
||||
// context with a storage transaction.
|
||||
func GetInfo(ctx context.Context, key string) (string, snapshot.Info, snapshot.Usage, error) {
|
||||
func GetInfo(ctx context.Context, key string) (string, snapshots.Info, snapshots.Usage, error) {
|
||||
var (
|
||||
id uint64
|
||||
su snapshot.Usage
|
||||
si = snapshot.Info{
|
||||
su snapshots.Usage
|
||||
si = snapshots.Info{
|
||||
Name: key,
|
||||
}
|
||||
)
|
||||
@ -69,15 +69,15 @@ func GetInfo(ctx context.Context, key string) (string, snapshot.Info, snapshot.U
|
||||
return readSnapshot(bkt, &id, &si)
|
||||
})
|
||||
if err != nil {
|
||||
return "", snapshot.Info{}, snapshot.Usage{}, err
|
||||
return "", snapshots.Info{}, snapshots.Usage{}, err
|
||||
}
|
||||
|
||||
return fmt.Sprintf("%d", id), si, su, nil
|
||||
}
|
||||
|
||||
// UpdateInfo updates an existing snapshot info's data
|
||||
func UpdateInfo(ctx context.Context, info snapshot.Info, fieldpaths ...string) (snapshot.Info, error) {
|
||||
updated := snapshot.Info{
|
||||
func UpdateInfo(ctx context.Context, info snapshots.Info, fieldpaths ...string) (snapshots.Info, error) {
|
||||
updated := snapshots.Info{
|
||||
Name: info.Name,
|
||||
}
|
||||
err := withBucket(ctx, func(ctx context.Context, bkt, pbkt *bolt.Bucket) error {
|
||||
@ -120,7 +120,7 @@ func UpdateInfo(ctx context.Context, info snapshot.Info, fieldpaths ...string) (
|
||||
return boltutil.WriteLabels(sbkt, updated.Labels)
|
||||
})
|
||||
if err != nil {
|
||||
return snapshot.Info{}, err
|
||||
return snapshots.Info{}, err
|
||||
}
|
||||
return updated, nil
|
||||
}
|
||||
@ -128,7 +128,7 @@ func UpdateInfo(ctx context.Context, info snapshot.Info, fieldpaths ...string) (
|
||||
// WalkInfo iterates through all metadata Info for the stored snapshots and
|
||||
// calls the provided function for each. Requires a context with a storage
|
||||
// transaction.
|
||||
func WalkInfo(ctx context.Context, fn func(context.Context, snapshot.Info) error) error {
|
||||
func WalkInfo(ctx context.Context, fn func(context.Context, snapshots.Info) error) error {
|
||||
return withBucket(ctx, func(ctx context.Context, bkt, pbkt *bolt.Bucket) error {
|
||||
return bkt.ForEach(func(k, v []byte) error {
|
||||
// skip non buckets
|
||||
@ -137,7 +137,7 @@ func WalkInfo(ctx context.Context, fn func(context.Context, snapshot.Info) error
|
||||
}
|
||||
var (
|
||||
sbkt = bkt.Bucket(k)
|
||||
si = snapshot.Info{
|
||||
si = snapshots.Info{
|
||||
Name: string(k),
|
||||
}
|
||||
)
|
||||
@ -162,7 +162,7 @@ func GetSnapshot(ctx context.Context, key string) (s Snapshot, err error) {
|
||||
s.ID = fmt.Sprintf("%d", readID(sbkt))
|
||||
s.Kind = readKind(sbkt)
|
||||
|
||||
if s.Kind != snapshot.KindActive && s.Kind != snapshot.KindView {
|
||||
if s.Kind != snapshots.KindActive && s.Kind != snapshots.KindView {
|
||||
return errors.Wrapf(errdefs.ErrFailedPrecondition, "requested snapshot %v not active or view", key)
|
||||
}
|
||||
|
||||
@ -187,13 +187,13 @@ func GetSnapshot(ctx context.Context, key string) (s Snapshot, err error) {
|
||||
}
|
||||
|
||||
// CreateSnapshot inserts a record for an active or view snapshot with the provided parent.
|
||||
func CreateSnapshot(ctx context.Context, kind snapshot.Kind, key, parent string, opts ...snapshot.Opt) (s Snapshot, err error) {
|
||||
func CreateSnapshot(ctx context.Context, kind snapshots.Kind, key, parent string, opts ...snapshots.Opt) (s Snapshot, err error) {
|
||||
switch kind {
|
||||
case snapshot.KindActive, snapshot.KindView:
|
||||
case snapshots.KindActive, snapshots.KindView:
|
||||
default:
|
||||
return Snapshot{}, errors.Wrapf(errdefs.ErrInvalidArgument, "snapshot type %v invalid; only snapshots of type Active or View can be created", kind)
|
||||
}
|
||||
var base snapshot.Info
|
||||
var base snapshots.Info
|
||||
for _, opt := range opts {
|
||||
if err := opt(&base); err != nil {
|
||||
return Snapshot{}, err
|
||||
@ -210,7 +210,7 @@ func CreateSnapshot(ctx context.Context, kind snapshot.Kind, key, parent string,
|
||||
return errors.Wrap(errdefs.ErrNotFound, "missing parent bucket")
|
||||
}
|
||||
|
||||
if readKind(spbkt) != snapshot.KindCommitted {
|
||||
if readKind(spbkt) != snapshots.KindCommitted {
|
||||
return errors.Wrap(errdefs.ErrInvalidArgument, "parent is not committed snapshot")
|
||||
}
|
||||
}
|
||||
@ -228,7 +228,7 @@ func CreateSnapshot(ctx context.Context, kind snapshot.Kind, key, parent string,
|
||||
}
|
||||
|
||||
t := time.Now().UTC()
|
||||
si := snapshot.Info{
|
||||
si := snapshots.Info{
|
||||
Parent: parent,
|
||||
Kind: kind,
|
||||
Labels: base.Labels,
|
||||
@ -268,10 +268,10 @@ func CreateSnapshot(ctx context.Context, kind snapshot.Kind, key, parent string,
|
||||
// Remove removes a snapshot from the metastore. The string identifier for the
|
||||
// snapshot is returned as well as the kind. The provided context must contain a
|
||||
// writable transaction.
|
||||
func Remove(ctx context.Context, key string) (string, snapshot.Kind, error) {
|
||||
func Remove(ctx context.Context, key string) (string, snapshots.Kind, error) {
|
||||
var (
|
||||
id uint64
|
||||
si snapshot.Info
|
||||
si snapshots.Info
|
||||
)
|
||||
|
||||
if err := withBucket(ctx, func(ctx context.Context, bkt, pbkt *bolt.Bucket) error {
|
||||
@ -320,10 +320,10 @@ func Remove(ctx context.Context, key string) (string, snapshot.Kind, error) {
|
||||
// lookup or removal. The returned string identifier for the committed snapshot
|
||||
// is the same identifier of the original active snapshot. The provided context
|
||||
// must contain a writable transaction.
|
||||
func CommitActive(ctx context.Context, key, name string, usage snapshot.Usage, opts ...snapshot.Opt) (string, error) {
|
||||
func CommitActive(ctx context.Context, key, name string, usage snapshots.Usage, opts ...snapshots.Opt) (string, error) {
|
||||
var (
|
||||
id uint64
|
||||
base snapshot.Info
|
||||
base snapshots.Info
|
||||
)
|
||||
for _, opt := range opts {
|
||||
if err := opt(&base); err != nil {
|
||||
@ -344,15 +344,15 @@ func CommitActive(ctx context.Context, key, name string, usage snapshot.Usage, o
|
||||
return errors.Wrap(errdefs.ErrNotFound, "failed to get active snapshot")
|
||||
}
|
||||
|
||||
var si snapshot.Info
|
||||
var si snapshots.Info
|
||||
if err := readSnapshot(sbkt, &id, &si); err != nil {
|
||||
return errors.Wrap(err, "failed to read snapshot")
|
||||
}
|
||||
|
||||
if si.Kind != snapshot.KindActive {
|
||||
if si.Kind != snapshots.KindActive {
|
||||
return errors.Wrapf(errdefs.ErrFailedPrecondition, "snapshot %v is not active", name)
|
||||
}
|
||||
si.Kind = snapshot.KindCommitted
|
||||
si.Kind = snapshots.KindCommitted
|
||||
si.Created = time.Now().UTC()
|
||||
si.Updated = si.Created
|
||||
|
||||
@ -460,10 +460,10 @@ func parents(bkt, pbkt *bolt.Bucket, parent uint64) (parents []string, err error
|
||||
}
|
||||
}
|
||||
|
||||
func readKind(bkt *bolt.Bucket) (k snapshot.Kind) {
|
||||
func readKind(bkt *bolt.Bucket) (k snapshots.Kind) {
|
||||
kind := bkt.Get(bucketKeyKind)
|
||||
if len(kind) == 1 {
|
||||
k = snapshot.Kind(kind[0])
|
||||
k = snapshots.Kind(kind[0])
|
||||
}
|
||||
return
|
||||
}
|
||||
@ -473,7 +473,7 @@ func readID(bkt *bolt.Bucket) uint64 {
|
||||
return id
|
||||
}
|
||||
|
||||
func readSnapshot(bkt *bolt.Bucket, id *uint64, si *snapshot.Info) error {
|
||||
func readSnapshot(bkt *bolt.Bucket, id *uint64, si *snapshots.Info) error {
|
||||
if id != nil {
|
||||
*id = readID(bkt)
|
||||
}
|
||||
@ -495,7 +495,7 @@ func readSnapshot(bkt *bolt.Bucket, id *uint64, si *snapshot.Info) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func putSnapshot(bkt *bolt.Bucket, id uint64, si snapshot.Info) error {
|
||||
func putSnapshot(bkt *bolt.Bucket, id uint64, si snapshots.Info) error {
|
||||
idEncoded, err := encodeID(id)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -519,12 +519,12 @@ func putSnapshot(bkt *bolt.Bucket, id uint64, si snapshot.Info) error {
|
||||
return boltutil.WriteLabels(bkt, si.Labels)
|
||||
}
|
||||
|
||||
func getUsage(bkt *bolt.Bucket, usage *snapshot.Usage) {
|
||||
func getUsage(bkt *bolt.Bucket, usage *snapshots.Usage) {
|
||||
usage.Inodes, _ = binary.Varint(bkt.Get(bucketKeyInodes))
|
||||
usage.Size, _ = binary.Varint(bkt.Get(bucketKeySize))
|
||||
}
|
||||
|
||||
func putUsage(bkt *bolt.Bucket, usage snapshot.Usage) error {
|
||||
func putUsage(bkt *bolt.Bucket, usage snapshots.Usage) error {
|
||||
for _, v := range []struct {
|
||||
key []byte
|
||||
value int64
|
@ -10,7 +10,7 @@ import (
|
||||
"sync"
|
||||
|
||||
"github.com/boltdb/bolt"
|
||||
"github.com/containerd/containerd/snapshot"
|
||||
"github.com/containerd/containerd/snapshots"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
@ -35,7 +35,7 @@ type Transactor interface {
|
||||
// the last index. The last index should always be considered the active
|
||||
// snapshots immediate parent.
|
||||
type Snapshot struct {
|
||||
Kind snapshot.Kind
|
||||
Kind snapshots.Kind
|
||||
ID string
|
||||
ParentIDs []string
|
||||
}
|
@ -7,7 +7,7 @@ import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/containerd/containerd/snapshot"
|
||||
"github.com/containerd/containerd/snapshots"
|
||||
)
|
||||
|
||||
// Benchmarks returns a benchmark suite using the provided metadata store
|
||||
@ -106,14 +106,14 @@ func openCloseReadonly(b *testing.B, name string, metaFn metaFactory) func(b *te
|
||||
}
|
||||
|
||||
func createActiveFromBase(ctx context.Context, ms *MetaStore, active, base string) error {
|
||||
if _, err := CreateSnapshot(ctx, snapshot.KindActive, "bottom", ""); err != nil {
|
||||
if _, err := CreateSnapshot(ctx, snapshots.KindActive, "bottom", ""); err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err := CommitActive(ctx, "bottom", base, snapshot.Usage{}); err != nil {
|
||||
if _, err := CommitActive(ctx, "bottom", base, snapshots.Usage{}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err := CreateSnapshot(ctx, snapshot.KindActive, active, base)
|
||||
_, err := CreateSnapshot(ctx, snapshots.KindActive, active, base)
|
||||
return err
|
||||
}
|
||||
|
||||
@ -135,7 +135,7 @@ func statCommittedBenchmark(ctx context.Context, b *testing.B, ms *MetaStore) {
|
||||
if err := createActiveFromBase(ctx, ms, "active", "base"); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
if _, err := CommitActive(ctx, "active", "committed", snapshot.Usage{}); err != nil {
|
||||
if _, err := CommitActive(ctx, "active", "committed", snapshots.Usage{}); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
|
||||
@ -150,7 +150,7 @@ func statCommittedBenchmark(ctx context.Context, b *testing.B, ms *MetaStore) {
|
||||
|
||||
func createActiveBenchmark(ctx context.Context, b *testing.B, ms *MetaStore) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
if _, err := CreateSnapshot(ctx, snapshot.KindActive, "active", ""); err != nil {
|
||||
if _, err := CreateSnapshot(ctx, snapshots.KindActive, "active", ""); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
b.StopTimer()
|
||||
@ -164,7 +164,7 @@ func createActiveBenchmark(ctx context.Context, b *testing.B, ms *MetaStore) {
|
||||
func removeBenchmark(ctx context.Context, b *testing.B, ms *MetaStore) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
b.StopTimer()
|
||||
if _, err := CreateSnapshot(ctx, snapshot.KindActive, "active", ""); err != nil {
|
||||
if _, err := CreateSnapshot(ctx, snapshots.KindActive, "active", ""); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
b.StartTimer()
|
||||
@ -177,11 +177,11 @@ func removeBenchmark(ctx context.Context, b *testing.B, ms *MetaStore) {
|
||||
func commitBenchmark(ctx context.Context, b *testing.B, ms *MetaStore) {
|
||||
b.StopTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
if _, err := CreateSnapshot(ctx, snapshot.KindActive, "active", ""); err != nil {
|
||||
if _, err := CreateSnapshot(ctx, snapshots.KindActive, "active", ""); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
b.StartTimer()
|
||||
if _, err := CommitActive(ctx, "active", "committed", snapshot.Usage{}); err != nil {
|
||||
if _, err := CommitActive(ctx, "active", "committed", snapshots.Usage{}); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
b.StopTimer()
|
||||
@ -194,17 +194,17 @@ func commitBenchmark(ctx context.Context, b *testing.B, ms *MetaStore) {
|
||||
func getActiveBenchmark(ctx context.Context, b *testing.B, ms *MetaStore) {
|
||||
var base string
|
||||
for i := 1; i <= 10; i++ {
|
||||
if _, err := CreateSnapshot(ctx, snapshot.KindActive, "tmp", base); err != nil {
|
||||
if _, err := CreateSnapshot(ctx, snapshots.KindActive, "tmp", base); err != nil {
|
||||
b.Fatalf("create active failed: %+v", err)
|
||||
}
|
||||
base = fmt.Sprintf("base-%d", i)
|
||||
if _, err := CommitActive(ctx, "tmp", base, snapshot.Usage{}); err != nil {
|
||||
if _, err := CommitActive(ctx, "tmp", base, snapshots.Usage{}); err != nil {
|
||||
b.Fatalf("commit failed: %+v", err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if _, err := CreateSnapshot(ctx, snapshot.KindActive, "active", base); err != nil {
|
||||
if _, err := CreateSnapshot(ctx, snapshots.KindActive, "active", base); err != nil {
|
||||
b.Fatalf("create active failed: %+v", err)
|
||||
}
|
||||
b.ResetTimer()
|
@ -9,7 +9,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/containerd/containerd/errdefs"
|
||||
"github.com/containerd/containerd/snapshot"
|
||||
"github.com/containerd/containerd/snapshots"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
@ -129,71 +129,71 @@ func inWriteTransaction(fn testFunc) testFunc {
|
||||
// - "active-4": readonly active without parent"
|
||||
// - "active-5": readonly active with parent "committed-2"
|
||||
func basePopulate(ctx context.Context, ms *MetaStore) error {
|
||||
if _, err := CreateSnapshot(ctx, snapshot.KindActive, "committed-tmp-1", ""); err != nil {
|
||||
if _, err := CreateSnapshot(ctx, snapshots.KindActive, "committed-tmp-1", ""); err != nil {
|
||||
return errors.Wrap(err, "failed to create active")
|
||||
}
|
||||
if _, err := CommitActive(ctx, "committed-tmp-1", "committed-1", snapshot.Usage{Size: 1}); err != nil {
|
||||
if _, err := CommitActive(ctx, "committed-tmp-1", "committed-1", snapshots.Usage{Size: 1}); err != nil {
|
||||
return errors.Wrap(err, "failed to create active")
|
||||
}
|
||||
if _, err := CreateSnapshot(ctx, snapshot.KindActive, "committed-tmp-2", "committed-1"); err != nil {
|
||||
if _, err := CreateSnapshot(ctx, snapshots.KindActive, "committed-tmp-2", "committed-1"); err != nil {
|
||||
return errors.Wrap(err, "failed to create active")
|
||||
}
|
||||
if _, err := CommitActive(ctx, "committed-tmp-2", "committed-2", snapshot.Usage{Size: 2}); err != nil {
|
||||
if _, err := CommitActive(ctx, "committed-tmp-2", "committed-2", snapshots.Usage{Size: 2}); err != nil {
|
||||
return errors.Wrap(err, "failed to create active")
|
||||
}
|
||||
if _, err := CreateSnapshot(ctx, snapshot.KindActive, "active-1", ""); err != nil {
|
||||
if _, err := CreateSnapshot(ctx, snapshots.KindActive, "active-1", ""); err != nil {
|
||||
return errors.Wrap(err, "failed to create active")
|
||||
}
|
||||
if _, err := CreateSnapshot(ctx, snapshot.KindActive, "active-2", "committed-1"); err != nil {
|
||||
if _, err := CreateSnapshot(ctx, snapshots.KindActive, "active-2", "committed-1"); err != nil {
|
||||
return errors.Wrap(err, "failed to create active")
|
||||
}
|
||||
if _, err := CreateSnapshot(ctx, snapshot.KindActive, "active-3", "committed-2"); err != nil {
|
||||
if _, err := CreateSnapshot(ctx, snapshots.KindActive, "active-3", "committed-2"); err != nil {
|
||||
return errors.Wrap(err, "failed to create active")
|
||||
}
|
||||
if _, err := CreateSnapshot(ctx, snapshot.KindView, "view-1", ""); err != nil {
|
||||
if _, err := CreateSnapshot(ctx, snapshots.KindView, "view-1", ""); err != nil {
|
||||
return errors.Wrap(err, "failed to create active")
|
||||
}
|
||||
if _, err := CreateSnapshot(ctx, snapshot.KindView, "view-2", "committed-2"); err != nil {
|
||||
if _, err := CreateSnapshot(ctx, snapshots.KindView, "view-2", "committed-2"); err != nil {
|
||||
return errors.Wrap(err, "failed to create active")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
var baseInfo = map[string]snapshot.Info{
|
||||
var baseInfo = map[string]snapshots.Info{
|
||||
"committed-1": {
|
||||
Name: "committed-1",
|
||||
Parent: "",
|
||||
Kind: snapshot.KindCommitted,
|
||||
Kind: snapshots.KindCommitted,
|
||||
},
|
||||
"committed-2": {
|
||||
Name: "committed-2",
|
||||
Parent: "committed-1",
|
||||
Kind: snapshot.KindCommitted,
|
||||
Kind: snapshots.KindCommitted,
|
||||
},
|
||||
"active-1": {
|
||||
Name: "active-1",
|
||||
Parent: "",
|
||||
Kind: snapshot.KindActive,
|
||||
Kind: snapshots.KindActive,
|
||||
},
|
||||
"active-2": {
|
||||
Name: "active-2",
|
||||
Parent: "committed-1",
|
||||
Kind: snapshot.KindActive,
|
||||
Kind: snapshots.KindActive,
|
||||
},
|
||||
"active-3": {
|
||||
Name: "active-3",
|
||||
Parent: "committed-2",
|
||||
Kind: snapshot.KindActive,
|
||||
Kind: snapshots.KindActive,
|
||||
},
|
||||
"view-1": {
|
||||
Name: "view-1",
|
||||
Parent: "",
|
||||
Kind: snapshot.KindView,
|
||||
Kind: snapshots.KindView,
|
||||
},
|
||||
"view-2": {
|
||||
Name: "view-2",
|
||||
Parent: "committed-2",
|
||||
Kind: snapshot.KindView,
|
||||
Kind: snapshots.KindView,
|
||||
},
|
||||
}
|
||||
|
||||
@ -252,8 +252,8 @@ func testGetInfoNotExist(ctx context.Context, t *testing.T, ms *MetaStore) {
|
||||
}
|
||||
|
||||
func testWalk(ctx context.Context, t *testing.T, ms *MetaStore) {
|
||||
found := map[string]snapshot.Info{}
|
||||
err := WalkInfo(ctx, func(ctx context.Context, info snapshot.Info) error {
|
||||
found := map[string]snapshots.Info{}
|
||||
err := WalkInfo(ctx, func(ctx context.Context, info snapshots.Info) error {
|
||||
if _, ok := found[info.Name]; ok {
|
||||
return errors.Errorf("entry already encountered")
|
||||
}
|
||||
@ -272,35 +272,35 @@ func testWalk(ctx context.Context, t *testing.T, ms *MetaStore) {
|
||||
func testGetSnapshot(ctx context.Context, t *testing.T, ms *MetaStore) {
|
||||
snapshotMap := map[string]Snapshot{}
|
||||
populate := func(ctx context.Context, ms *MetaStore) error {
|
||||
if _, err := CreateSnapshot(ctx, snapshot.KindActive, "committed-tmp-1", ""); err != nil {
|
||||
if _, err := CreateSnapshot(ctx, snapshots.KindActive, "committed-tmp-1", ""); err != nil {
|
||||
return errors.Wrap(err, "failed to create active")
|
||||
}
|
||||
if _, err := CommitActive(ctx, "committed-tmp-1", "committed-1", snapshot.Usage{}); err != nil {
|
||||
if _, err := CommitActive(ctx, "committed-tmp-1", "committed-1", snapshots.Usage{}); err != nil {
|
||||
return errors.Wrap(err, "failed to create active")
|
||||
}
|
||||
|
||||
for _, opts := range []struct {
|
||||
Kind snapshot.Kind
|
||||
Kind snapshots.Kind
|
||||
Name string
|
||||
Parent string
|
||||
}{
|
||||
{
|
||||
Name: "active-1",
|
||||
Kind: snapshot.KindActive,
|
||||
Kind: snapshots.KindActive,
|
||||
},
|
||||
{
|
||||
Name: "active-2",
|
||||
Parent: "committed-1",
|
||||
Kind: snapshot.KindActive,
|
||||
Kind: snapshots.KindActive,
|
||||
},
|
||||
{
|
||||
Name: "view-1",
|
||||
Kind: snapshot.KindView,
|
||||
Kind: snapshots.KindView,
|
||||
},
|
||||
{
|
||||
Name: "view-2",
|
||||
Parent: "committed-1",
|
||||
Kind: snapshot.KindView,
|
||||
Kind: snapshots.KindView,
|
||||
},
|
||||
} {
|
||||
active, err := CreateSnapshot(ctx, opts.Kind, opts.Name, opts.Parent)
|
||||
@ -336,26 +336,26 @@ func testGetSnapshotNotExist(ctx context.Context, t *testing.T, ms *MetaStore) {
|
||||
}
|
||||
|
||||
func testCreateActive(ctx context.Context, t *testing.T, ms *MetaStore) {
|
||||
a1, err := CreateSnapshot(ctx, snapshot.KindActive, "active-1", "")
|
||||
a1, err := CreateSnapshot(ctx, snapshots.KindActive, "active-1", "")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if a1.Kind != snapshot.KindActive {
|
||||
if a1.Kind != snapshots.KindActive {
|
||||
t.Fatal("Expected writable active")
|
||||
}
|
||||
|
||||
a2, err := CreateSnapshot(ctx, snapshot.KindView, "view-1", "")
|
||||
a2, err := CreateSnapshot(ctx, snapshots.KindView, "view-1", "")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if a2.ID == a1.ID {
|
||||
t.Fatal("Returned active identifiers must be unique")
|
||||
}
|
||||
if a2.Kind != snapshot.KindView {
|
||||
if a2.Kind != snapshots.KindView {
|
||||
t.Fatal("Expected a view")
|
||||
}
|
||||
|
||||
commitID, err := CommitActive(ctx, "active-1", "committed-1", snapshot.Usage{})
|
||||
commitID, err := CommitActive(ctx, "active-1", "committed-1", snapshots.Usage{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -363,7 +363,7 @@ func testCreateActive(ctx context.Context, t *testing.T, ms *MetaStore) {
|
||||
t.Fatal("Snapshot identifier must not change on commit")
|
||||
}
|
||||
|
||||
a3, err := CreateSnapshot(ctx, snapshot.KindActive, "active-3", "committed-1")
|
||||
a3, err := CreateSnapshot(ctx, snapshots.KindActive, "active-3", "committed-1")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -376,11 +376,11 @@ func testCreateActive(ctx context.Context, t *testing.T, ms *MetaStore) {
|
||||
if a3.ParentIDs[0] != commitID {
|
||||
t.Fatal("Expected active parent to be same as commit ID")
|
||||
}
|
||||
if a3.Kind != snapshot.KindActive {
|
||||
if a3.Kind != snapshots.KindActive {
|
||||
t.Fatal("Expected writable active")
|
||||
}
|
||||
|
||||
a4, err := CreateSnapshot(ctx, snapshot.KindView, "view-2", "committed-1")
|
||||
a4, err := CreateSnapshot(ctx, snapshots.KindView, "view-2", "committed-1")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -393,7 +393,7 @@ func testCreateActive(ctx context.Context, t *testing.T, ms *MetaStore) {
|
||||
if a3.ParentIDs[0] != commitID {
|
||||
t.Fatal("Expected active parent to be same as commit ID")
|
||||
}
|
||||
if a4.Kind != snapshot.KindView {
|
||||
if a4.Kind != snapshots.KindView {
|
||||
t.Fatal("Expected a view")
|
||||
}
|
||||
}
|
||||
@ -402,14 +402,14 @@ func testCreateActiveExist(ctx context.Context, t *testing.T, ms *MetaStore) {
|
||||
if err := basePopulate(ctx, ms); err != nil {
|
||||
t.Fatalf("Populate failed: %+v", err)
|
||||
}
|
||||
_, err := CreateSnapshot(ctx, snapshot.KindActive, "active-1", "")
|
||||
_, err := CreateSnapshot(ctx, snapshots.KindActive, "active-1", "")
|
||||
assertExist(t, err)
|
||||
_, err = CreateSnapshot(ctx, snapshot.KindActive, "committed-1", "")
|
||||
_, err = CreateSnapshot(ctx, snapshots.KindActive, "committed-1", "")
|
||||
assertExist(t, err)
|
||||
}
|
||||
|
||||
func testCreateActiveNotExist(ctx context.Context, t *testing.T, ms *MetaStore) {
|
||||
_, err := CreateSnapshot(ctx, snapshot.KindActive, "active-1", "does-not-exist")
|
||||
_, err := CreateSnapshot(ctx, snapshots.KindActive, "active-1", "does-not-exist")
|
||||
assertNotExist(t, err)
|
||||
}
|
||||
|
||||
@ -417,20 +417,20 @@ func testCreateActiveFromActive(ctx context.Context, t *testing.T, ms *MetaStore
|
||||
if err := basePopulate(ctx, ms); err != nil {
|
||||
t.Fatalf("Populate failed: %+v", err)
|
||||
}
|
||||
_, err := CreateSnapshot(ctx, snapshot.KindActive, "active-new", "active-1")
|
||||
_, err := CreateSnapshot(ctx, snapshots.KindActive, "active-new", "active-1")
|
||||
assertNotCommitted(t, err)
|
||||
}
|
||||
|
||||
func testCommit(ctx context.Context, t *testing.T, ms *MetaStore) {
|
||||
a1, err := CreateSnapshot(ctx, snapshot.KindActive, "active-1", "")
|
||||
a1, err := CreateSnapshot(ctx, snapshots.KindActive, "active-1", "")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if a1.Kind != snapshot.KindActive {
|
||||
if a1.Kind != snapshots.KindActive {
|
||||
t.Fatal("Expected writable active")
|
||||
}
|
||||
|
||||
commitID, err := CommitActive(ctx, "active-1", "committed-1", snapshot.Usage{})
|
||||
commitID, err := CommitActive(ctx, "active-1", "committed-1", snapshots.Usage{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -448,7 +448,7 @@ func testCommitExist(ctx context.Context, t *testing.T, ms *MetaStore) {
|
||||
if err := basePopulate(ctx, ms); err != nil {
|
||||
t.Fatalf("Populate failed: %+v", err)
|
||||
}
|
||||
_, err := CommitActive(ctx, "active-1", "committed-1", snapshot.Usage{})
|
||||
_, err := CommitActive(ctx, "active-1", "committed-1", snapshots.Usage{})
|
||||
assertExist(t, err)
|
||||
}
|
||||
|
||||
@ -456,7 +456,7 @@ func testCommitCommitted(ctx context.Context, t *testing.T, ms *MetaStore) {
|
||||
if err := basePopulate(ctx, ms); err != nil {
|
||||
t.Fatalf("Populate failed: %+v", err)
|
||||
}
|
||||
_, err := CommitActive(ctx, "committed-1", "committed-3", snapshot.Usage{})
|
||||
_, err := CommitActive(ctx, "committed-1", "committed-3", snapshots.Usage{})
|
||||
assertNotActive(t, err)
|
||||
}
|
||||
|
||||
@ -464,19 +464,19 @@ func testCommitViewFails(ctx context.Context, t *testing.T, ms *MetaStore) {
|
||||
if err := basePopulate(ctx, ms); err != nil {
|
||||
t.Fatalf("Populate failed: %+v", err)
|
||||
}
|
||||
_, err := CommitActive(ctx, "view-1", "committed-3", snapshot.Usage{})
|
||||
_, err := CommitActive(ctx, "view-1", "committed-3", snapshots.Usage{})
|
||||
if err == nil {
|
||||
t.Fatal("Expected error committing readonly active")
|
||||
}
|
||||
}
|
||||
|
||||
func testRemove(ctx context.Context, t *testing.T, ms *MetaStore) {
|
||||
a1, err := CreateSnapshot(ctx, snapshot.KindActive, "active-1", "")
|
||||
a1, err := CreateSnapshot(ctx, snapshots.KindActive, "active-1", "")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
commitID, err := CommitActive(ctx, "active-1", "committed-1", snapshot.Usage{})
|
||||
commitID, err := CommitActive(ctx, "active-1", "committed-1", snapshots.Usage{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -484,12 +484,12 @@ func testRemove(ctx context.Context, t *testing.T, ms *MetaStore) {
|
||||
t.Fatal("Snapshot identifier must not change on commit")
|
||||
}
|
||||
|
||||
a2, err := CreateSnapshot(ctx, snapshot.KindView, "view-1", "committed-1")
|
||||
a2, err := CreateSnapshot(ctx, snapshots.KindView, "view-1", "committed-1")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
a3, err := CreateSnapshot(ctx, snapshot.KindView, "view-2", "committed-1")
|
||||
a3, err := CreateSnapshot(ctx, snapshots.KindView, "view-2", "committed-1")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -504,7 +504,7 @@ func testRemove(ctx context.Context, t *testing.T, ms *MetaStore) {
|
||||
if r3 != a3.ID {
|
||||
t.Fatal("Expected remove ID to match create ID")
|
||||
}
|
||||
if k3 != snapshot.KindView {
|
||||
if k3 != snapshots.KindView {
|
||||
t.Fatalf("Expected view kind, got %v", k3)
|
||||
}
|
||||
|
||||
@ -515,7 +515,7 @@ func testRemove(ctx context.Context, t *testing.T, ms *MetaStore) {
|
||||
if r2 != a2.ID {
|
||||
t.Fatal("Expected remove ID to match create ID")
|
||||
}
|
||||
if k2 != snapshot.KindView {
|
||||
if k2 != snapshots.KindView {
|
||||
t.Fatalf("Expected view kind, got %v", k2)
|
||||
}
|
||||
|
||||
@ -526,7 +526,7 @@ func testRemove(ctx context.Context, t *testing.T, ms *MetaStore) {
|
||||
if r1 != commitID {
|
||||
t.Fatal("Expected remove ID to match commit ID")
|
||||
}
|
||||
if k1 != snapshot.KindCommitted {
|
||||
if k1 != snapshots.KindCommitted {
|
||||
t.Fatalf("Expected committed kind, got %v", k1)
|
||||
}
|
||||
}
|
||||
@ -581,10 +581,10 @@ func testParents(ctx context.Context, t *testing.T, ms *MetaStore) {
|
||||
id string
|
||||
parents []string
|
||||
)
|
||||
if info.Kind == snapshot.KindCommitted {
|
||||
if info.Kind == snapshots.KindCommitted {
|
||||
// When commited, create view and resolve from view
|
||||
nid := fmt.Sprintf("test-%s-%d", tc.Name, i)
|
||||
s, err := CreateSnapshot(ctx, snapshot.KindView, nid, name)
|
||||
s, err := CreateSnapshot(ctx, snapshots.KindView, nid, name)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to get snapshot %s: %v", tc.Name, err)
|
||||
}
|
@ -9,7 +9,7 @@ import (
|
||||
|
||||
"github.com/containerd/containerd/fs/fstest"
|
||||
"github.com/containerd/containerd/mount"
|
||||
"github.com/containerd/containerd/snapshot"
|
||||
"github.com/containerd/containerd/snapshots"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
@ -34,7 +34,7 @@ func applyToMounts(m []mount.Mount, work string, a fstest.Applier) (err error) {
|
||||
|
||||
// createSnapshot creates a new snapshot in the snapshotter
|
||||
// given an applier to run on top of the given parent.
|
||||
func createSnapshot(ctx context.Context, sn snapshot.Snapshotter, parent, work string, a fstest.Applier) (string, error) {
|
||||
func createSnapshot(ctx context.Context, sn snapshots.Snapshotter, parent, work string, a fstest.Applier) (string, error) {
|
||||
n := fmt.Sprintf("%p-%d", a, rand.Int())
|
||||
prepare := fmt.Sprintf("%s-prepare", n)
|
||||
|
||||
@ -54,7 +54,7 @@ func createSnapshot(ctx context.Context, sn snapshot.Snapshotter, parent, work s
|
||||
return n, nil
|
||||
}
|
||||
|
||||
func checkSnapshot(ctx context.Context, sn snapshot.Snapshotter, work, name, check string) (err error) {
|
||||
func checkSnapshot(ctx context.Context, sn snapshots.Snapshotter, work, name, check string) (err error) {
|
||||
td, err := ioutil.TempDir(work, "check")
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to create temp dir")
|
||||
@ -95,7 +95,7 @@ func checkSnapshot(ctx context.Context, sn snapshot.Snapshotter, work, name, che
|
||||
// checkSnapshots creates a new chain of snapshots in the given snapshotter
|
||||
// using the provided appliers, checking each snapshot created in a view
|
||||
// against the changes applied to a single directory.
|
||||
func checkSnapshots(ctx context.Context, sn snapshot.Snapshotter, work string, as ...fstest.Applier) error {
|
||||
func checkSnapshots(ctx context.Context, sn snapshots.Snapshotter, work string, as ...fstest.Applier) error {
|
||||
td, err := ioutil.TempDir(work, "flat")
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to create temp dir")
|
||||
@ -124,7 +124,7 @@ func checkSnapshots(ctx context.Context, sn snapshot.Snapshotter, work string, a
|
||||
}
|
||||
|
||||
// checkInfo checks that the infos are the same
|
||||
func checkInfo(si1, si2 snapshot.Info) error {
|
||||
func checkInfo(si1, si2 snapshots.Info) error {
|
||||
if si1.Kind != si2.Kind {
|
||||
return errors.Errorf("Expected kind %v, got %v", si1.Kind, si2.Kind)
|
||||
}
|
@ -8,7 +8,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/containerd/containerd/fs/fstest"
|
||||
"github.com/containerd/containerd/snapshot"
|
||||
"github.com/containerd/containerd/snapshots"
|
||||
)
|
||||
|
||||
// Checks which cover former issues found in older layering models.
|
||||
@ -23,7 +23,7 @@ import (
|
||||
// Cause of issue was originally related to tar, snapshot should be able to
|
||||
// avoid such issues by not relying on tar to create layers.
|
||||
// See https://github.com/docker/docker/issues/21555
|
||||
func checkLayerFileUpdate(ctx context.Context, t *testing.T, sn snapshot.Snapshotter, work string) {
|
||||
func checkLayerFileUpdate(ctx context.Context, t *testing.T, sn snapshots.Snapshotter, work string) {
|
||||
l1Init := fstest.Apply(
|
||||
fstest.CreateDir("/etc", 0700),
|
||||
fstest.CreateFile("/etc/hosts", []byte("mydomain 10.0.0.1"), 0644),
|
||||
@ -54,7 +54,7 @@ func checkLayerFileUpdate(ctx context.Context, t *testing.T, sn snapshot.Snapsho
|
||||
|
||||
// checkRemoveDirectoryInLowerLayer
|
||||
// See https://github.com/docker/docker/issues/25244
|
||||
func checkRemoveDirectoryInLowerLayer(ctx context.Context, t *testing.T, sn snapshot.Snapshotter, work string) {
|
||||
func checkRemoveDirectoryInLowerLayer(ctx context.Context, t *testing.T, sn snapshots.Snapshotter, work string) {
|
||||
l1Init := fstest.Apply(
|
||||
fstest.CreateDir("/lib", 0700),
|
||||
fstest.CreateFile("/lib/hidden", []byte{}, 0644),
|
||||
@ -77,7 +77,7 @@ func checkRemoveDirectoryInLowerLayer(ctx context.Context, t *testing.T, sn snap
|
||||
// See https://github.com/docker/docker/issues/20240 aufs
|
||||
// See https://github.com/docker/docker/issues/24913 overlay
|
||||
// see https://github.com/docker/docker/issues/28391 overlay2
|
||||
func checkChown(ctx context.Context, t *testing.T, sn snapshot.Snapshotter, work string) {
|
||||
func checkChown(ctx context.Context, t *testing.T, sn snapshots.Snapshotter, work string) {
|
||||
l1Init := fstest.Apply(
|
||||
fstest.CreateDir("/opt", 0700),
|
||||
fstest.CreateDir("/opt/a", 0700),
|
||||
@ -98,7 +98,7 @@ func checkChown(ctx context.Context, t *testing.T, sn snapshot.Snapshotter, work
|
||||
|
||||
// checkRename
|
||||
// https://github.com/docker/docker/issues/25409
|
||||
func checkRename(ctx context.Context, t *testing.T, sn snapshot.Snapshotter, work string) {
|
||||
func checkRename(ctx context.Context, t *testing.T, sn snapshots.Snapshotter, work string) {
|
||||
t.Skip("rename test still fails on some kernels with overlay")
|
||||
l1Init := fstest.Apply(
|
||||
fstest.CreateDir("/dir1", 0700),
|
||||
@ -120,7 +120,7 @@ func checkRename(ctx context.Context, t *testing.T, sn snapshot.Snapshotter, wor
|
||||
|
||||
// checkDirectoryPermissionOnCommit
|
||||
// https://github.com/docker/docker/issues/27298
|
||||
func checkDirectoryPermissionOnCommit(ctx context.Context, t *testing.T, sn snapshot.Snapshotter, work string) {
|
||||
func checkDirectoryPermissionOnCommit(ctx context.Context, t *testing.T, sn snapshots.Snapshotter, work string) {
|
||||
l1Init := fstest.Apply(
|
||||
fstest.CreateDir("/dir1", 0700),
|
||||
fstest.CreateDir("/dir2", 0700),
|
||||
@ -155,13 +155,13 @@ func checkDirectoryPermissionOnCommit(ctx context.Context, t *testing.T, sn snap
|
||||
}
|
||||
|
||||
// checkStatInWalk ensures that a stat can be called during a walk
|
||||
func checkStatInWalk(ctx context.Context, t *testing.T, sn snapshot.Snapshotter, work string) {
|
||||
func checkStatInWalk(ctx context.Context, t *testing.T, sn snapshots.Snapshotter, work string) {
|
||||
prefix := "stats-in-walk-"
|
||||
if err := createNamedSnapshots(ctx, sn, prefix); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
err := sn.Walk(ctx, func(ctx context.Context, si snapshot.Info) error {
|
||||
err := sn.Walk(ctx, func(ctx context.Context, si snapshots.Info) error {
|
||||
if !strings.HasPrefix(si.Name, prefix) {
|
||||
// Only stat snapshots from this test
|
||||
return nil
|
||||
@ -178,7 +178,7 @@ func checkStatInWalk(ctx context.Context, t *testing.T, sn snapshot.Snapshotter,
|
||||
}
|
||||
}
|
||||
|
||||
func createNamedSnapshots(ctx context.Context, snapshotter snapshot.Snapshotter, ns string) error {
|
||||
func createNamedSnapshots(ctx context.Context, snapshotter snapshots.Snapshotter, ns string) error {
|
||||
c1 := fmt.Sprintf("%sc1", ns)
|
||||
c2 := fmt.Sprintf("%sc2", ns)
|
||||
if _, err := snapshotter.Prepare(ctx, c1+"-a", "", opt); err != nil {
|
@ -13,13 +13,13 @@ import (
|
||||
"github.com/containerd/containerd/fs/fstest"
|
||||
"github.com/containerd/containerd/mount"
|
||||
"github.com/containerd/containerd/namespaces"
|
||||
"github.com/containerd/containerd/snapshot"
|
||||
"github.com/containerd/containerd/snapshots"
|
||||
"github.com/containerd/containerd/testutil"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
// SnapshotterSuite runs a test suite on the snapshotter given a factory function.
|
||||
func SnapshotterSuite(t *testing.T, name string, snapshotterFn func(ctx context.Context, root string) (snapshot.Snapshotter, func() error, error)) {
|
||||
func SnapshotterSuite(t *testing.T, name string, snapshotterFn func(ctx context.Context, root string) (snapshots.Snapshotter, func() error, error)) {
|
||||
restoreMask := clearMask()
|
||||
defer restoreMask()
|
||||
|
||||
@ -46,7 +46,7 @@ func SnapshotterSuite(t *testing.T, name string, snapshotterFn func(ctx context.
|
||||
t.Run("CloseTwice", makeTest(name, snapshotterFn, closeTwice))
|
||||
}
|
||||
|
||||
func makeTest(name string, snapshotterFn func(ctx context.Context, root string) (snapshot.Snapshotter, func() error, error), fn func(ctx context.Context, t *testing.T, snapshotter snapshot.Snapshotter, work string)) func(t *testing.T) {
|
||||
func makeTest(name string, snapshotterFn func(ctx context.Context, root string) (snapshots.Snapshotter, func() error, error), fn func(ctx context.Context, t *testing.T, snapshotter snapshots.Snapshotter, work string)) func(t *testing.T) {
|
||||
return func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
@ -91,12 +91,12 @@ func makeTest(name string, snapshotterFn func(ctx context.Context, root string)
|
||||
}
|
||||
}
|
||||
|
||||
var opt = snapshot.WithLabels(map[string]string{
|
||||
var opt = snapshots.WithLabels(map[string]string{
|
||||
"containerd.io/gc.root": time.Now().UTC().Format(time.RFC3339),
|
||||
})
|
||||
|
||||
// checkSnapshotterBasic tests the basic workflow of a snapshot snapshotter.
|
||||
func checkSnapshotterBasic(ctx context.Context, t *testing.T, snapshotter snapshot.Snapshotter, work string) {
|
||||
func checkSnapshotterBasic(ctx context.Context, t *testing.T, snapshotter snapshots.Snapshotter, work string) {
|
||||
initialApplier := fstest.Apply(
|
||||
fstest.CreateFile("/foo", []byte("foo\n"), 0777),
|
||||
fstest.CreateDir("/a", 0755),
|
||||
@ -145,7 +145,7 @@ func checkSnapshotterBasic(ctx context.Context, t *testing.T, snapshotter snapsh
|
||||
}
|
||||
|
||||
assert.Equal(t, "", si.Parent)
|
||||
assert.Equal(t, snapshot.KindCommitted, si.Kind)
|
||||
assert.Equal(t, snapshots.KindCommitted, si.Kind)
|
||||
|
||||
_, err = snapshotter.Stat(ctx, preparing)
|
||||
if err == nil {
|
||||
@ -180,7 +180,7 @@ func checkSnapshotterBasic(ctx context.Context, t *testing.T, snapshotter snapsh
|
||||
}
|
||||
|
||||
assert.Equal(t, committed, ni.Parent)
|
||||
assert.Equal(t, snapshot.KindActive, ni.Kind)
|
||||
assert.Equal(t, snapshots.KindActive, ni.Kind)
|
||||
|
||||
nextCommitted := filepath.Join(work, "committed-next")
|
||||
if err := snapshotter.Commit(ctx, nextCommitted, next, opt); err != nil {
|
||||
@ -193,19 +193,19 @@ func checkSnapshotterBasic(ctx context.Context, t *testing.T, snapshotter snapsh
|
||||
}
|
||||
|
||||
assert.Equal(t, committed, si2.Parent)
|
||||
assert.Equal(t, snapshot.KindCommitted, si2.Kind)
|
||||
assert.Equal(t, snapshots.KindCommitted, si2.Kind)
|
||||
|
||||
_, err = snapshotter.Stat(ctx, next)
|
||||
if err == nil {
|
||||
t.Fatalf("%s should no longer be available after Commit", next)
|
||||
}
|
||||
|
||||
expected := map[string]snapshot.Info{
|
||||
expected := map[string]snapshots.Info{
|
||||
si.Name: si,
|
||||
si2.Name: si2,
|
||||
}
|
||||
walked := map[string]snapshot.Info{} // walk is not ordered
|
||||
assert.NoError(t, snapshotter.Walk(ctx, func(ctx context.Context, si snapshot.Info) error {
|
||||
walked := map[string]snapshots.Info{} // walk is not ordered
|
||||
assert.NoError(t, snapshotter.Walk(ctx, func(ctx context.Context, si snapshots.Info) error {
|
||||
walked[si.Name] = si
|
||||
return nil
|
||||
}))
|
||||
@ -246,7 +246,7 @@ func checkSnapshotterBasic(ctx context.Context, t *testing.T, snapshotter snapsh
|
||||
}
|
||||
|
||||
// Create a New Layer on top of base layer with Prepare, Stat on new layer, should return Active layer.
|
||||
func checkSnapshotterStatActive(ctx context.Context, t *testing.T, snapshotter snapshot.Snapshotter, work string) {
|
||||
func checkSnapshotterStatActive(ctx context.Context, t *testing.T, snapshotter snapshots.Snapshotter, work string) {
|
||||
preparing := filepath.Join(work, "preparing")
|
||||
if err := os.MkdirAll(preparing, 0777); err != nil {
|
||||
t.Fatal(err)
|
||||
@ -275,12 +275,12 @@ func checkSnapshotterStatActive(ctx context.Context, t *testing.T, snapshotter s
|
||||
t.Fatal(err)
|
||||
}
|
||||
assert.Equal(t, si.Name, preparing)
|
||||
assert.Equal(t, snapshot.KindActive, si.Kind)
|
||||
assert.Equal(t, snapshots.KindActive, si.Kind)
|
||||
assert.Equal(t, "", si.Parent)
|
||||
}
|
||||
|
||||
// Commit a New Layer on top of base layer with Prepare & Commit , Stat on new layer, should return Committed layer.
|
||||
func checkSnapshotterStatCommitted(ctx context.Context, t *testing.T, snapshotter snapshot.Snapshotter, work string) {
|
||||
func checkSnapshotterStatCommitted(ctx context.Context, t *testing.T, snapshotter snapshots.Snapshotter, work string) {
|
||||
preparing := filepath.Join(work, "preparing")
|
||||
if err := os.MkdirAll(preparing, 0777); err != nil {
|
||||
t.Fatal(err)
|
||||
@ -314,12 +314,12 @@ func checkSnapshotterStatCommitted(ctx context.Context, t *testing.T, snapshotte
|
||||
t.Fatal(err)
|
||||
}
|
||||
assert.Equal(t, si.Name, committed)
|
||||
assert.Equal(t, snapshot.KindCommitted, si.Kind)
|
||||
assert.Equal(t, snapshots.KindCommitted, si.Kind)
|
||||
assert.Equal(t, "", si.Parent)
|
||||
|
||||
}
|
||||
|
||||
func snapshotterPrepareMount(ctx context.Context, snapshotter snapshot.Snapshotter, diffPathName string, parent string, work string) (string, error) {
|
||||
func snapshotterPrepareMount(ctx context.Context, snapshotter snapshots.Snapshotter, diffPathName string, parent string, work string) (string, error) {
|
||||
preparing := filepath.Join(work, diffPathName)
|
||||
if err := os.MkdirAll(preparing, 0777); err != nil {
|
||||
return "", err
|
||||
@ -341,7 +341,7 @@ func snapshotterPrepareMount(ctx context.Context, snapshotter snapshot.Snapshott
|
||||
}
|
||||
|
||||
// Given A <- B <- C, B is the parent of C and A is a transitive parent of C (in this case, a "grandparent")
|
||||
func checkSnapshotterTransitivity(ctx context.Context, t *testing.T, snapshotter snapshot.Snapshotter, work string) {
|
||||
func checkSnapshotterTransitivity(ctx context.Context, t *testing.T, snapshotter snapshots.Snapshotter, work string) {
|
||||
preparing, err := snapshotterPrepareMount(ctx, snapshotter, "preparing", "", work)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@ -395,7 +395,7 @@ func checkSnapshotterTransitivity(ctx context.Context, t *testing.T, snapshotter
|
||||
}
|
||||
|
||||
// Creating two layers with Prepare or View with same key must fail.
|
||||
func checkSnapshotterPrepareView(ctx context.Context, t *testing.T, snapshotter snapshot.Snapshotter, work string) {
|
||||
func checkSnapshotterPrepareView(ctx context.Context, t *testing.T, snapshotter snapshots.Snapshotter, work string) {
|
||||
preparing, err := snapshotterPrepareMount(ctx, snapshotter, "preparing", "", work)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@ -456,7 +456,7 @@ func checkSnapshotterPrepareView(ctx context.Context, t *testing.T, snapshotter
|
||||
}
|
||||
|
||||
// Deletion of files/folder of base layer in new layer, On Commit, those files should not be visible.
|
||||
func checkDeletedFilesInChildSnapshot(ctx context.Context, t *testing.T, snapshotter snapshot.Snapshotter, work string) {
|
||||
func checkDeletedFilesInChildSnapshot(ctx context.Context, t *testing.T, snapshotter snapshots.Snapshotter, work string) {
|
||||
|
||||
l1Init := fstest.Apply(
|
||||
fstest.CreateFile("/foo", []byte("foo\n"), 0777),
|
||||
@ -474,7 +474,7 @@ func checkDeletedFilesInChildSnapshot(ctx context.Context, t *testing.T, snapsho
|
||||
}
|
||||
|
||||
//Create three layers. Deleting intermediate layer must fail.
|
||||
func checkRemoveIntermediateSnapshot(ctx context.Context, t *testing.T, snapshotter snapshot.Snapshotter, work string) {
|
||||
func checkRemoveIntermediateSnapshot(ctx context.Context, t *testing.T, snapshotter snapshots.Snapshotter, work string) {
|
||||
|
||||
base, err := snapshotterPrepareMount(ctx, snapshotter, "base", "", work)
|
||||
if err != nil {
|
||||
@ -533,7 +533,7 @@ func checkRemoveIntermediateSnapshot(ctx context.Context, t *testing.T, snapshot
|
||||
// a1 - active snapshot, no parent
|
||||
// v1 - view snapshot, v1 is parent
|
||||
// v2 - view snapshot, no parent
|
||||
func baseTestSnapshots(ctx context.Context, snapshotter snapshot.Snapshotter) error {
|
||||
func baseTestSnapshots(ctx context.Context, snapshotter snapshots.Snapshotter) error {
|
||||
if _, err := snapshotter.Prepare(ctx, "c1-a", "", opt); err != nil {
|
||||
return err
|
||||
}
|
||||
@ -561,7 +561,7 @@ func baseTestSnapshots(ctx context.Context, snapshotter snapshot.Snapshotter) er
|
||||
return nil
|
||||
}
|
||||
|
||||
func checkUpdate(ctx context.Context, t *testing.T, snapshotter snapshot.Snapshotter, work string) {
|
||||
func checkUpdate(ctx context.Context, t *testing.T, snapshotter snapshots.Snapshotter, work string) {
|
||||
t1 := time.Now().UTC()
|
||||
if err := baseTestSnapshots(ctx, snapshotter); err != nil {
|
||||
t.Fatalf("Failed to create base snapshots: %v", err)
|
||||
@ -569,35 +569,35 @@ func checkUpdate(ctx context.Context, t *testing.T, snapshotter snapshot.Snapsho
|
||||
t2 := time.Now().UTC()
|
||||
testcases := []struct {
|
||||
name string
|
||||
kind snapshot.Kind
|
||||
kind snapshots.Kind
|
||||
parent string
|
||||
}{
|
||||
{
|
||||
name: "c1",
|
||||
kind: snapshot.KindCommitted,
|
||||
kind: snapshots.KindCommitted,
|
||||
},
|
||||
{
|
||||
name: "c2",
|
||||
kind: snapshot.KindCommitted,
|
||||
kind: snapshots.KindCommitted,
|
||||
parent: "c1",
|
||||
},
|
||||
{
|
||||
name: "a1",
|
||||
kind: snapshot.KindActive,
|
||||
kind: snapshots.KindActive,
|
||||
parent: "c2",
|
||||
},
|
||||
{
|
||||
name: "a2",
|
||||
kind: snapshot.KindActive,
|
||||
kind: snapshots.KindActive,
|
||||
},
|
||||
{
|
||||
name: "v1",
|
||||
kind: snapshot.KindView,
|
||||
kind: snapshots.KindView,
|
||||
parent: "c2",
|
||||
},
|
||||
{
|
||||
name: "v2",
|
||||
kind: snapshot.KindView,
|
||||
kind: snapshots.KindView,
|
||||
},
|
||||
}
|
||||
for _, tc := range testcases {
|
||||
@ -717,7 +717,7 @@ func assertLabels(t *testing.T, actual, expected map[string]string) {
|
||||
}
|
||||
}
|
||||
|
||||
func checkRemove(ctx context.Context, t *testing.T, snapshotter snapshot.Snapshotter, work string) {
|
||||
func checkRemove(ctx context.Context, t *testing.T, snapshotter snapshots.Snapshotter, work string) {
|
||||
if _, err := snapshotter.Prepare(ctx, "committed-a", "", opt); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -749,7 +749,7 @@ func checkRemove(ctx context.Context, t *testing.T, snapshotter snapshot.Snapsho
|
||||
|
||||
// checkSnapshotterViewReadonly ensures a KindView snapshot to be mounted as a read-only filesystem.
|
||||
// This function is called only when WithTestViewReadonly is true.
|
||||
func checkSnapshotterViewReadonly(ctx context.Context, t *testing.T, snapshotter snapshot.Snapshotter, work string) {
|
||||
func checkSnapshotterViewReadonly(ctx context.Context, t *testing.T, snapshotter snapshots.Snapshotter, work string) {
|
||||
preparing := filepath.Join(work, "preparing")
|
||||
if _, err := snapshotter.Prepare(ctx, preparing, "", opt); err != nil {
|
||||
t.Fatal(err)
|
||||
@ -786,7 +786,7 @@ func checkSnapshotterViewReadonly(ctx context.Context, t *testing.T, snapshotter
|
||||
|
||||
// Move files from base layer to new location in intermediate layer.
|
||||
// Verify if the file at source is deleted and copied to new location.
|
||||
func checkFileFromLowerLayer(ctx context.Context, t *testing.T, snapshotter snapshot.Snapshotter, work string) {
|
||||
func checkFileFromLowerLayer(ctx context.Context, t *testing.T, snapshotter snapshots.Snapshotter, work string) {
|
||||
l1Init := fstest.Apply(
|
||||
fstest.CreateDir("/dir1", 0700),
|
||||
fstest.CreateFile("/dir1/f1", []byte("Hello"), 0644),
|
||||
@ -806,7 +806,7 @@ func checkFileFromLowerLayer(ctx context.Context, t *testing.T, snapshotter snap
|
||||
}
|
||||
}
|
||||
|
||||
func closeTwice(ctx context.Context, t *testing.T, snapshotter snapshot.Snapshotter, work string) {
|
||||
func closeTwice(ctx context.Context, t *testing.T, snapshotter snapshots.Snapshotter, work string) {
|
||||
// do some dummy ops to modify the snapshotter internal state
|
||||
if _, err := snapshotter.Prepare(ctx, "dummy", ""); err != nil {
|
||||
t.Fatal(err)
|
@ -7,7 +7,7 @@ import (
|
||||
|
||||
"github.com/containerd/containerd/mount"
|
||||
"github.com/containerd/containerd/plugin"
|
||||
"github.com/containerd/containerd/snapshot"
|
||||
"github.com/containerd/containerd/snapshots"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
@ -31,7 +31,7 @@ type snapshotter struct {
|
||||
}
|
||||
|
||||
// NewSnapshotter returns a new windows snapshotter
|
||||
func NewSnapshotter(root string) (snapshot.Snapshotter, error) {
|
||||
func NewSnapshotter(root string) (snapshots.Snapshotter, error) {
|
||||
return &snapshotter{
|
||||
root: root,
|
||||
}, nil
|
||||
@ -42,23 +42,23 @@ func NewSnapshotter(root string) (snapshot.Snapshotter, error) {
|
||||
//
|
||||
// Should be used for parent resolution, existence checks and to discern
|
||||
// the kind of snapshot.
|
||||
func (o *snapshotter) Stat(ctx context.Context, key string) (snapshot.Info, error) {
|
||||
func (o *snapshotter) Stat(ctx context.Context, key string) (snapshots.Info, error) {
|
||||
panic("not implemented")
|
||||
}
|
||||
|
||||
func (o *snapshotter) Update(ctx context.Context, info snapshot.Info, fieldpaths ...string) (snapshot.Info, error) {
|
||||
func (o *snapshotter) Update(ctx context.Context, info snapshots.Info, fieldpaths ...string) (snapshots.Info, error) {
|
||||
panic("not implemented")
|
||||
}
|
||||
|
||||
func (o *snapshotter) Usage(ctx context.Context, key string) (snapshot.Usage, error) {
|
||||
func (o *snapshotter) Usage(ctx context.Context, key string) (snapshots.Usage, error) {
|
||||
panic("not implemented")
|
||||
}
|
||||
|
||||
func (o *snapshotter) Prepare(ctx context.Context, key, parent string, opts ...snapshot.Opt) ([]mount.Mount, error) {
|
||||
func (o *snapshotter) Prepare(ctx context.Context, key, parent string, opts ...snapshots.Opt) ([]mount.Mount, error) {
|
||||
panic("not implemented")
|
||||
}
|
||||
|
||||
func (o *snapshotter) View(ctx context.Context, key, parent string, opts ...snapshot.Opt) ([]mount.Mount, error) {
|
||||
func (o *snapshotter) View(ctx context.Context, key, parent string, opts ...snapshots.Opt) ([]mount.Mount, error) {
|
||||
panic("not implemented")
|
||||
}
|
||||
|
||||
@ -70,7 +70,7 @@ func (o *snapshotter) Mounts(ctx context.Context, key string) ([]mount.Mount, er
|
||||
panic("not implemented")
|
||||
}
|
||||
|
||||
func (o *snapshotter) Commit(ctx context.Context, name, key string, opts ...snapshot.Opt) error {
|
||||
func (o *snapshotter) Commit(ctx context.Context, name, key string, opts ...snapshots.Opt) error {
|
||||
panic("not implemented")
|
||||
}
|
||||
|
||||
@ -81,7 +81,7 @@ func (o *snapshotter) Remove(ctx context.Context, key string) error {
|
||||
}
|
||||
|
||||
// Walk the committed snapshots.
|
||||
func (o *snapshotter) Walk(ctx context.Context, fn func(context.Context, snapshot.Info) error) error {
|
||||
func (o *snapshotter) Walk(ctx context.Context, fn func(context.Context, snapshots.Info) error) error {
|
||||
panic("not implemented")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user