Merge pull request #286 from AkihiroSuda/oci-worker-overlay-false

worker/oci: allow using naive snapshotter
docker-18.09
Vincent Demeester 2018-02-20 14:38:47 +01:00 committed by GitHub
commit 40212c5fcd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 8 deletions

View File

@ -27,6 +27,12 @@ func init() {
Name: "oci-worker-labels", Name: "oci-worker-labels",
Usage: "user-specific annotation labels (com.example.foo=bar)", Usage: "user-specific annotation labels (com.example.foo=bar)",
}, },
cli.StringFlag{
Name: "oci-worker-snapshotter",
Usage: "name of snapshotter (overlayfs or naive)",
// TODO(AkihiroSuda): autodetect overlayfs availability when the value is set to "auto"?
Value: "overlayfs",
},
) )
// TODO: allow multiple oci runtimes and snapshotters // TODO: allow multiple oci runtimes and snapshotters
} }
@ -43,7 +49,7 @@ func ociWorkerInitializer(c *cli.Context, common workerInitializerOpt) ([]worker
if err != nil { if err != nil {
return nil, err return nil, err
} }
opt, err := runc.NewWorkerOpt(common.root, labels) opt, err := runc.NewWorkerOpt(common.root, labels, c.GlobalString("oci-worker-snapshotter"))
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -11,19 +11,30 @@ import (
"github.com/containerd/containerd/diff/walking" "github.com/containerd/containerd/diff/walking"
ctdmetadata "github.com/containerd/containerd/metadata" ctdmetadata "github.com/containerd/containerd/metadata"
ctdsnapshot "github.com/containerd/containerd/snapshots" ctdsnapshot "github.com/containerd/containerd/snapshots"
"github.com/containerd/containerd/snapshots/naive"
"github.com/containerd/containerd/snapshots/overlay" "github.com/containerd/containerd/snapshots/overlay"
"github.com/moby/buildkit/cache/metadata" "github.com/moby/buildkit/cache/metadata"
"github.com/moby/buildkit/executor/runcexecutor" "github.com/moby/buildkit/executor/runcexecutor"
containerdsnapshot "github.com/moby/buildkit/snapshot/containerd" containerdsnapshot "github.com/moby/buildkit/snapshot/containerd"
"github.com/moby/buildkit/worker/base" "github.com/moby/buildkit/worker/base"
"github.com/pkg/errors"
) )
// NewWorkerOpt creates a WorkerOpt. // NewWorkerOpt creates a WorkerOpt.
// But it does not set the following fields: // But it does not set the following fields:
// - SessionManager // - SessionManager
func NewWorkerOpt(root string, labels map[string]string) (base.WorkerOpt, error) { func NewWorkerOpt(root string, labels map[string]string, snapshotterName string) (base.WorkerOpt, error) {
var opt base.WorkerOpt var opt base.WorkerOpt
name := "runc-overlayfs" var snapshotterNew func(root string) (ctdsnapshot.Snapshotter, error)
switch snapshotterName {
case "naive":
snapshotterNew = naive.NewSnapshotter
case "overlayfs": // not "overlay", for consistency with containerd snapshotter plugin ID.
snapshotterNew = overlay.NewSnapshotter
default:
return opt, errors.Errorf("unknown snapshotter name: %q", snapshotterName)
}
name := "runc-" + snapshotterName
root = filepath.Join(root, name) root = filepath.Join(root, name)
if err := os.MkdirAll(root, 0700); err != nil { if err := os.MkdirAll(root, 0700); err != nil {
return opt, err return opt, err
@ -36,7 +47,7 @@ func NewWorkerOpt(root string, labels map[string]string) (base.WorkerOpt, error)
if err != nil { if err != nil {
return opt, err return opt, err
} }
s, err := overlay.NewSnapshotter(filepath.Join(root, "snapshots")) s, err := snapshotterNew(filepath.Join(root, "snapshots"))
if err != nil { if err != nil {
return opt, err return opt, err
} }
@ -52,7 +63,7 @@ func NewWorkerOpt(root string, labels map[string]string) (base.WorkerOpt, error)
} }
mdb := ctdmetadata.NewDB(db, c, map[string]ctdsnapshot.Snapshotter{ mdb := ctdmetadata.NewDB(db, c, map[string]ctdsnapshot.Snapshotter{
"overlayfs": s, snapshotterName: s,
}) })
if err := mdb.Init(context.TODO()); err != nil { if err := mdb.Init(context.TODO()); err != nil {
return opt, err return opt, err
@ -69,7 +80,7 @@ func NewWorkerOpt(root string, labels map[string]string) (base.WorkerOpt, error)
if err != nil { if err != nil {
return opt, err return opt, err
} }
xlabels := base.Labels("oci", "overlayfs") xlabels := base.Labels("oci", snapshotterName)
for k, v := range labels { for k, v := range labels {
xlabels[k] = v xlabels[k] = v
} }
@ -78,7 +89,7 @@ func NewWorkerOpt(root string, labels map[string]string) (base.WorkerOpt, error)
Labels: xlabels, Labels: xlabels,
MetadataStore: md, MetadataStore: md,
Executor: exe, Executor: exe,
Snapshotter: containerdsnapshot.NewSnapshotter(mdb.Snapshotter("overlayfs"), c, md, "buildkit", gc), Snapshotter: containerdsnapshot.NewSnapshotter(mdb.Snapshotter(snapshotterName), c, md, "buildkit", gc),
ContentStore: c, ContentStore: c,
Applier: apply.NewFileSystemApplier(c), Applier: apply.NewFileSystemApplier(c),
Differ: walking.NewWalkingDiff(c), Differ: walking.NewWalkingDiff(c),

View File

@ -38,7 +38,7 @@ func TestRuncWorker(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
defer os.RemoveAll(tmpdir) defer os.RemoveAll(tmpdir)
workerOpt, err := NewWorkerOpt(tmpdir, nil) workerOpt, err := NewWorkerOpt(tmpdir, nil, "overlayfs")
require.NoError(t, err) require.NoError(t, err)
workerOpt.SessionManager, err = session.NewManager() workerOpt.SessionManager, err = session.NewManager()