From 70ffb12c1bed2bf9f104a4edb2256fcb363f800b Mon Sep 17 00:00:00 2001 From: Derek McGowan Date: Wed, 26 Aug 2020 18:40:47 -0700 Subject: [PATCH] Separate overlay implementation from plugin Put the overlay plugin in a separate package to allow the overlay package to be used without needing to import and initialize the plugin. Signed-off-by: Derek McGowan --- cmd/containerd/builtins_linux.go | 2 +- snapshots/overlay/overlay.go | 26 --------------- .../overlay/{config.go => plugin/plugin.go} | 32 +++++++++++++++++++ 3 files changed, 33 insertions(+), 27 deletions(-) rename snapshots/overlay/{config.go => plugin/plugin.go} (51%) diff --git a/cmd/containerd/builtins_linux.go b/cmd/containerd/builtins_linux.go index 5fa9a911c..59fe8de44 100644 --- a/cmd/containerd/builtins_linux.go +++ b/cmd/containerd/builtins_linux.go @@ -23,5 +23,5 @@ import ( _ "github.com/containerd/containerd/runtime/v2" _ "github.com/containerd/containerd/runtime/v2/runc/options" _ "github.com/containerd/containerd/snapshots/native" - _ "github.com/containerd/containerd/snapshots/overlay" + _ "github.com/containerd/containerd/snapshots/overlay/plugin" ) diff --git a/snapshots/overlay/overlay.go b/snapshots/overlay/overlay.go index ef2f76ada..1e55fb2f3 100644 --- a/snapshots/overlay/overlay.go +++ b/snapshots/overlay/overlay.go @@ -29,38 +29,12 @@ import ( "github.com/containerd/containerd/log" "github.com/containerd/containerd/mount" - "github.com/containerd/containerd/platforms" - "github.com/containerd/containerd/plugin" "github.com/containerd/containerd/snapshots" "github.com/containerd/containerd/snapshots/storage" "github.com/containerd/continuity/fs" "github.com/pkg/errors" ) -func init() { - plugin.Register(&plugin.Registration{ - Type: plugin.SnapshotPlugin, - ID: "overlayfs", - Config: &Config{}, - InitFn: func(ic *plugin.InitContext) (interface{}, error) { - ic.Meta.Platforms = append(ic.Meta.Platforms, platforms.DefaultSpec()) - - config, ok := ic.Config.(*Config) - if !ok { - return nil, errors.New("invalid overlay configuration") - } - - root := ic.Root - if config.RootPath != "" { - root = config.RootPath - } - - ic.Meta.Exports["root"] = root - return NewSnapshotter(root, AsynchronousRemove) - }, - }) -} - // SnapshotterConfig is used to configure the overlay snapshotter instance type SnapshotterConfig struct { asyncRemove bool diff --git a/snapshots/overlay/config.go b/snapshots/overlay/plugin/plugin.go similarity index 51% rename from snapshots/overlay/config.go rename to snapshots/overlay/plugin/plugin.go index 5dba1377a..33324d910 100644 --- a/snapshots/overlay/config.go +++ b/snapshots/overlay/plugin/plugin.go @@ -18,8 +18,40 @@ package overlay +import ( + "errors" + + "github.com/containerd/containerd/platforms" + "github.com/containerd/containerd/plugin" + "github.com/containerd/containerd/snapshots/overlay" +) + // Config represents configuration for the overlay plugin. type Config struct { // Root directory for the plugin RootPath string `toml:"root_path"` } + +func init() { + plugin.Register(&plugin.Registration{ + Type: plugin.SnapshotPlugin, + ID: "overlayfs", + Config: &Config{}, + InitFn: func(ic *plugin.InitContext) (interface{}, error) { + ic.Meta.Platforms = append(ic.Meta.Platforms, platforms.DefaultSpec()) + + config, ok := ic.Config.(*Config) + if !ok { + return nil, errors.New("invalid overlay configuration") + } + + root := ic.Root + if config.RootPath != "" { + root = config.RootPath + } + + ic.Meta.Exports["root"] = root + return overlay.NewSnapshotter(root, overlay.AsynchronousRemove) + }, + }) +}