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 <derek@mcg.dev>
This commit is contained in:
Derek McGowan 2020-08-26 18:40:47 -07:00
parent 1a89feb5d7
commit 70ffb12c1b
No known key found for this signature in database
GPG Key ID: F58C5D0A4405ACDB
3 changed files with 33 additions and 27 deletions

View File

@ -23,5 +23,5 @@ import (
_ "github.com/containerd/containerd/runtime/v2" _ "github.com/containerd/containerd/runtime/v2"
_ "github.com/containerd/containerd/runtime/v2/runc/options" _ "github.com/containerd/containerd/runtime/v2/runc/options"
_ "github.com/containerd/containerd/snapshots/native" _ "github.com/containerd/containerd/snapshots/native"
_ "github.com/containerd/containerd/snapshots/overlay" _ "github.com/containerd/containerd/snapshots/overlay/plugin"
) )

View File

@ -29,38 +29,12 @@ 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/platforms"
"github.com/containerd/containerd/plugin"
"github.com/containerd/containerd/snapshots" "github.com/containerd/containerd/snapshots"
"github.com/containerd/containerd/snapshots/storage" "github.com/containerd/containerd/snapshots/storage"
"github.com/containerd/continuity/fs" "github.com/containerd/continuity/fs"
"github.com/pkg/errors" "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 // SnapshotterConfig is used to configure the overlay snapshotter instance
type SnapshotterConfig struct { type SnapshotterConfig struct {
asyncRemove bool asyncRemove bool

View File

@ -18,8 +18,40 @@
package overlay 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. // Config represents configuration for the overlay plugin.
type Config struct { type Config struct {
// Root directory for the plugin // Root directory for the plugin
RootPath string `toml:"root_path"` 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)
},
})
}