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